Skip to content

Commit 3c724f8

Browse files
committed
Minors.
1 parent f56b22e commit 3c724f8

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

vignettes/introduction.Rmd

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ Estimation can then simply be done using the `DFM()` function with parameters `r
8888

8989
```{r}
9090
# 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)
9494
```
9595

9696
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.
9797

9898
```{r}
99-
dfm_summary <- summary(model1)
99+
dfm_summary <- summary(model_m)
100100
print(dfm_summary) # Large model with > 40 series: defaults to compact = 2
101101
102102
# Can request more detailed printouts
@@ -107,47 +107,45 @@ print(dfm_summary) # Large model with > 40 series: defaults to compact = 2
107107
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.
108108

109109
```{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))
112112
```
113113

114114

115115

116116
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`.
117117

118118
```{r}
119-
plot(model1, method = "all", type = "individual")
119+
plot(model_m, method = "all", type = "individual")
120120
```
121121

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")`.
123123

124124
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).
125125

126126
```{r}
127127
# 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)))
129129
```
130130

131131
## Forecasting
132132

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'.
134134

135135
```{r}
136136
# 12-period ahead DFM forecast
137-
fc <- predict(model1, h = 12)
137+
fc <- predict(model_m, h = 12)
138138
print(fc)
139139
```
140140

141141
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.].
142142
```{r}
143143
# Setting an appropriate plot range to see the forecast
144144
plot(fc, xlim = c(320, 370))
145-
# Predicting with Two-Step estimates
146-
# plot(predict(model1, h = 12, method = "2s"), xlim = c(320, 370))
147145
```
146+
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")`.
148147

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.
151149

152150
```{r}
153151
# Factor forecasts in wide format
@@ -156,7 +154,7 @@ head(as.data.frame(fc, pivot = "wide"))
156154

157155
## Estimation with Mixed Frequency
158156

159-
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.
160158

161159
<!--
162160
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.
@@ -172,12 +170,12 @@ head(BM14_Q, 3)
172170
BM14_Q[, BM14_Models$log_trans[BM14_Models$freq == "Q"]] %<>% log()
173171
BM14_Q_diff <- diff(BM14_Q)
174172
# Merging to monthly data
175-
BM14_diff <- cbind(BM14_M_diff, BM14_Q_diff)
173+
BM14_diff <- merge(BM14_M_diff, BM14_Q_diff)
176174
177175
# Estimating the model with 5 factors and 3 lags using BM14's EM algorithm
178-
model2 <- DFM(BM14_diff, r = 5, p = 3, quarterly.vars = colnames(BM14_Q))
179-
print(model2)
180-
plot(model2)
176+
model_mq <- DFM(BM14_diff, r = 5, p = 3, quarterly.vars = colnames(BM14_Q))
177+
print(model_mq)
178+
plot(model_mq)
181179
```
182180

183181
<!--

0 commit comments

Comments
 (0)