| convert | R Documentation |
Converts a dfm object to the state space representation used by
the dlm or KFAS packages, enabling their forecasting, smoothing,
and prediction-interval functionality.
convert(object, ...)
## S3 method for class 'dfm'
convert(object, to = c("KFAS", "dlm"), ...)
object |
an object of class 'dfm'. |
... |
other arguments |
to |
character, target package format: |
The DFM is defined by the state space model:
Observation equation: X_t = C F_t + e_t,
e_t \sim N(0, R)
Transition equation: F_t = A F_{t-1} + u_t,
u_t \sim N(0, Q)
where F_t is the companion-form state vector of length r \cdot p
and A is the companion transition matrix [r \cdot p \times r \cdot p].
For dlm: The system matrices map directly — FF = C,
GG = A, V = R, W = Q, with initial state m0 = F[1,]
and covariance C0 = P[,,1]. The user should pass standardized (scaled and centered)
data when using further dlm functions.
For KFAS: An SSModel is built via SSMcustom with
Z = C, T = A, R = I, Q = Q, H = R with initial state
a1 = F[1,] and covariance P1 = P[,,1]. The standardized data with
original missing values restored is embedded in the model object y = X.
For to = "dlm": a dlm object (see
dlm).
For to = "KFAS": an SSModel object (see
SSModel).
## Not run:
mod <- DFM(BM14_Q, r=2, p=3)
# Convert to dlm and run filter extract prediction variance
if (requireNamespace("dlm", quietly = TRUE)) {
dlm_mod <- convert(mod, to = "dlm")
# Pass standardized data (scale each column) to dlmFilter
fitf <- dlm::dlmFilter(scale(BM14_Q), dlm_mod)
dlm::dlmSvd2var(fitf$U.R, fitf$D.R)
}
# Convert to KFAS and compute prediction intervals
if (requireNamespace("KFAS", quietly = TRUE)) {
kfas_mod <- convert(mod, to = "KFAS")
predict(kfas_mod, n.ahead = 10, interval = "prediction",
level = 0.95)
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.