Efficient estimation of a Dynamic Factor Model via the EM Algorithm - on stationary data with time-invariant system matrices and classical assumptions, while permitting missing data.

DFM(
  X,
  r,
  p = 1L,
  ...,
  idio.ar1 = FALSE,
  rQ = c("none", "diagonal", "identity"),
  rR = c("diagonal", "identity", "none"),
  em.method = c("auto", "DGR", "BM", "none"),
  min.iter = 25L,
  max.iter = 100L,
  tol = 1e-04,
  pos.corr = TRUE,
  check.increased = FALSE
)

Arguments

X

a T x n numeric data matrix or frame of stationary time series. May contain missing values.

r

integer. number of factors.

p

integer. number of lags in factor VAR.

...

(optional) arguments to tsnarmimp.

idio.ar1

logical. Model observation errors as AR(1) processes: \(e_t = \rho e_{t-1} + v_t\). Note that this substantially increases computation time, and is generaly not needed if n is large (>30). See theoretical vignette for details.

rQ

character. restrictions on the state (transition) covariance matrix (Q).

rR

character. restrictions on the observation (measurement) covariance matrix (R).

em.method

character. The implementation of the Expectation Maximization Algorithm used. The options are:

"auto"Automatic selection: "BM" if anyNA(X), else "DGR".
"DGR"The classical EM implementation of Doz, Giannone and Reichlin (2012). This implementation is efficient and quite robust, missing values are removed on a casewise basis in the Kalman Filter and Smoother, but not explicitly accounted for in EM iterations.
"BM"The modified EM algorithm of Banbura and Modugno (2014) which also accounts for missing data in the EM iterations. Optimal for datasets with systematically missing data e.g. datasets with ragged edges or series at different frequencies.
"none"Performs no EM iterations and just returns the Two-Step estimates from running the data through the Kalman Filter and Smoother once as in Doz, Giannone and Reichlin (2011) (the Kalman Filter is Initialized with system matrices obtained from a regression and VAR on PCA factor estimates). This yields significant performance gains over the iterative methods. Final system matrices are estimated by running a regression and a VAR on the smoothed factors.
min.iter

integer. Minimum number of EM iterations (to ensure a convergence path).

max.iter

integer. Maximum number of EM iterations.

tol

numeric. EM convergence tolerance.

pos.corr

logical. Increase the likelihood that factors correlate positively with the data, by scaling the eigenvectors such that the principal components (used to initialize the Kalman Filter) co-vary positively with the row-means of the standardized data.

check.increased

logical. Check if likelihood has increased. Passed to em_converged. If TRUE, the algorithm only terminates if convergence was reached with decreasing likelihood.

Value

A list-like object of class 'dfm' with the following elements:

X_imp

\(T \times n\) matrix with the imputed and standardized (scaled and centered) data - with attributes attached allowing reconstruction of the original data:

"stats"is a \(n \times 5\) matrix of summary statistics of class "qsu" (see qsu).
"missing"is a \(T \times n\) logical matrix indicating missing or infinite values in the original data (which are imputed in X_imp).
"attributes"contains the attributes of the original data input.
"is.list"is a logical value indicating whether the original data input was a list / data frame.
eigen

eigen(cov(X_imp)).

F_pca

\(T \times r\) matrix of principal component factor estimates - X_imp %*% eigen$vectors.

P_0

\(r \times r\) initial factor covariance matrix estimate based on PCA results.

F_2s

\(T \times r\) matrix two-step factor estimates as in Doz, Giannone and Reichlin (2011) - obtained from running the data through the Kalman Filter and Smoother once, where the Filter is initialized with results from PCA.

P_2s

\(r \times r \times T\) covariance matrices of two-step factor estimates.

F_qml

\(T \times r\) matrix of quasi-maximum likelihood factor estimates - obtained by iteratively Kalman Filtering and Smoothing the factor estimates until EM convergence.

P_qml

\(r \times r \times T\) covariance matrices of QML factor estimates.

