sparseDFM {sparseDFM} | R Documentation |
Estimate a Sparse Dynamic Factor Model
Description
Main function to allow estimation of a DFM or a sparse DFM (with sparse loadings) on stationary data that may have arbitrary patterns of missing data. We allow the user:
an option for estimation method -
"PCA"
,"2Stage"
,"EM"
or"EM-sparse"
an option for
IID
orAR1
idiosyncratic errorsan option for Kalman Filter/Smoother estimation using standard
multivariate
equations or fastunivariate
filtering equations
Usage
sparseDFM(
X,
r,
q = 0,
alphas = logspace(-2, 3, 100),
alg = "EM-sparse",
err = "IID",
kalman = "univariate",
store.parameters = FALSE,
standardize = TRUE,
max_iter = 100,
threshold = 1e-04
)
Arguments
X |
| |||||||||||||||||
r |
Integer. Number of factors. | |||||||||||||||||
q |
Integer. The first q series (columns of X) should not be made sparse. Default q = 0. | |||||||||||||||||
alphas |
Numeric vector or value of LASSO regularisation parameters. Default is alphas = logspace(-2,3,100). | |||||||||||||||||
alg |
Character. Option for estimation algorithm. Default is
| |||||||||||||||||
err |
Character. Option for idiosyncratic errors. Default is
| |||||||||||||||||
kalman |
Character. Option for Kalman filter and smoother equations. Default is
| |||||||||||||||||
store.parameters |
Logical. Store outputs for every alpha L1 penalty parameter. Default is FALSE. | |||||||||||||||||
standardize |
Logical. Standardize the data before estimating the model. Default is | |||||||||||||||||
max_iter |
Integer. Maximum number of EM iterations. Default is 100. | |||||||||||||||||
threshold |
Numeric. Tolerance on EM iterates. Default is 1e-4. |
Details
For full details of the model please refer to Mosley et al. (2023).
Value
A list-of-lists-like S3 object of class 'sparseDFM' with the following elements:
data |
A list containing information about the data with the following elements:
| |||||||||||||||||||||||||||||||||||||||||||||
params |
A list containing the estimated parameters of the model with the following elements:
| |||||||||||||||||||||||||||||||||||||||||||||
state |
A list containing the estimated states and state covariances with the following elements:
| |||||||||||||||||||||||||||||||||||||||||||||
em |
A list containing information about the EM algorithm with the following elements:
| |||||||||||||||||||||||||||||||||||||||||||||
alpha.output |
Parameter and state outputs for each L1-norm penalty parameter in |
References
Banbura, M., & Modugno, M. (2014). Maximum likelihood estimation of factor models on datasets with arbitrary pattern of missing data. Journal of Applied Econometrics, 29(1), 133-160.
Doz, C., Giannone, D., & Reichlin, L. (2011). A two-step estimator for large approximate dynamic factor models based on Kalman filtering. Journal of Econometrics, 164(1), 188-205.
Giannone, D., Reichlin, L., & Small, D. (2008). Nowcasting: The real-time informational content of macroeconomic data. Journal of monetary economics, 55(4), 665-676.
Koopman, S. J., & Durbin, J. (2000). Fast filtering and smoothing for multivariate state space models. Journal of Time Series Analysis, 21(3), 281-296.
Mosley, L., Chan, TS., & Gibberd, A. (2023). sparseDFM: An R Package to Estimate Dynamic Factor Models with Sparse Loadings.
Shumway, R. H., & Stoffer, D. S. (1982). An approach to time series smoothing and forecasting using the EM algorithm. Journal of time series analysis, 3(4), 253-264.
Stock, J. H., & Watson, M. W. (2002). Forecasting using principal components from a large number of predictors. Journal of the American statistical association, 97(460), 1167-1179.
Examples
# load inflation data set
data = inflation
# reduce the size for these examples - full data found in vignette
data = data[1:60,]
# make stationary by taking first differences
new_data = transformData(data, rep(2,ncol(data)))
# tune for the number of factors to use
tuneFactors(new_data, type = 2)
# fit a PCA using 3 PC's
fit.pca <- sparseDFM(new_data, r = 3, alg = 'PCA')
# fit a DFM using the two-stage approach
fit.2stage <- sparseDFM(new_data, r = 3, alg = '2Stage')
# fit a DFM using EM algorithm with 3 factors
fit.dfm <- sparseDFM(new_data, r = 3, alg = 'EM')
# fit a Sparse DFM with 3 factors
fit.sdfm <- sparseDFM(new_data, r = 3, alg = 'EM-sparse')
# observe the factor loadings of the sparse DFM
plot(fit.sdfm, type = 'loading.heatmap')
# observe the factors
plot(fit.sdfm, type = 'factor')
# observe the residuals
plot(fit.sdfm, type = 'residual')
# observe the LASSO parameter selected and BIC values
plot(fit.sdfm, type = 'lasso.bic')
# predict 3 steps ahead
predict(fit.sdfm, h = 3)