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
)
What KFS
returns depends on the arguments filtering
,
smoothing
and simplify
, and whether the model is Gaussian or
not:
Original state space model.
How the non-diagonal H
was handled.
Value of the log-likelihood function. Only returned for fully Gaussian models.
One-step-ahead predictions of states,
Non-diffuse parts of the error covariance matrix of predicted states,
Diffuse part of the error covariance matrix of predicted states. Only returned for Gaussian models.
Filtered estimates of states,
Non-diffuse parts of the error covariance matrix of filtered states,
One-step-ahead predictions of signals,
Non-diffuse part of
One-step-ahead predictions
Non-diffuse part of nsim = 0
, only diagonal elements (variances) are computed, using the
Delta method.
Smoothed estimates of states,
Error covariance matrices of smoothed states,
Smoothed estimates of signals,
Error covariance matrices of smoothed signals
Smoothed estimates of
Error covariances nsim = 0
, only diagonal elements (variances) are
computed, using the Delta method.
Smoothed disturbance terms
Error covariances rstandard.KFS
.
Smoothed disturbance terms
Diagonal elements of rstandard.KFS
.
The number of iterations used in linearization of non-Gaussian model.
Prediction errors
Prediction error variances
Diffuse part of prediction error variances. Only returned for Gaussian models.
The last time index of diffuse phase, i.e. the non-diffuse
phase began at time
The last observation index
In addition, if argument simplify = FALSE
, list contains following
components:
Covariances
Diffuse part of
Weighted sums of innovations
Diffuse phase decomposition of
Covariances
Diffuse phase decomposition of
Object of class SSModel
.
Types of filtering. Possible choices are "state"
,
"signal"
, "mean"
, and "none"
. Default is
"state"
for Gaussian and "none"
for non-Gaussian models.
Multiple values are allowed. For Gaussian models, the signal is the mean.
Note that filtering for non-Gaussian models with importance sampling can be
very slow with large models.
Types of smoothing. Possible choices are "state"
,
"signal"
, "mean"
, "disturbance"
, and "none"
. Default is "state"
and "mean"
. For
non-Gaussian models, option "disturbance"
is not supported, and for
Gaussian models option "mean"
is identical to "signal"
. Multiple values are
allowed.
If FALSE
and the model is completely Gaussian, KFS
returns some
generally not so interesting variables from filtering and smoothing. Default
is TRUE
.
How to transform the model in case of non-diagonal
covariance matrix H
. Defaults to "ldl"
. See function
transformSSM
for details.
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 approxSSM
and performs the
usual Gaussian filtering/smoothing so that the smoothed state estimates
equals to the conditional mode of nsim = 0
, the mean estimates and their variances are computed using
the Delta method (ignoring the covariance terms).
Initial values for conditional mode theta. Only used for non-Gaussian models.
The maximum number of iterations used in Gaussian approximation. Default is 50. Only used for non-Gaussian models.
Tolerance parameter for convergence checks for Gaussian approximation. Only used for non-Gaussian models.
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 KFS
use this model so this will not work if return_model=FALSE
.
Logical value defining the approximation of H_t in case of Gamma
and negative binomial distribution. Default is FALSE
which matches the
algorithm of Durbin & Koopman (1997), whereas TRUE
uses the expected value
of observations in the equations, leading to results which match with glm
(where applicable).
The latter case was the default behaviour of KFAS before version 1.3.8.
Essentially this is the difference between observed and expected information in the GLM context.
Only used for non-Gaussian model.
Tolerance parameter for check max(H) > tol_H
, which suggests that the approximation
converged to degenerate case with near zero signal-to-noise ratio. Default is very generous 1e15.
Only used for non-Gaussian model.
Tolerance parameter for LDL decomposition in case of a
non-diagonal H and transform = "ldl"
. See transformSSM
and
ldl
for details.
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
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 nsim>0
), results correspond to the conditional mean 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)
Run the code above in your browser using DataLab