KalmanLike(y, mod, nit = 0L, update = FALSE)
KalmanRun(y, mod, nit = 0L, update = FALSE)
KalmanSmooth(y, mod, nit = 0L)
KalmanForecast(n.ahead = 10L, mod, update = FALSE)
makeARIMA(phi, theta, Delta, kappa = 1e6, SSinit = c("Gardner1980", "Rossignol2011"), tol = .Machine$double.eps)
nit = 0L
implies that the initialization is for a one-step
prediction, so Pn
should not be computed at the first step.TRUE
the update mod
object will be
returned as attribute "mod"
of the result.y[t] - Delta[1]*y[t-1] - ...
.Pn
part of the state-space initialization; see
Details.solve.default
when SSinit = "Rossignol2011"
.KalmanLike
, a list with components Lik
(the
log-likelihood less some constants) and s2
, the estimate of
$kappa$.For KalmanRun
, a list with components values
, a vector
of length 2 giving the output of KalmanLike
, resid
(the
residuals) and states
, the contemporaneous state estimates,
a matrix with one row for each observation time.For KalmanSmooth
, a list with two components.
Component smooth
is a n
by p
matrix of state
estimates based on all the observations, with one row for each time.
Component var
is a n
by p
by p
array of
variance matrices.For KalmanForecast
, a list with components pred
, the
predictions, and var
, the unscaled variances of the prediction
errors (to be multiplied by s2
).For makeARIMA
, a model list including components for
its arguments.
The model is specified as a list with at least components
T
Z
h
V
a
P
Pn
KalmanForecast
.
KalmanSmooth
is the workhorse function for tsSmooth
.
makeARIMA
constructs the state-space model for an ARIMA model,
see also arima
.
The state-space initialization has used Gardner et al's method
(SSinit = "Gardner1980"
), as only method for years. However,
that suffers sometimes from deficiencies when close to non-stationarity.
For this reason, it may be replaced as default in the future and only
kept for reproducibility reasons. Explicit specification of
SSinit
is therefore recommended, notably also in
arima()
.
The "Rossignol2011"
method has been proposed and partly
documented by Raphael Rossignol, Univ. Grenoble, on 2011-09-20 (see
PR#14682, below), and later been ported to C by Matwey V. Kornilov.
It computes the covariance matrix of
$(X_{t-1},...,X_{t-p},Z_t,...,Z_{t-q})$
by the method of difference equations (page 93 of Brockwell and Davis),
apparently suggested by a referee of Gardner et al (see p.314 of
their paper).
Gardner, G, Harvey, A. C. and Phillips, G. D. A. (1980) Algorithm AS154. An algorithm for exact maximum likelihood estimation of autoregressive-moving average models by means of Kalman filtering. Applied Statistics 29, 311--322.
R bug report PR#14682 (2011-2013) https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14682.
arima
, StructTS
. tsSmooth
.
## an ARIMA fit
fit3 <- arima(presidents, c(3, 0, 0))
predict(fit3, 12)
## reconstruct this
pr <- KalmanForecast(12, fit3$model)
pr$pred + fit3$coef[4]
sqrt(pr$var * fit3$sigma2)
## and now do it year by year
mod <- fit3$model
for(y in 1:3) {
pr <- KalmanForecast(4, mod, TRUE)
print(list(pred = pr$pred + fit3$coef["intercept"],
se = sqrt(pr$var * fit3$sigma2)))
mod <- attr(pr, "mod")
}
Run the code above in your browser using DataLab