These functions are based on the MATLAB functions of Giannone et. al. (2008).
Let us define as our standardized variables. Then, the factor model has the following representation:
where is an
matrix of factor loadings,
is the idiosyncratic component,
represents the unobserved common factors following a vector autoregression process (VAR) as follows:
where is an
matrix of full rank
with
,
are
matrices of autoregressive coefficients, and
is the
dimensional vector of common shocks, which follows a white-noise process.
Set of equations defined above is estimated using the two step estimation procedure of Doz et. al. (2011) as follows:
- All variables are standardized in the first step.
- First
principal components are extracted from the balanced part of the data set where all observations are present and obtain the initial factor estimates and parameters using the function
ricSW(z, q, r, p)
.represents the balanced part of the data set.
- Before moving to the Kalman smoother part, the ragged edge part of the data set are incorporated into the procedure by assigning an extremely large value to the variance of the idiosyncratic component where there is missing observations and replacing missing values in
with arbitrary values.
- Factors are re-estimated using one run of the Kalman filter function
kalman_filter_diag(y, A, C, Q, R, init_x, init_V, model)
and one run of the Kalman smoother functionkalman_smoother_diag(y, A, C, Q, R, init_x, init_V, model)
while incorporating the unbalanced part of the data set.
Load FRED-MD Data Set
load(url("https://github.com/Soybilgen/2_Step_Estimator_DFM/raw/master/Example.RData"))
Load necessary functions
source("https://github.com/raw/Soybilgen/2_Step_Estimator_DFM/master/FactorExtraction.R")
source("https://github.com/raw/Soybilgen/2_Step_Estimator_DFM/master/center.R")
source("https://github.com/raw/Soybilgen/2_Step_Estimator_DFM/master/kalman_filter_diag.R")
source("https://github.com/raw/Soybilgen/2_Step_Estimator_DFM/master/kalman_smoother_diag.R")
source("https://github.com/raw/Soybilgen/2_Step_Estimator_DFM/master/kalman_update_diag.R")
source("https://github.com/raw/Soybilgen/2_Step_Estimator_DFM/master/ricSW.R")
source("https://github.com/raw/Soybilgen/2_Step_Estimator_DFM/master/smooth_update.R")
Load necessary packages
install.packages("pracma") # Numeric Analysis Package
install.packages("RSpectra") # Solvers for Large-Scale Eigenvalue and SVD Problems
Determine the DFM specification
q <- 2 # dynamic factors
r <- 5 # static factors
p <- 4 # VAR lag
Estimate the DFM and obtain dynamic factors
result <- FactorExtraction(x, q, r, p)
Dynamic_Factors <- result$F
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.