KFS | R Documentation |
Performs Kalman filtering and smoothing with exact diffuse initialization using univariate approach for exponential family state space models.
KFS(
model,
filtering,
smoothing,
simplify = TRUE,
transform = c("ldl", "augment"),
nsim = 0,
theta,
maxiter = 50,
convtol = 1e-08,
return_model = TRUE,
expected = FALSE,
H_tol = 1e+15,
transform_tol
)
model |
Object of class |
filtering |
Types of filtering. Possible choices are |
smoothing |
Types of smoothing. Possible choices are |
simplify |
If |
transform |
How to transform the model in case of non-diagonal
covariance matrix |
nsim |
The number of independent samples used in importance sampling.
Only used for non-Gaussian models. Default is 0, which computes the
approximating Gaussian model by |
theta |
Initial values for conditional mode theta. Only used for non-Gaussian models. |
maxiter |
The maximum number of iterations used in Gaussian approximation. Default is 50. Only used for non-Gaussian models. |
convtol |
Tolerance parameter for convergence checks for Gaussian approximation. Only used for non-Gaussian models. |
return_model |
Logical, indicating whether the original input model should be
returned as part of the output. Defaults to TRUE, but for large models can be set
to FALSE in order to save memory. However, many of the methods operating on the
output of |
expected |
Logical value defining the approximation of H_t in case of Gamma
and negative binomial distribution. Default is |
H_tol |
Tolerance parameter for check |
transform_tol |
Tolerance parameter for LDL decomposition in case of a
non-diagonal H and |
Notice that in case of multivariate Gaussian observations, v
, F
,
Finf
, K
and Kinf
are usually not the same as those
calculated in usual multivariate Kalman filter. As filtering is done one
observation element at the time, the elements of the prediction error
v_t
are uncorrelated, and F
, Finf
, K
and
Kinf
contain only the diagonal elemens of the corresponding covariance
matrices. The usual multivariate versions of F
and v
can be
obtained from the output of KFS
using the function
mvInnovations
.
In rare cases (typically with regression components with high multicollinearity or
long cyclic patterns), the cumulative rounding errors in Kalman filtering and
smoothing can cause the diffuse phase end too early,
or the backward smoothing gives negative variances (in diffuse and nondiffuse cases).
Since version 1.4.0, filtering and smoothing algorithms truncate these values to zero during the
recursions, but this can still leads some numerical problems.
In these cases, redefining the prior state variances more informative is often helpful.
Changing the tolerance parameter tol
of the model (see SSModel
) to smaller
(or larger), or scaling the model input can sometimes help as well. These numerical issues
are well known in Kalman filtering/smoothing in general
(there are other numerically more stable versions available, but these are in general slower).
Fon non-Gaussian models the components corresponding to diffuse filtering
(Finf
, Pinf
, d
, Kinf
) are not returned even
when filtering
is used. Results based on approximating Gaussian model
can be obtained by running KFS
using the output of approxSSM
.
In case of non-Gaussian models with nsim = 0
, the smoothed estimates
relate to the conditional mode of p(\alpha|y)
. When using importance
sampling (nsim>0
), results correspond to the conditional mean of
p(\alpha|y)
.
What KFS
returns depends on the arguments filtering
,
smoothing
and simplify
, and whether the model is Gaussian or
not:
model |
Original state space model. |
KFS_transform |
How the non-diagonal |
logLik |
Value of the log-likelihood function. Only returned for fully Gaussian models. |
a |
One-step-ahead predictions of states, |
P |
Non-diffuse parts of the error covariance matrix of predicted states,
|
Pinf |
Diffuse part of the error covariance matrix of predicted states. Only returned for Gaussian models. |
att |
Filtered estimates of states, |
Ptt |
Non-diffuse parts of the error covariance matrix of filtered states,
|
t |
One-step-ahead predictions of signals, |
P_theta |
Non-diffuse part of |
m |
One-step-ahead predictions |
P_mu |
Non-diffuse part of |
alphahat |
Smoothed estimates of states, |
V |
Error covariance matrices of smoothed states, |
thetahat |
Smoothed estimates of signals, |
V_theta |
Error covariance matrices of smoothed signals
|
muhat |
Smoothed estimates of |
V_mu |
Error covariances |
etahat |
Smoothed disturbance terms |
V_eta |
Error covariances |
epshat |
Smoothed disturbance terms |
V_eps |
Diagonal elements of |
iterations |
The number of iterations used in linearization of non-Gaussian model. |
v |
Prediction errors
. Only returned for Gaussian models. |
F |
Prediction error variances |
Finf |
Diffuse part of prediction error variances. Only returned for Gaussian models. |
d |
The last time index of diffuse phase, i.e. the non-diffuse
phase began at time |
j |
The last observation index |
In addition, if argument simplify = FALSE
, list contains following
components:
K |
Covariances |
Kinf |
Diffuse part of |
r |
Weighted sums of innovations |
r0, r1 |
Diffuse phase decomposition of |
N |
Covariances |
N0, N1, N2 |
Diffuse phase decomposition of |
Koopman, S.J. and Durbin J. (2000). Fast filtering and
smoothing for non-stationary time series models, Journal of American
Statistical Assosiation, 92, 1630-38.
Koopman, S.J. and Durbin J. (2001). Time Series Analysis by State Space
Methods. Oxford: Oxford University Press.
Koopman, S.J. and Durbin J. (2003). Filtering and smoothing of state vector
for diffuse state space models, Journal of Time Series Analysis, Vol. 24,
No. 1.
KFAS
for examples
logLik
, KFAS
, fitSSM
,
boat
, sexratio
,
GlobalTemp
, SSModel
,
importanceSSM
, approxSSM
for examples.
set.seed(1)
x <- cumsum(rnorm(100, 0, 0.1))
y <- rnorm(100, x, 0.1)
model <- SSModel(y ~ SSMtrend(1, Q = 0.01), H = 0.01)
out <- KFS(model)
ts.plot(ts(x), out$a, out$att, out$alpha, col = 1:4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.