Skip to content

Commit 866809d

Browse files
committed
Using <- instead of = and mixed frequency example.
1 parent afb0061 commit 866809d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

vignettes/introduction.Rmd

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Prior to estimation, all data is differenced by BM14, and some series are log, d
5353
library(magrittr)
5454
# log-transforming and first-differencing the data
5555
BM14_M[, BM14_Models_M$log_trans] %<>% log()
56-
BM14_M_diff = diff(BM14_M)
56+
BM14_M_diff <- diff(BM14_M)
5757
plot(scale(BM14_M_diff), lwd = 1)
5858
```
5959

@@ -62,7 +62,7 @@ plot(scale(BM14_M_diff), lwd = 1)
6262
Before estimating a model, the `ICr()` function can be applied to determine the number of factors. It computes 3 information criteria proposed in Bai and NG (2002)^[Bai, J., Ng, S. (2002). Determining the Number of Factors in Approximate Factor Models. *Econometrica, 70*(1), 191-221. <doi:10.1111/1468-0262.00273>], whereby the second criteria generally suggests the most parsimonious model.
6363

6464
```{r}
65-
ic = ICr(BM14_M_diff)
65+
ic <- ICr(BM14_M_diff)
6666
print(ic)
6767
plot(ic)
6868
```
@@ -88,7 +88,7 @@ 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)
91+
model1 <- DFM(BM14_M_diff, r = 4, p = 3)
9292
print(model1)
9393
plot(model1)
9494
```
@@ -134,7 +134,7 @@ DFM forecasts can be obtained with the `predict()` method, which dynamically for
134134

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

@@ -156,7 +156,7 @@ head(as.data.frame(fc, pivot = "wide"))
156156

157157
## Estimation with Mixed Frequency
158158

159-
*dfms* currently provides no specific adjustments for data at different frequencies. An algorithm that accommodates monthly and quarterly series is planned for summer 2023. In the meantime, users may choose to block the data (creating multiple quarterly series from a monthly series, and duplicating quarterly series to maintain equal representation).
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.
160160

161161
<!--
162162
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.
@@ -170,12 +170,12 @@ In the absence of such adjustments to the algorithm, or other methods of interpo
170170
head(BM14_Q, 3)
171171
# Pre-processing the data
172172
BM14_Q[, BM14_Models[BM14_Models$freq == "Q", ]$log_trans] %<>% log()
173-
BM14_Q_diff = diff(BM14_Q)
174-
# Merging to monthly data and duplicating 2 times
175-
BM14_diff = cbind(BM14_M_diff, BM14_Q_diff, BM14_Q_diff, BM14_Q_diff)
173+
BM14_Q_diff <- diff(BM14_Q)
174+
# Merging to monthly data
175+
BM14_diff <- cbind(BM14_M_diff, BM14_Q_diff)
176176
177177
# Estimating the model with 5 factors and 3 lags using BM14's EM algorithm
178-
model2 = DFM(BM14_diff, r = 5, p = 3)
178+
model2 <- DFM(BM14_diff, r = 5, p = 3, quarterly.vars = colnames(BM14_Q))
179179
print(model2)
180180
plot(model2)
181181
```

0 commit comments

Comments
 (0)