@@ -1030,21 +1030,24 @@ acf(ret)
10301030
10311031This clearly hints at non-stationarity of the exchange rate series and
10321032at (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
10441047Now 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 ])
10481051eigenvalues <- matrix (NA_complex_ , nrow(draws [[1 ]]), ncol(draws [[1 ]]))
10491052mains <- c(" AR(2) on the raw series" , " AR(2) on the returns" )
10501053for (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
11971212We 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")
12591274barplot(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
12641279We inspect the posterior distributions of $\eta_ {t,2}$ for wage category
126512802 (left-hand side) versus $\eta_ {t,5}$ for wage category 5 (right-hand
@@ -1294,4 +1309,4 @@ hist(eta_male_t[, 6], breaks = breaks,
12941309legend(" 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 )
0 commit comments