You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/introduction.Rmd
+18-20Lines changed: 18 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -88,15 +88,15 @@ Estimation can then simply be done using the `DFM()` function with parameters `r
88
88
89
89
```{r}
90
90
# Estimating the model with 4 factors and 3 lags using BM14's EM algorithm
91
-
model1 <- DFM(BM14_M_diff, r = 4, p = 3)
92
-
print(model1)
93
-
plot(model1)
91
+
model_m <- DFM(BM14_M_diff, r = 4, p = 3)
92
+
print(model_m)
93
+
plot(model_m)
94
94
```
95
95
96
96
The model can be investigated using `summary()`, which returns an object of class 'dfm_summary' containing the system matrices and summary statistics of the factors and the residuals in the measurement equation, as well as the R-Squared of the factor model for individual series. The print method automatically adjusts the amount of information printed to the data size. For large databases with more than 40 series, no series-level statistics are printed.
97
97
98
98
```{r}
99
-
dfm_summary <- summary(model1)
99
+
dfm_summary <- summary(model_m)
100
100
print(dfm_summary) # Large model with > 40 series: defaults to compact = 2
101
101
102
102
# Can request more detailed printouts
@@ -107,47 +107,45 @@ print(dfm_summary) # Large model with > 40 series: defaults to compact = 2
107
107
Apart from the model summary, the *dfm* methods `residuals()` and `fitted()` return observation residuals and fitted values from the model. The default format is a plain matrix, but the functions also have an argument to return data in the original (input) format.
108
108
109
109
```{r}
110
-
plot(resid(model1, orig.format = TRUE))
111
-
plot(fitted(model1, orig.format = TRUE))
110
+
plot(resid(model_m, orig.format = TRUE))
111
+
plot(fitted(model_m, orig.format = TRUE))
112
112
```
113
113
114
114
115
115
116
116
Another way to examine the factor model visually is to plot the Quasi-Maximum-Likelihood (QML) factor estimates against PCA and Two-Step estimates following Doz, Giannone and Reichlin (2011)^[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.], where the Kalman Filter and Smoother is run only once. Both estimates are also computed by `DFM()` during EM estimation and can also be visualized with `plot.dfm`.
117
117
118
118
```{r}
119
-
plot(model1, method = "all", type = "individual")
119
+
plot(model_m, method = "all", type = "individual")
120
120
```
121
121
122
-
The plot with the various estimates shows that the QML estimates are more volatile in the initial periods where there are many missing series, but less volatile in the latter periods. In general, QML estimates may now always be superior across the entire data range to Two-Step and PCA estimates. Often, Two-Step estimates also provide similar forecasting performance, and are much faster to estimate using `DFM(BM14_M_diff, r = 4, p = 3, em.method = "none")`.
122
+
The plot with the various estimates shows that the QML estimates are more volatile in the initial periods where there are many missing series, but less volatile in the latter periods. In general, QML estimates may not always be superior across the entire data range to Two-Step and PCA estimates. Often, Two-Step estimates also provide similar forecasting performance, and are much faster to estimate using `DFM(BM14_M_diff, r = 4, p = 3, em.method = "none")`.
123
123
124
124
The factor estimates themselves can be extracted in a data frame using `as.data.frame()`, which also provides various options regarding the estimates retained and the format of the frame. It is also possible to add a time variable from the original data (the default is a sequence of integers).
125
125
126
126
```{r}
127
127
# Default: all estimates in long format
128
-
head(as.data.frame(model1, time = index(BM14_M_diff)))
128
+
head(as.data.frame(model_m, time = index(BM14_M_diff)))
129
129
```
130
130
131
131
## Forecasting
132
132
133
-
DFM forecasts can be obtained with the `predict()` method, which dynamically forecasts the factors using the transition equation (default 10 periods), and then also predicts data forecasts using the observation equation. Objects are of class 'dfm_forecast'
133
+
DFM forecasts can be obtained with the `predict()` method, which dynamically forecasts the factors using the transition equation (default 10 periods), and then also predicts data forecasts using the observation equation. Objects are of class 'dfm_forecast'.
134
134
135
135
```{r}
136
136
# 12-period ahead DFM forecast
137
-
fc <- predict(model1, h = 12)
137
+
fc <- predict(model_m, h = 12)
138
138
print(fc)
139
139
```
140
140
141
141
These forecasts can also be visualized using a plot method. By default the entire series history is plotted along with the forecasts, thus it is often helpful to restrict the plot range. As with any stationary autoregressive model, the forecasts tend to zero quite quickly^[Depending also on the lag-order of the factor-VAR. Higher lag-orders product more interesting forecast dynamics.].
142
142
```{r}
143
143
# Setting an appropriate plot range to see the forecast
By default, `predict()` uses the QML factor estimates (if available). We can however also predict with PCA or TwoStep estimates using, e.g., `predict(model_m, h = 12, method = "2s")`.
148
147
149
-
150
-
The forecasts can also be retrieved in data frame using `as.data.frame()`. Again the method has various arguments to control the forecasts retained (factors, data or both, default factors), and the format of the frame.
148
+
The forecasts can be retrieved in data frame using `as.data.frame()`. Again the method has various arguments to control the output (factors, data, or both --- default factors) and the format of the frame.
Since v0.3.0 *dfms* allows monthly and quarterly mixed frequency estimation following Mariano & Murasawa (2003) and Banbura & Modugno (2014). Quarterly variables should be to the right of the monthly variables in the data matrix and need to be indicated using the `quarterly.vars` argument. Quarterly observations should be provided every 3rd period.
157
+
Since v0.3.0,*dfms* allows monthly and quarterly mixed frequency estimation following Mariano & Murasawa (2003) and Banbura & Modugno (2014). Quarterly variables should be to the right of the monthly variables in the data matrix and need to be indicated using the `quarterly.vars` argument. Quarterly observations should be provided every 3rd period (months 3, 6, 9, and 12). Below, I estimate the mixed frequency DFM, adding a factor to capture any idiosynchratic dynamics in the quarterly series.
160
158
161
159
<!--
162
160
The baseline algorithm of BM14, being designed for arbitrary patterns of missing data, allows lower frequency series to be included in the estimation. The problem here is that series at lower frequency contain many missing values, which effectively lets these series have less weight in the estimation.
0 commit comments