Skip to content

Commit 2ef2246

Browse files
committed
Executing README examples.
1 parent 6787f46 commit 2ef2246

File tree

3 files changed

+116
-3
lines changed

3 files changed

+116
-3
lines changed

README.md

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,136 @@ install.packages("dfms")
4848
install.packages('dfms', repos = c('https://sebkrantz.r-universe.dev', 'https://cloud.r-project.org'))
4949

5050
```
51+
5152
### Usage Example
53+
54+
5255
```r
5356
library(dfms)
5457

5558
# Fit DFM with 6 factors and 3 lags in the transition equation
5659
mod = DFM(diff(BM14_M), r = 6, p = 3)
60+
```
5761

62+
```
63+
## Converged after 32 iterations.
64+
```
65+
66+
```r
5867
# 'dfm' methods
5968
summary(mod)
69+
```
70+
71+
```
72+
## Mixed Frequency Dynamic Factor Model
73+
## n = 92, nm = 92, nq = 0, T = 356, r = 6, p = 3
74+
## %NA = 25.8366, %NAm = NA
75+
##
76+
## Call: DFM(X = diff(BM14_M), r = 6, p = 3)
77+
##
78+
## Summary Statistics of Factors [F]
79+
## N Mean Median SD Min Max
80+
## f1 356 -0.1189 0.4409 4.0228 -22.9164 7.8513
81+
## f2 356 -0.4615 -0.3476 2.9201 -9.0973 10.7003
82+
## f3 356 -0.0173 0.0377 2.2719 -8.5067 7.3009
83+
## f4 356 -0.007 -0.1338 1.9378 -9.5052 9.3673
84+
## f5 356 0.237 0.1091 2.0857 -8.7252 9.6715
85+
## f6 356 -0.8361 -0.304 3.1406 -11.6611 15.4897
86+
##
87+
## Factor Transition Matrix [A]
88+
## L1.f1 L1.f2 L1.f3 L1.f4 L1.f5 L1.f6 L2.f1 L2.f2
89+
## f1 0.53029 -0.53009 0.367302 0.04607 -0.06351 0.10310 0.02457 0.11673
90+
## f2 -0.28380 0.07421 -0.032292 0.29741 -0.10094 0.21989 0.09958 -0.09149
91+
## f3 0.17607 0.12979 0.378798 -0.06662 -0.12236 0.06685 -0.08068 0.09101
92+
## f4 0.02711 0.08936 0.004643 0.37159 0.12100 -0.02763 0.01234 -0.05147
93+
## f5 -0.26227 -0.03469 -0.046294 0.12712 0.26847 0.03141 0.06400 0.01971
94+
## f6 0.08251 0.17619 -0.013374 -0.08731 -0.03875 0.27812 -0.01662 0.04877
95+
## L2.f3 L2.f4 L2.f5 L2.f6 L3.f1 L3.f2 L3.f3 L3.f4
96+
## f1 -0.12638 0.23135 0.117184 0.21941 0.18478 0.02259 -0.03719 -0.07236
97+
## f2 0.06708 -0.09768 -0.043057 0.08489 0.21107 0.16261 0.03057 0.04835
98+
## f3 -0.22232 0.09799 -0.060666 -0.18028 -0.02773 0.01798 0.10143 -0.12420
99+
## f4 0.02195 0.01266 0.050912 0.05144 -0.05601 0.04665 0.05710 -0.11412
100+
## f5 0.04806 -0.03965 -0.009952 -0.18471 0.08332 -0.04640 -0.02047 0.02458
101+
## f6 0.02279 0.01163 -0.100859 0.07152 0.00792 0.06071 0.11381 0.02520
102+
## L3.f5 L3.f6
103+
## f1 -0.03026 -0.12606
104+
## f2 0.12249 0.13357
105+
## f3 0.04207 -0.07011
106+
## f4 -0.05680 -0.01609
107+
## f5 0.16397 0.07820
108+
## f6 -0.17897 0.30328
109+
##
110+
## Factor Covariance Matrix [cov(F)]
111+
## f1 f2 f3 f4 f5 f6
112+
## f1 16.1832 -0.4329 0.2483 -0.8224* -1.7708* 0.7702
113+
## f2 -0.4329 8.5272 0.0051 0.2954 -0.2114 4.2080*
114+
## f3 0.2483 0.0051 5.1614 -0.1851 -0.3979 0.2979
115+
## f4 -0.8224* 0.2954 -0.1851 3.7550 0.4344* 0.2211
116+
## f5 -1.7708* -0.2114 -0.3979 0.4344* 4.3503 -1.9785*
117+
## f6 0.7702 4.2080* 0.2979 0.2211 -1.9785* 9.8634
118+
##
119+
## Factor Transition Error Covariance Matrix [Q]
120+
## u1 u2 u3 u4 u5 u6
121+
## u1 7.2142 0.1151 -0.8208 -0.4379 0.4110 -0.1206
122+
## u2 0.1151 4.8724 0.1076 -0.1438 0.1418 0.1759
123+
## u3 -0.8208 0.1076 4.0584 -0.0788 0.0163 0.0038
124+
## u4 -0.4379 -0.1438 -0.0788 3.0003 0.2562 0.0243
125+
## u5 0.4110 0.1418 0.0163 0.2562 2.8410 -0.1031
126+
## u6 -0.1206 0.1759 0.0038 0.0243 -0.1031 2.9284
127+
##
128+
## Summary of Residual AR(1) Serial Correlations
129+
## N Mean Median SD Min Max
130+
## 92 -0.0644 -0.1024 0.2702 -0.5113 0.6674
131+
##
132+
## Summary of Individual R-Squared's
133+
## N Mean Median SD Min Max
134+
## 92 0.4556 0.4069 0.3041 0.0112 0.9989
135+
```
136+
137+
```r
60138
plot(mod)
61-
as.data.frame(mod)
139+
```
62140

141+
<div class="figure">
142+
<img src="misc/figure/unnamed-chunk-1-1.png" alt="plot of chunk unnamed-chunk-1" width="100%" />
143+
</div>
144+
145+
```r
146+
as.data.frame(mod) |> head()
147+
```
148+
149+
```
150+
## Method Factor Time Value
151+
## 1 PCA f1 1 0.8445713
152+
## 2 PCA f1 2 0.5259228
153+
## 3 PCA f1 3 -1.2107116
154+
## 4 PCA f1 4 -1.5399532
155+
## 5 PCA f1 5 -0.4631786
156+
## 6 PCA f1 6 0.2399304
157+
```
158+
159+
```r
63160
# Forecasting 20 periods ahead
64161
fc = predict(mod, h = 20)
65162

66163
# 'dfm_forecast' methods
67-
print(fc)
68164
plot(fc)
69-
as.data.frame(fc)
165+
```
166+
167+
<div class="figure">
168+
<img src="misc/figure/unnamed-chunk-1-2.png" alt="plot of chunk unnamed-chunk-1" width="100%" />
169+
</div>
170+
171+
```r
172+
as.data.frame(fc) |> head()
173+
```
174+
175+
```
176+
## Variable Time Forecast Value
177+
## 1 f1 1 FALSE 4.179331
178+
## 2 f1 2 FALSE -1.368577
179+
## 3 f1 3 FALSE -12.845157
180+
## 4 f1 4 FALSE -14.562265
181+
## 5 f1 5 FALSE -7.791254
182+
## 6 f1 6 FALSE -1.254970
70183
```

misc/figure/unnamed-chunk-1-1.png

414 KB
Loading

misc/figure/unnamed-chunk-1-2.png

391 KB
Loading

0 commit comments

Comments
 (0)