-
Notifications
You must be signed in to change notification settings - Fork 0
/
stsmFit.R
47 lines (38 loc) · 1.57 KB
/
stsmFit.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
##FIXME TODO for other methods (concentrated likelihood, EM)
##FIXME if xreg is not null (in ellipsis, list(...)) and derivatives is "analytical"
#change to numerical (at least for maxlik.fd/td.optim functions)
#stsmFit <- function(x, xreg = NULL, method = c("maxlik.fd.scoring"), args = NULL)
#stsmFit <- function(x, xreg = NULL, method = c("maxlik.fd.scoring"), ...)
stsmFit <- function(x, stsm.method = c("maxlik.fd.scoring", "maxlik.td.scoring",
"maxlik.fd.optim", "maxlik.td.optim"), xreg = NULL, ...)
{
method <- match.arg(stsm.method)
##NOTE
# argument "xreg" could be avoided because it is supposed to be defined
# in the object "x", but this argument is convenient for package "tsoutlies".
# In this way, the same arguments are passed to "stats::arima" and "stsmFit"
# and the code is simplified there without the need of "if" statements.
if (!is.null(xreg))
{
if (!is.null(x@xreg))
stop("multiple definitions of ", sQuote("xreg"))
#x@xreg <- xreg
x <- set.xreg(x, xreg)
}
#do.call(method, args = c(list(m = x, xreg = xreg), args))
res <- do.call(stsm.method, args = c(list(m = x), list(...)))
res$call0 <- res$call
res$call <- NULL
# the call to "stsmFit" (not to "maxlik.td.optim" or other "stsm.method")
# is required in package "tsoutliers::remove.outliers"
res <- c(call = match.call(), res)
class(res) <- "stsmFit"
res
}
# do.call("stsmFit", args = list(x = x, args = list()))
# fcn <- function(x, xreg = NULL, method = c("maxlik.fd.scoring"), ...)
# {
# #match.call(expand.dots = TRUE)
# res <- list(...)
# res
# }