A

\(r \times rp\) factor transition matrix.

C

\(n \times r\) observation matrix.

Q

\(r \times r\) state (error) covariance matrix.

R

\(n \times n\) observation (error) covariance matrix.

e

\(T \times n\) estimates of observation errors \(\textbf{e}_t\). Only available if idio.ar1 = TRUE.

rho

\(n \times 1\) estimates of AR(1) coefficients (\(\rho\)) in observation errors: \(e_t = \rho e_{t-1} + v_t\). Only available if idio.ar1 = TRUE.

loglik

vector of log-likelihoods - one for each EM iteration. The final value corresponds to the log-likelihood of the reported model.

tol

The numeric convergence tolerance used.

converged

single logical valued indicating whether the EM algorithm converged (within max.iter iterations subject to tol).

anyNA

single logical valued indicating whether there were any (internal) missing values in the data (determined after removal of rows with too many missing values). If FALSE, X_imp is simply the original data in matrix form, and does not have the "missing" attribute attached.

rm.rows

vector of any cases (rows) that were removed beforehand (subject to max.missing and na.rm.method). If no cases were removed the slot is NULL.

em.method

The EM method used.

call

call object obtained from match.call().

Details

This function efficiently estimates a Dynamic Factor Model with the following classical assumptions:

  1. Linearity

  2. Idiosynchratic measurement (observation) errors (R is diagonal)

  3. No direct relationship between series and lagged factors (ceteris paribus contemporaneous factors)

  4. No relationship between lagged error terms in the either measurement or transition equation (no serial correlation), unless explicitly modeled as AR(1) processes using idio.ar1 = TRUE.

Factors are allowed to evolve in a \(VAR(p)\) process, and data is internally standardized (scaled and centered) before estimation (removing the need of intercept terms). By assumptions 1-4, this translates into the following dynamic form:

$$\textbf{x}_t = \textbf{C}_0 \textbf{f}_t + \textbf{e}_t \ \sim\ N(\textbf{0}, \textbf{R})$$ $$\textbf{f}_t = \sum_{j=1}^p \textbf{A}_j \textbf{f}_{t-j} + \textbf{u}_t \ \sim\ N(\textbf{0}, \textbf{Q}_0)$$

where the first equation is called the measurement or observation equation and the second equation is called transition, state or process equation, and

