Skip to content

Commit 968a105

Browse files
committed
Deploying to gh-pages from @ 6ae0031 🚀
1 parent 8fb73cc commit 968a105

11 files changed

Lines changed: 68 additions & 40 deletions

articles/Chapter07.html

Lines changed: 38 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

articles/Chapter07.md

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,21 +1030,24 @@ acf(ret)
10301030

10311031
This clearly hints at non-stationarity of the exchange rate series and
10321032
at (first order) stationarity of the returns. To check more formally, we
1033-
fit an AR(2) model to both.
1033+
fit AR(p) models to both.
10341034

10351035
``` r
1036-
y <- tail(dat, -2)
1037-
Xy <- ARdesignmatrix(dat, 2)
1038-
ar2dat <- regression(y, Xy, prior = "improper")
1039-
y <- tail(ret, -2)
1040-
Xy <- ARdesignmatrix(ret, 2)
1041-
ar2ret <- regression(y, Xy, prior = "improper")
1036+
ardat <- arret <- list()
1037+
for (p in 1:4) {
1038+
y <- tail(dat, -p)
1039+
Xy <- ARdesignmatrix(dat, p)
1040+
ardat[[p]] <- regression(y, Xy, prior = "improper")
1041+
y <- tail(ret, -p)
1042+
Xy <- ARdesignmatrix(ret, p)
1043+
arret[[p]] <- regression(y, Xy, prior = "improper")
1044+
}
10421045
```
10431046

10441047
Now we can graphically investigate stationarity as above.
10451048

10461049
``` r
1047-
draws <- list(ar2dat$betas[,2:3], ar2ret$betas[,2:3])
1050+
draws <- list(ardat[[2]]$betas[,2:3], arret[[2]]$betas[,2:3])
10481051
eigenvalues <- matrix(NA_complex_, nrow(draws[[1]]), ncol(draws[[1]]))
10491052
mains <- c("AR(2) on the raw series", "AR(2) on the returns")
10501053
for (i in seq_along(draws)) {
@@ -1065,6 +1068,18 @@ for (i in seq_along(draws)) {
10651068

10661069
![](Chapter07_files/figure-html/unnamed-chunk-41-1.png)
10671070

1071+
To explore whether the nonstationarity of the raw series could be caused
1072+
by a unit root, we investigate the posterior of
1073+
$1 - \phi_{1} - \ldots - \phi_{p}$ for $p = 1,\ldots,4$.
1074+
1075+
``` r
1076+
for (p in 1:4) {
1077+
hist(1 - rowSums(ardat[[p]]$betas[, 2:(p + 1), drop = FALSE]), freq = FALSE)
1078+
}
1079+
```
1080+
1081+
![](Chapter07_files/figure-html/unnamed-chunk-42-1.png)
1082+
10681083
## Section 7.4: Markov modeling for a panel of categorical time series
10691084

10701085
### Example 7.13: Wage mobility data
@@ -1101,7 +1116,7 @@ for (i in index) {
11011116
}
11021117
```
11031118

1104-
![](Chapter07_files/figure-html/unnamed-chunk-44-1.png)
1119+
![](Chapter07_files/figure-html/unnamed-chunk-45-1.png)
11051120

11061121
### Example 7.14: Wage mobility data – comparing wage mobility of men and women
11071122

@@ -1192,7 +1207,7 @@ corrplot::corrplot(mean_xi_male, method = "square", is.corr = FALSE,
11921207
col = 1, cl.pos = "n")
11931208
```
11941209

1195-
![](Chapter07_files/figure-html/unnamed-chunk-48-1.png)
1210+
![](Chapter07_files/figure-html/unnamed-chunk-49-1.png)
11961211

11971212
We compare the posterior densities of various transition probabilities
11981213
$\xi_{g,hk}$ for women and men.
@@ -1234,7 +1249,7 @@ legend("topright", col = 1, lty = 1:2,
12341249
legend = c("female", "male"))
12351250
```
12361251

1237-
![](Chapter07_files/figure-html/unnamed-chunk-49-1.png)
1252+
![](Chapter07_files/figure-html/unnamed-chunk-50-1.png)
12381253

12391254
### Example 7.15: Wage mobility data – long run
12401255

@@ -1259,7 +1274,7 @@ barplot(eta_hat_female_t, main = "Women", xlab = "Year", ylab = "Wage groups")
12591274
barplot(eta_hat_male_t, main = "Men", xlab = "Year", ylab = "Wage groups")
12601275
```
12611276

1262-
![](Chapter07_files/figure-html/unnamed-chunk-50-1.png)
1277+
![](Chapter07_files/figure-html/unnamed-chunk-51-1.png)
12631278

12641279
We inspect the posterior distributions of $\eta_{t,2}$ for wage category
12651280
2 (left-hand side) versus $\eta_{t,5}$ for wage category 5 (right-hand
@@ -1294,4 +1309,4 @@ hist(eta_male_t[, 6], breaks = breaks,
12941309
legend("topright", c("female", "male"), fill = rgb(c(0, 1), 0, 0, 0.2))
12951310
```
12961311

1297-
![](Chapter07_files/figure-html/unnamed-chunk-51-1.png)
1312+
![](Chapter07_files/figure-html/unnamed-chunk-52-1.png)
38 Bytes
Loading
22.5 KB
Loading
26 KB
Loading
-146 KB
Loading
134 KB
Loading
2.19 KB
Loading
37 KB
Loading

pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ articles:
1111
Chapter07: Chapter07.html
1212
Chapter08: Chapter08.html
1313
Chapter09: Chapter09.html
14-
last_built: 2026-01-10T23:04Z
14+
last_built: 2026-01-10T23:29Z
1515
urls:
1616
reference: https://gregorkastner.github.io/BayesianLearningCode/reference
1717
article: https://gregorkastner.github.io/BayesianLearningCode/articles

0 commit comments

Comments
 (0)