@@ -17,7 +17,7 @@ data("movies", package = "BayesianLearningCode")
1717
1818### Section 6.2.1 Bayesian Learning Under Improper Priors
1919
20- #### Example 6.2: Movie data
20+ #### Example 6.2: Movie data: Analysis under improper prior
2121
2222We use as response ` y ` the variable * OpenBoxOffice* , which contains the
2323box office sales at the opening weekend in Mio.\$ , and as covariates the
@@ -150,7 +150,7 @@ knitr::kable(round(cbind(qinvgamma(0.025, a = cN, b = reg.improp$CN),
150150| --------------:| ---------------:| ---------------:|
151151| 178.38 | 239.07 | 319.96 |
152152
153- #### Example 6.3: Movie data
153+ #### Example 6.3: Movie data: Prediction
154154
155155We are now interested in predicting the box office sales on the opening
156156weekend. We compute the predicted box office sales for a film with an
@@ -296,7 +296,7 @@ regression_conjugate <- function(y, X, b0 = 0, B0 = 10, c0 = 0.01, C0 = 0.01) {
296296}
297297```
298298
299- #### Example 6.4: Movie data
299+ #### Example 6.4: Movie data - Analysis under conjugate prior
300300
301301We specify a normal prior with mean zero and
302302$\mathbf{B}_ {0} = \lambda^{2}\mathbf{I}$ with $\lambda^{2} = 10$ on the
@@ -445,7 +445,7 @@ reg_semiconj <- function(y, X, b0 = 0, B0 = 10000, c0 = 2.5, C0 = 1.5,
445445}
446446```
447447
448- #### Example 6.5: Movie data - Show traceplots of the sampler
448+ #### Example 6.5: Movie data - Traceplots of the Gibbs sampler
449449
450450We run the sampler for 1000 draws starting with a very large value for
451451the innovation variance.
@@ -472,7 +472,7 @@ plot(post.draws$sigma2s, type = "l", xlab = "m", ylab = "",
472472starting value of the error variance was far from the posterior
473473distribution the burn-in phase of the sampler is very short.
474474
475- #### Example 6.6: Movie data
475+ #### Example 6.6: Movie data: Analysis under the semi-conjugate prior
476476
477477We now include all available covariates in the regression analysis. As
478478there is only one film with MPAA rating “G”, we merge the two ratings
@@ -499,7 +499,7 @@ p <- d - 1 # number of regression effects without intercept
499499Next, we define the prior parameters and run the sampler.
500500
501501``` r
502- set.seed(1 )
502+ set.seed(421 )
503503M <- 20000L # number of draws after burn-in
504504post.draws <- reg_semiconj(y , X , b0 = 0 , B0 = 10000 , c0 = 2.5 , C0 = 1.5 ,
505505 burnin = 1000L , M = M )
@@ -522,18 +522,18 @@ knitr::kable(round(res_beta.sc, 3))
522522
523523| | 2.5% quantile | posterior mean | 97.5% quantile |
524524| :----------| --------------:| ---------------:| ---------------:|
525- | Intercept | 17.501 | 19.104 | 20.714 |
526- | Comedy | -2.730 | 1.453 | 5.544 |
527- | Thriller | -3.972 | 0.535 | 4.967 |
528- | PG13 | -8.441 | -2.741 | 3.000 |
529- | R | -3.634 | 2.197 | 8.038 |
530- | Budget | 0.040 | 0.128 | 0.215 |
531- | Weeks | 0.022 | 0.380 | 0.742 |
532- | Screens | 0.596 | 0.964 | 1.332 |
533- | S-4-6 | -4.835 | -1.274 | 2.350 |
534- | S-1-3 | -1.202 | 2.449 | 6.117 |
535- | Vol-4-6 | -19.648 | -16.726 | -13.766 |
536- | Vol-1-3 | 19.283 | 22.365 | 25.458 |
525+ | Intercept | 17.492 | 19.109 | 20.716 |
526+ | Comedy | -2.597 | 1.492 | 5.553 |
527+ | Thriller | -3.886 | 0.579 | 4.966 |
528+ | PG13 | -8.535 | -2.732 | 2.993 |
529+ | R | -3.643 | 2.217 | 8.039 |
530+ | Budget | 0.041 | 0.128 | 0.214 |
531+ | Weeks | 0.017 | 0.376 | 0.732 |
532+ | Screens | 0.600 | 0.968 | 1.338 |
533+ | S-4-6 | -4.851 | -1.281 | 2.358 |
534+ | S-1-3 | -1.245 | 2.464 | 6.129 |
535+ | Vol-4-6 | -19.684 | -16.726 | -13.784 |
536+ | Vol-1-3 | 19.256 | 22.355 | 25.472 |
537537
538538We do the same for the error variances.
539539
@@ -547,7 +547,11 @@ knitr::kable(t(round(res_sigma2.sc, 3)))
547547
548548| 2.5% quantile | posterior mean | 97.5% quantile |
549549| --------------:| ---------------:| ---------------:|
550- | 47.415 | 63.815 | 86.276 |
550+ | 47.333 | 63.925 | 86.247 |
551+
552+ Obviously, taking into account more covariates the posterior mean of the
553+ error variance is considerably lower than in the model with only
554+ * Budget* and * Screens* used as covariates.
551555
552556The different signs of the effects of * Vol-4-6* and * Vol-1-3* deserve
553557some further comment. The two covariates are highly correlated. Due to
@@ -569,7 +573,7 @@ plot(X[, "Vol-4-6"], X[, "Vol-1-3"])
569573``` r
570574round(sum(res_beta.sc [c(" Vol-4-6" , " Vol-1-3" ), " posterior mean" ]),
571575 digits = 3 )
572- # > [1] 5.639
576+ # > [1] 5.629
573577```
574578
575579## 6.4 Regression Analysis Based on the Horseshoe Prior
@@ -659,13 +663,14 @@ reg_hs <- function(y, X, b0 = 0, B0 = 10000, c0 = 2.5, C0 = 1.5,
659663}
660664```
661665
662- #### Example 6.6 : Movie data
666+ #### Example 6.7 : Movie data- Analysis under Horseshoe prior
663667
664668We estimate the parameters in the regression model with the same prior
665669on intercept and error variance as in the semi-conjugate prior, but a
666670horseshoe prior on the covariate effects.
667671
668672``` r
673+ set.seed(421 )
669674post.draws.hs <- reg_hs(y , X , M = M )
670675```
671676
@@ -682,20 +687,27 @@ knitr::kable(round(res_beta.hs, 3))
682687
683688| | 2.5% quantile | posterior mean | 97.5% quantile |
684689| :----------| --------------:| ---------------:| ---------------:|
685- | Intercept | 17.485 | 19.110 | 20.726 |
686- | Comedy | -1.602 | 0.268 | 2.795 |
687- | Thriller | -2.230 | 0.044 | 2.485 |
688- | PG13 | -6.446 | -1.904 | 0.738 |
689- | R | -1.374 | 0.992 | 4.976 |
690- | Budget | 0.033 | 0.125 | 0.213 |
691- | Weeks | -0.003 | 0.336 | 0.688 |
692- | Screens | 0.596 | 0.960 | 1.326 |
693- | S-4-6 | -1.564 | 0.223 | 1.693 |
694- | S-1-3 | -0.517 | 0.764 | 2.704 |
695- | Vol-4-6 | -19.091 | -16.150 | -13.178 |
696- | Vol-1-3 | 18.716 | 21.758 | 24.781 |
697-
698- We also report the estimation results for the error variance.
690+ | Intercept | 17.515 | 19.107 | 20.702 |
691+ | Comedy | -1.569 | 0.278 | 2.811 |
692+ | Thriller | -2.247 | 0.039 | 2.406 |
693+ | PG13 | -6.208 | -1.857 | 0.792 |
694+ | R | -1.355 | 0.998 | 5.004 |
695+ | Budget | 0.035 | 0.126 | 0.213 |
696+ | Weeks | -0.002 | 0.334 | 0.679 |
697+ | Screens | 0.587 | 0.956 | 1.322 |
698+ | S-4-6 | -1.546 | 0.225 | 1.686 |
699+ | S-1-3 | -0.535 | 0.763 | 2.725 |
700+ | Vol-4-6 | -19.106 | -16.148 | -13.169 |
701+ | Vol-1-3 | 18.659 | 21.749 | 24.836 |
702+
703+ Estimation results are very similar to those under the semi-conjugate
704+ prior for the effects of Budget, Weeks, Screens, Vol-4-6 and Vol-1-3.
705+ For all other covariates the posterior means of their effects are closer
706+ to zero and the 95% posterior intervals are tighter under the horseshoe
707+ than under the semi-conjugate prior, indicating shrinkage to zero.
708+
709+ However, the estimation results on the error variance are very similar
710+ to those under the semi-conjugate prior.
699711
700712``` r
701713sigma2.hs <- post.draws.hs $ sigma2s
@@ -707,18 +719,14 @@ knitr::kable(t(round(res_sigma2.hs, 3)))
707719
708720| 2.5% quantile | posterior mean | 97.5% quantile |
709721| --------------:| ---------------:| ---------------:|
710- | 47.349 | 63.632 | 85.447 |
711-
712- Obviously, taking into account more covariates the posterior mean of the
713- error variance is considerably lower than in the model with only
714- * Budget* and * Screens* used as covariates.
722+ | 47.429 | 63.694 | 85.307 |
715723
716724We next have a look at the posterior distributions. The plots on the
717725left hand side show the posterior distribution for the regression
718726effects under the semi-conjugate prior, those on the right hand side the
719- posterior distributions under the horseshoe prior. Note that the
720- posterior distributions are symmetric under the semi-conjugate prior,
721- whereas this is not the case under the horseshoe prior.
727+ posterior distributions under the horseshoe prior. Whereas the posterior
728+ distributions are symmetric under the semi-conjugate prior, this is not
729+ the case under the horseshoe prior.
722730
723731``` r
724732for (i in seq_len(d )) {
@@ -804,7 +812,7 @@ for (i in seq_len(ncol(beta.hs))) {
804812
805813![ ] ( Chapter06_files/figure-html/unnamed-chunk-38-1.png )
806814
807- #### Example 6.7 : Movie data
815+ #### Example 6.8 : Movie data- Check convergence by a second MCMC run
808816
809817We verify convergence of the sampler by doing a second run of the six
810818block sampler in Algorithm 6.2. In the QQ plots of the draws of the
@@ -829,7 +837,7 @@ abline(a = 0, b = 1)
829837
830838![ ] ( Chapter06_files/figure-html/unnamed-chunk-39-1.png )
831839
832- #### Example 6.8 : Movie data
840+ #### Example 6.9 : Movie data - Predictions
833841
834842We predict the box office sales for different movies: a film with
835843baseline values in all covariates (A), a film with baseline values in
@@ -885,7 +893,7 @@ axis(1, at = 1:nf, labels = c("A", "B", "C", "D"))
885893
886894## Section 6.5: Shrinkage beyond the Horseshoe Prior
887895
888- #### Figure 6.10
896+ #### Figure 6.11
889897
890898We next investigate different shrinkage priors and plot the marginal
891899prior on a regression coefficient for various choices of the
@@ -1008,7 +1016,7 @@ legend(x = 1.05, y = 3,
10081016
10091017![ ] ( Chapter06_files/figure-html/unnamed-chunk-43-1.png )
10101018
1011- #### Example 6.10
1019+ #### Example 6.11: A hierarchical Bayesian lasso prior
10121020
10131021``` r
10141022beta2 <- beta1 <- seq(from = - 2 , to = 2 , by = 0.01 )
0 commit comments