\(n\)number of series in \(\textbf{x}_t\) (\(r\) and \(p\) as the arguments to DFM).
\(\textbf{x}_t\)\(n \times 1\) vector of observed series at time \(t\): \((x_{1t}, \dots, x_{nt})'\). Some observations can be missing.
\(\textbf{f}_t\)\(r \times 1\) vector of factors at time \(t\): \((f_{1t}, \dots, f_{rt})'\).
\(\textbf{C}_0\)\(n \times r\) measurement (observation) matrix.
\(\textbf{A}_j\)\(r \times r\) state transition matrix at lag \(j\).
\(\textbf{Q}_0\)\(r \times r\) state covariance matrix.
\(\textbf{R}\)\(n \times n\) measurement (observation) covariance matrix. It is diagonal by assumption 2 that \(E[\textbf{x}_{it}|\textbf{x}_{-i,t},\textbf{x}_{i,t-1}, \dots, \textbf{f}_t, \textbf{f}_{t-1}, \dots] = \textbf{Cf}_t \forall i\).

This model can be estimated using a classical form of the Kalman Filter and the Expectation Maximization (EM) algorithm, after transforming it to State-Space (stacked, VAR(1)) form:

$$\textbf{x}_t = \textbf{C} \textbf{F}_t + \textbf{e}_t \ \sim\ N(\textbf{0}, \textbf{R})$$ $$\textbf{F}_t = \textbf{A F}_{t-1} + \textbf{u}_t \ \sim\ N(\textbf{0}, \textbf{Q})$$

where

\(n\)number of series in \(\textbf{x}_t\) (\(r\) and \(p\) as the arguments to DFM).
\(\textbf{x}_t\)\(n \times 1\) vector of observed series at time \(t\): \((x_{1t}, \dots, x_{nt})'\). Some observations can be missing.
\(\textbf{F}_t\)\(rp \times 1\) vector of stacked factors at time \(t\): \((f_{1t}, \dots, f_{rt}, f_{1,t-1}, \dots, f_{r,t-1}, \dots, f_{1,t-p}, \dots, f_{r,t-p})'\).
\(\textbf{C}\)\(n \times rp\) observation matrix. Only the first \(n \times r\) terms are non-zero, by assumption 3 that \(E[\textbf{x}_t|\textbf{F}_t] = E[\textbf{x}_t|\textbf{f}_t]\) (no relationship of observed series with lagged factors given contemporaneous factors).
\(\textbf{A}\)stacked \(rp \times rp\) state transition matrix consisting of 3 parts: the top \(r \times rp\) part provides the dynamic relationships captured by \((\textbf{A}_1, \dots, \textbf{A}_p)\) in the dynamic form, the terms A[(r+1):rp, 1:(rp-r)] constitute an \((rp-r) \times (rp-r)\) identity matrix mapping all lagged factors to their known values at times t. The remaining part A[(rp-r+1):rp, (rp-r+1):rp] is an \(r \times r\) matrix of zeros.
\(\textbf{Q}\)\(rp \times rp\) state covariance matrix. The top \(r \times r\) part gives the contemporaneous relationships, the rest are zeros by assumption 4.
\(\textbf{R}\)\(n \times n\) observation covariance matrix. It is diagonal by assumption 2 and identical to \(\textbf{R}\) as stated in the dynamic form.

References

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.

Doz, C., Giannone, D., & Reichlin, L. (2012). A quasi-maximum likelihood approach for large, approximate dynamic factor models. Review of Economics and Statistics, 94(4), 1014-1024.

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.

Stock, J. H., & Watson, M. W. (2016). Dynamic Factor Models, Factor-Augmented Vector Autoregressions, and Structural Vector Autoregressions in Macroeconomics. Handbook of Macroeconomics, 2, 415–525. https://doi.org/10.1016/bs.hesmac.2016.04.002

Examples

library(magrittr)
library(xts)
library(vars)
#> Loading required package: MASS
#> Loading required package: strucchange
#> Loading required package: sandwich
#> Loading required package: urca
#> Loading required package: lmtest

# BM14 Replication Data. Constructing the database:
BM14 = merge(BM14_M, BM14_Q)
BM14[, BM14_Models$log_trans] %<>% log()
BM14[, BM14_Models$freq == "M"] %<>% diff()
BM14[, BM14_Models$freq == "Q"] %<>% diff(3)


### Small Model ---------------------------------------

# IC for number of factors
IC_small = ICr(BM14[, BM14_Models$small], max.r = 5)
#> Missing values detected: imputing data with tsnarmimp() with default settings
plot(IC_small)

screeplot(IC_small)


# I take 2 factors. Now number of lags
VARselect(IC_small$F_pca[, 1:2])
#> $selection
#> AIC(n)  HQ(n)  SC(n) FPE(n) 
#>      6      5      2      6 
#> 
#> $criteria
#>                 1          2         3          4         5          6
#> AIC(n) -1.5028163 -1.7020957 -1.701093 -1.7021266 -1.782692 -1.7977899
#> HQ(n)  -1.4762557 -1.6578279 -1.639118 -1.6224446 -1.685303 -1.6826936
#> SC(n)  -1.4361151 -1.5909270 -1.545457 -1.5020229 -1.538121 -1.5087511
#> FPE(n)  0.2225028  0.1823018  0.182486  0.1822997  0.168192  0.1656763
#>                 7          8          9         10
#> AIC(n) -1.7892503 -1.7887748 -1.7793434 -1.7708400
#> HQ(n)  -1.6564469 -1.6382643 -1.6111258 -1.5849153
#> SC(n)  -1.4557440 -1.4108011 -1.3569022 -1.3039313
#> FPE(n)  0.1671036  0.1671913  0.1687862  0.1702408
#> 

# Estimating the model with 2 factors and 3 lags
dfm_small = DFM(BM14[, BM14_Models$small], 2, 3)
#> Converged after 26 iterations.

# Inspecting the model
summary(dfm_small)
#> Dynamic Factor Model: n = 14, T = 356, r = 2, p = 3, %NA = 38.3628
#> 
#> Call:  DFM(X = BM14[, BM14_Models$small], r = 2, p = 3)
#> 
#> Summary Statistics of Factors [F]
#>       N     Mean   Median      SD      Min     Max
#> f1  356  -0.0777   0.1544  2.0324  -8.9693  3.2519
#> f2  356   0.0468  -0.0279  1.3933  -4.2683  5.8201
#> 
#> Factor Transition Matrix [A]
#>     L1.f1   L1.f2    L2.f1   L2.f2   L3.f1    L3.f2
#> f1 1.2107 -0.1290 -0.06743  0.1059 -0.2065 0.008175
#> f2 0.3656  0.4819  0.10274 -0.2022 -0.6789 0.391439
#> 
#> Factor Covariance Matrix [cov(F)]
#>           f1        f2
#> f1   4.1307   -0.4890*
#> f2  -0.4890*   1.9412 
#> 
#> Factor Transition Error Covariance Matrix [Q]
#>        u1     u2
#> u1 0.2845 0.2434
#> u2 0.2434 0.4387
#> 
#> Observation Matrix [C]
#>                             f1      f2
#> ip_tot_cstr             0.2450  0.1850
#> new_cars                0.0245  0.0323
#> orders                  0.1669  0.1692
#> ret_turnover_defl       0.0493 -0.0062
#> ecs_ec_sent_ind         0.2450  0.4559
#> pms_pmi                 0.1196  0.4508
#> urx                    -0.3830  0.1478
#> extra_ea_trade_exp_val  0.0568  0.0847
#> euro325                 0.1207  0.2317
#> raw_mat                 0.0968  0.1707
#> gdp                     0.3666  0.0236
#> empl                    0.3661 -0.2945
#> capacity                0.2730 -0.1416
#> gdp_us                  0.2194  0.1953
#> 
#> Observation Error Covariance Matrix [diag(R) - Restricted]
#>            ip_tot_cstr               new_cars                 orders 
#>                 0.6374                 0.9906                 0.7938 
#>      ret_turnover_defl        ecs_ec_sent_ind                pms_pmi 
#>                 0.9863                 0.3405                 0.3814 
#>                    urx extra_ea_trade_exp_val                euro325 
#>                 0.1861                 0.9708                 0.8215 
#>                raw_mat                    gdp                   empl 
#>                 0.9028                 0.4079                 0.1488 
#>               capacity                 gdp_us 
#>                 0.5644                 0.7362 
#> 
#> Observation Residual Covariance Matrix [cov(resid(DFM))]
#>                        ip_tot_cstr  new_cars    orders ret_turnover_defl
#> ip_tot_cstr                0.6126   -0.0151    0.1996*          -0.0168 
#> new_cars                  -0.0151    0.9943   -0.0077            0.1269*
#> orders                     0.1996*  -0.0077    0.7827            0.0342 
#> ret_turnover_defl         -0.0168    0.1269*   0.0342            0.9885 
#> ecs_ec_sent_ind           -0.0074   -0.0312   -0.0863*          -0.0018 
#> pms_pmi                   -0.0591   -0.0482   -0.0184            0.0068 
#> urx                        0.0104   -0.0190    0.0524           -0.0095 
#> extra_ea_trade_exp_val     0.0737    0.0962    0.0760           -0.0145 
#> euro325                   -0.0294    0.0543   -0.0896            0.0140 
#> raw_mat                    0.0936    0.1054    0.0054            0.0392 
#> gdp                       -0.0178   -0.0432   -0.0163            0.0624 
#> empl                      -0.0335   -0.0505    0.0229            0.0005 
#> capacity                  -0.0503   -0.0134   -0.0238           -0.0375 
#> gdp_us                    -0.1565*   0.0034   -0.0046           -0.0659 
#>                        ecs_ec_sent_ind   pms_pmi       urx
#> ip_tot_cstr                   -0.0074   -0.0591    0.0104 
#> new_cars                      -0.0312   -0.0482   -0.0190 
#> orders                        -0.0863*  -0.0184    0.0524 
#> ret_turnover_defl             -0.0018    0.0068   -0.0095 
#> ecs_ec_sent_ind                0.2537   -0.0718*   0.0030 
#> pms_pmi                       -0.0718*   0.3167    0.0291 
#> urx                            0.0030    0.0291    0.1653 
#> extra_ea_trade_exp_val        -0.0657*  -0.0426    0.0045 
#> euro325                       -0.0290   -0.0365    0.0002 
#> raw_mat                       -0.0451    0.0409    0.0336 
#> gdp                           -0.0813*  -0.0211   -0.0020 
#> empl                           0.0453*   0.0421    0.0066 
#> capacity                      -0.0567   -0.0113    0.0380 
#> gdp_us                        -0.1000*  -0.0293    0.0423 
#>                        extra_ea_trade_exp_val   euro325   raw_mat       gdp
#> ip_tot_cstr                           0.0737   -0.0294    0.0936   -0.0178 
#> new_cars                              0.0962    0.0543    0.1054   -0.0432 
#> orders                                0.0760   -0.0896    0.0054   -0.0163 
#> ret_turnover_defl                    -0.0145    0.0140    0.0392    0.0624 
#> ecs_ec_sent_ind                      -0.0657*  -0.0290   -0.0451   -0.0813*
#> pms_pmi                              -0.0426   -0.0365    0.0409   -0.0211 
#> urx                                   0.0045    0.0002    0.0336   -0.0020 
#> extra_ea_trade_exp_val                0.9693    0.0141   -0.0336    0.0744 
#> euro325                               0.0141    0.8026    0.0103   -0.0458 
#> raw_mat                              -0.0336    0.0103    0.8897   -0.0561 
#> gdp                                   0.0744   -0.0458   -0.0561    0.3798 
#> empl                                 -0.0301    0.0173    0.0022   -0.0311 
#> capacity                             -0.0421   -0.0023   -0.2376*   0.1283*
#> gdp_us                               -0.0775    0.0616   -0.0399    0.0510 
#>                             empl  capacity    gdp_us
#> ip_tot_cstr             -0.0335   -0.0503   -0.1565*
#> new_cars                -0.0505   -0.0134    0.0034 
#> orders                   0.0229   -0.0238   -0.0046 
#> ret_turnover_defl        0.0005   -0.0375   -0.0659 
#> ecs_ec_sent_ind          0.0453*  -0.0567   -0.1000*
#> pms_pmi                  0.0421   -0.0113   -0.0293 
#> urx                      0.0066    0.0380    0.0423 
#> extra_ea_trade_exp_val  -0.0301   -0.0421   -0.0775 
#> euro325                  0.0173   -0.0023    0.0616 
#> raw_mat                  0.0022   -0.2376*  -0.0399 
#> gdp                     -0.0311    0.1283*   0.0510 
#> empl                     0.1155   -0.0515*  -0.0259 
#> capacity                -0.0515*   0.5558    0.1338*
#> gdp_us                  -0.0259    0.1338*   0.7093 
#> 
#> Residual AR(1) Serial Correlation
#>            ip_tot_cstr               new_cars                 orders 
#>               -0.37927               -0.40846               -0.41429 
#>      ret_turnover_defl        ecs_ec_sent_ind                pms_pmi 
#>               -0.49173               -0.12364                0.09490 
#>                    urx extra_ea_trade_exp_val                euro325 
#>                0.01165               -0.52365                0.24452 
#>                raw_mat                    gdp                   empl 
#>                0.26723                     NA                     NA 
#>               capacity                 gdp_us 
#>                     NA                     NA 
#> 
#> Summary of Residual AR(1) Serial Correlations
#>    N     Mean   Median      SD      Min     Max
#>   10  -0.1723  -0.2515  0.3086  -0.5237  0.2672
#> 
#> Goodness of Fit: R-Squared
#>            ip_tot_cstr               new_cars                 orders 
#>                 0.3874                 0.0057                 0.2173 
#>      ret_turnover_defl        ecs_ec_sent_ind                pms_pmi 
#>                 0.0115                 0.7463                 0.6833 
#>                    urx extra_ea_trade_exp_val                euro325 
#>                 0.8347                 0.0307                 0.1974 
#>                raw_mat                    gdp                   empl 
#>                 0.1103                 0.6202                 0.8845 
#>               capacity                 gdp_us 
#>                 0.4442                 0.2907 
#> 
#> Summary of Individual R-Squared's
#>    N    Mean  Median      SD     Min     Max
#>   14  0.3903  0.3391  0.3146  0.0057  0.8845
plot(dfm_small)  # Factors and data

plot(dfm_small, method = "all", type = "individual") # Factor estimates

plot(dfm_small, type = "residual") # Residuals from factor predictions


# 10 periods ahead forecast
plot(predict(dfm_small), xlim = c(300, 370))



### Medium-Sized Model ---------------------------------

# IC for number of factors
IC_medium = ICr(BM14[, BM14_Models$medium])
#> Missing values detected: imputing data with tsnarmimp() with default settings
plot(IC_medium)

screeplot(IC_medium)


# I take 3 factors. Now number of lags
VARselect(IC_medium$F_pca[, 1:3])
#> $selection
#> AIC(n)  HQ(n)  SC(n) FPE(n) 
#>      7      2      1      7 
#> 
#> $criteria
#>               1        2        3        4        5        6        7        8
#> AIC(n) 1.539267 1.492781 1.498671 1.509014 1.486111 1.479450 1.468524 1.490378
#> HQ(n)  1.592388 1.585744 1.631474 1.681659 1.698597 1.731776 1.760691 1.822386
#> SC(n)  1.672669 1.726236 1.832177 1.942573 2.019721 2.113112 2.202238 2.324143
#> FPE(n) 4.661186 4.449528 4.475952 4.522752 4.420750 4.391987 4.345059 4.442132
#>               9       10
#> AIC(n) 1.500199 1.534401
#> HQ(n)  1.872048 1.946092
#> SC(n)  2.434016 2.568271
#> FPE(n) 4.487352 4.645257
#> 

# Estimating the model with 3 factors and 3 lags
dfm_medium = DFM(BM14[, BM14_Models$medium], 3, 3)
#> Converged after 26 iterations.

# Inspecting the model
summary(dfm_medium)
#> Dynamic Factor Model: n = 48, T = 356, r = 3, p = 3, %NA = 32.6135
#> 
#> Call:  DFM(X = BM14[, BM14_Models$medium], r = 3, p = 3)
#> 
#> Summary Statistics of Factors [F]
#>       N     Mean   Median      SD       Min     Max
#> f1  356  -0.0403   0.4214  2.9848  -17.3578  5.4713
#> f2  356  -0.0109  -0.2687  2.0526   -4.8352  8.2507
#> f3  356  -0.0274   -0.119  1.5727   -6.8234  4.0181
#> 
#> Factor Transition Matrix [A]
#>       L1.f1    L1.f2   L1.f3    L2.f1     L2.f2   L2.f3    L3.f1   L3.f2
#> f1  0.74619  0.08633 0.28267  0.06055 -0.045219 -0.1494  0.07457 0.05102
#> f2 -0.01289  0.40113 0.04716 -0.09857  0.104393  0.1231 -0.09578 0.24146
#> f3  0.14844 -0.06662 0.41315 -0.01687 -0.001667 -0.1762 -0.14472 0.15933
#>       L3.f3
#> f1  0.06631
#> f2 -0.02438
#> f3  0.15381
#> 
#> Factor Covariance Matrix [cov(F)]
#>          f1       f2       f3
#> f1  8.9091   0.2889   0.2680 
#> f2  0.2889   4.2132   0.0017 
#> f3  0.2680   0.0017   2.4733 
#> 
#> Factor Transition Error Covariance Matrix [Q]
#>         u1      u2      u3
#> u1  2.1176  1.1526 -0.3597
#> u2  1.1526  1.9879 -0.4395
#> u3 -0.3597 -0.4395  2.0555
#> 
#> Summary of Residual AR(1) Serial Correlations
#>    N     Mean   Median      SD      Min     Max
#>   39  -0.0879  -0.1043  0.2624  -0.5417  0.4481
#> 
#> Summary of Individual R-Squared's
#>    N   Mean  Median      SD     Min     Max
#>   48  0.381  0.3489  0.2986  0.0073  0.9311
plot(dfm_medium)  # Factors and data

plot(dfm_medium, method = "all", type = "individual") # Factor estimates

plot(dfm_medium, type = "residual") # Residuals from factor predictions


# 10 periods ahead forecast
plot(predict(dfm_medium), xlim = c(300, 370))



### Large Model ---------------------------------
# \donttest{
# IC for number of factors
IC_large = ICr(BM14)
#> Missing values detected: imputing data with tsnarmimp() with default settings
plot(IC_large)

screeplot(IC_large)


# I take 6 factors. Now number of lags
VARselect(IC_large$F_pca[, 1:6])
#> $selection
#> AIC(n)  HQ(n)  SC(n) FPE(n) 
#>      6      1      1      6 
#> 
#> $criteria
#>                 1          2          3          4          5          6
#> AIC(n)   6.020768   5.926947   5.883307   5.889824   5.897327   5.845883
#> HQ(n)    6.206692   6.272235   6.387960   6.553841   6.720708   6.828628
#> SC(n)    6.487677   6.794063   7.150631   7.557355   7.965066   8.313830
#> FPE(n) 411.908362 375.087393 359.232802 361.888929 365.116976 347.515300
#>                 7          8          9         10
#> AIC(n)   5.908082   5.963699   5.982969   6.111831
#> HQ(n)    7.050191   7.265172   7.443806   7.732032
#> SC(n)    8.776235   9.232061   9.651538  10.180607
#> FPE(n) 370.862536 393.546431 403.139879 461.355079
#> 

# Estimating the model with 6 factors and 3 lags
dfm_large = DFM(BM14, 6, 3)
#> Converged after 42 iterations.

# Inspecting the model
summary(dfm_large)
#> Dynamic Factor Model: n = 101, T = 356, r = 6, p = 3, %NA = 29.7363
#> 
#> Call:  DFM(X = BM14, r = 6, p = 3)
#> 
#> Summary Statistics of Factors [F]
#>       N     Mean   Median      SD       Min      Max
#> f1  356  -0.0128   0.6589  4.8593  -22.6273  12.1396
#> f2  356  -0.1426   0.1953  3.2924  -13.4553  17.0049
#> f3  356  -0.0121   0.0539  2.6158  -10.0501    7.645
#> f4  356   0.0532    0.227  3.0551  -17.2138   10.345
#> f5  356  -0.0526  -0.0474  2.6591  -10.8706  11.5097
#> f6  356  -0.0074  -0.0276  2.3392   -8.0883  15.4214
#> 
#> Factor Transition Matrix [A]
#>      L1.f1    L1.f2     L1.f3    L1.f4    L1.f5    L1.f6    L2.f1    L2.f2
#> f1  0.4892 -0.27413  0.555373 -0.49350  0.33904 -0.10227 -0.10721  0.04923
#> f2 -0.1409  0.42355 -0.119072 -0.09760  0.11595  0.14366  0.19016 -0.06640
#> f3  0.2769  0.06985  0.394982  0.10002 -0.12723 -0.11881 -0.20734  0.04944
#> f4 -0.2432 -0.03345  0.085401 -0.18619  0.52093 -0.04263  0.01735 -0.17177
#> f5  0.2858  0.01547 -0.008841  0.40969  0.07289  0.01797 -0.01169  0.16386
#> f6 -0.2178  0.12874 -0.113025 -0.03033 -0.09462  0.40510  0.10945 -0.09195
#>       L2.f3    L2.f4    L2.f5    L2.f6     L3.f1    L3.f2     L3.f3     L3.f4
#> f1 -0.23156 -0.14988 -0.06505  0.50861  0.367040 -0.11658  0.070419  0.008798
#> f2  0.07793 -0.07484  0.21098 -0.19913  0.091421  0.22904  0.008526 -0.142987
#> f3 -0.32524  0.23108 -0.07323  0.10170 -0.004843 -0.10569  0.186417  0.121418
#> f4  0.08269 -0.19694  0.05137  0.11849  0.054295 -0.13206 -0.029156  0.100593
#> f5 -0.12568 -0.01248 -0.15211 -0.01158 -0.145431  0.01864  0.038644  0.038082
#> f6  0.11387 -0.08252  0.14040 -0.19996  0.015064  0.05480  0.060205 -0.111405
#>       L3.f5    L3.f6
#> f1  0.13116 -0.02589
#> f2  0.02080  0.17876
#> f3 -0.12427 -0.03180
#> f4 -0.05662  0.06638
#> f5  0.02519 -0.18284
#> f6  0.05736  0.10027
#> 
#> Factor Covariance Matrix [cov(F)]
#>           f1        f2        f3        f4        f5        f6
#> f1  23.6126   -0.2329    0.1166    4.0970*  -2.4727*  -2.8984*
#> f2  -0.2329   10.8399   -1.8458*   0.6389   -1.1282*   2.1751*
#> f3   0.1166   -1.8458*   6.8426   -1.6781*   1.6056*  -1.2712*
#> f4   4.0970*   0.6389   -1.6781*   9.3339   -4.2441*  -0.0480 
#> f5  -2.4727*  -1.1282*   1.6056*  -4.2441*   7.0708   -0.6045 
#> f6  -2.8984*   2.1751*  -1.2712*  -0.0480   -0.6045    5.4720 
#> 
#> Factor Transition Error Covariance Matrix [Q]
#>         u1      u2      u3      u4      u5      u6
#> u1  9.4291 -0.3199 -1.3015  2.2611 -2.0748  0.0669
#> u2 -0.3199  5.3107  0.0049  0.8209 -0.5604 -0.0135
#> u3 -1.3015  0.0049  4.3942 -0.5711  0.4848  0.0342
#> u4  2.2611  0.8209 -0.5711  4.8600 -1.6002  0.1788
#> u5 -2.0748 -0.5604  0.4848 -1.6002  4.4129 -0.0902
#> u6  0.0669 -0.0135  0.0342  0.1788 -0.0902  3.2699
#> 
#> Summary of Residual AR(1) Serial Correlations
#>    N     Mean   Median      SD      Min     Max
#>   92  -0.0706  -0.0965  0.2712  -0.5567  0.6628
#> 
#> Summary of Individual R-Squared's
#>     N    Mean  Median      SD     Min     Max
#>   101  0.4677  0.4352  0.2929  0.0096  0.9984
plot(dfm_large)  # Factors and data

# plot(dfm_large, method = "all", type = "individual") # Factor estimates
plot(dfm_large, type = "residual") # Residuals from factor predictions


# 10 periods ahead forecast
plot(predict(dfm_large), xlim = c(300, 370))

# }