fdlm_factor: Sample the dynamic factors

Description Usage Arguments Value Note Examples

View source: R/component_samplers.R

Description

Sample the dynamic factors (latent state space variables) using the simulation smoothing algorithm of Koopman and Durbin (2001), implemented in the KFAS package.

Usage

1
2
fdlm_factor(Y, sigma_et, Wt, Fmat = NULL, YF = NULL, Gt = NULL,
  W0 = NULL, kfas_model = NULL, useFastImpute = FALSE)

Arguments

Y

the T x m data observation matrix, where T is the number of time points and m is the number of observation points (NAs allowed)

sigma_et

T- or 1-dimensional vector of observation error standard deviation(s)

Wt

K x K matrix or K x K x T array of evolution error covariances

Fmat

m x K matrix of FLCs; only needed for useFastImpute = FALSE

YF

T x K matrix of data Y projected onto FLCs, Y%*%Fmat, which takes the place of Y; only needed for useFastImpute = TRUE

Gt

K x K evolution matrix; if NULL, set as identity (for random walk)

W0

K x K matrix of initial evolution error covariances; if NULL, set to diag(10^-4, K)

kfas_model

SSModel object from KFAS package; if NULL, construct model w/in the sampler (might be slower!)

useFastImpute

logical; when TRUE, use imputation/projection scheme for the dynamic factors; otherwise use full state space model for factors (slower)

Value

The T x K matrix of dynamic factors, Beta.

Note

The sampler has two options: useFastImpute = TRUE, in which the response is YF = Y%*%Fmat (T x K) and the observation matrix is the identity (K x K); and useFastImpute = FALSE, in which the response is Y (T x m) and the observation matrix is Fmat (m x K). Recall that typically K < < m, so useFastImpute = TRUE is often much faster.

Examples

1
2
3
4
5
6
7
8
9
# Read in the yield curve data:
data("US_Yields")

# Restrict to dates since 2006:
Y = Y[which(dates > as.Date("2006-01-01")),];

# This is a simple (yet meaningless) example:
K = 3
Beta = fdlm_factor(Y, sigma_et = 1, Wt = diag(K), Fmat = diag(ncol(Y))[,1:K])

drkowal/FDLM documentation built on May 20, 2019, 5:20 p.m.