Description Usage Arguments Details Value References See Also Examples
These functions run the disturbance smoother upon the output from the Kalman filter and smoother.
1 2 |
y |
a numeric time series or vector. |
ss |
a list containing the matrices of the state space model. |
kf |
a list containing the output returned by the function |
ks |
a list containing the output returned by the function |
ksd |
a list containing the output returned by the function |
See the details section and the section ‘state space representation’
in KF
.
DS
returns a list containing the following elements:
epshat |
smoothed estimate of the disturbance term in the observation equation. |
vareps |
error variance of |
etahat |
smoothed estimate of the disturbance term(s) in the state equation. |
vareta |
error variance of |
DS.deriv
returns a list containing the derivatives of the elements above
named respectively depshat
, dvareps
, detahat
and dvareta
.
The derivatives are summed over all the observations.
Durbin, J. and Koopman, S. J. (2001). Time Series Analysis by State Space Methods. Oxford University Press.
Harvey, A. C. (1989). Forecasting, Structural Time Series Models and the Kalman Filter. Cambridge University Press.
KF
, KS
;
char2numeric
in package stsm.
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 | # local level plus seasonal model with arbitrary parameter values
# for the 'JohnsonJohnson' time series
m <- stsm::stsm.model(model = "llm+seas", y = JohnsonJohnson,
pars = c("var1" = 2, "var2" = 15, "var3" = 30))
ss <- stsm::char2numeric(m)
kf <- KF(m@y, ss)
ks <- KS(m@y, ss, kf)
ds <- DS(m@y, ss, kf, ks)
acf(ds$epshat, main = "ACF of smoothed disturbance")
kfd <- KF.deriv(m@y, ss)
ksd <- KS.deriv(m@y, ss, kfd)
dsd <- DS.deriv(ss, ksd)
# compare analytical and numerical derivatives
fcn <- function(x, model, type, i = 1)
{
m <- stsm::set.pars(model, x)
ss <- stsm::char2numeric(m)
kf <- KF(m@y, ss)
ks <- KS(m@y, ss, kf)
ds <- DS(m@y, ss, kf, ks)
switch(type,
"epshat" = sum(ds$epshat),
"vareps" = sum(ds$vareps))
}
d <- numDeriv::grad(func = fcn, x = m@pars, model = m, type = "epshat")
all.equal(d, dsd$depshat)
d <- numDeriv::grad(func = fcn, x = m@pars, model = m, type = "vareps")
all.equal(d, dsd$dvareps)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.