Skip to content

Commit 4961c1d

Browse files
committed
prediction corrected
1 parent ccc6160 commit 4961c1d

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

vignettes/Chapter06.Rmd

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ data("movies", package = "BayesianLearningCode")
4040
## Section 6.2.1 Bayesian Learning Under Improper Priors
4141
### Example 6.2: Movie data
4242

43-
We use as response `y` the variable `OpenBoxOffice`, which contains
44-
the box office sales at the opening weekend in Mio.$, and as
45-
covariates the budget (`Budget`, in Mio.$) and the number of screens
46-
(`Screens`, in 1000) the film was forecast to be in theaters six weeks
43+
We use as response `y` the variable _OpenBoxOffice_, which contains
44+
the box office sales at the opening weekend in Mio.\$, and as
45+
covariates the budget (_Budget_, in Mio.$) and the number of screens
46+
(_Screens_, in 1000) the film was forecast to be in theaters six weeks
4747
prior to opening.
4848

4949
We center the covariates _Budget_ and _Screens_ at their means in the
@@ -797,11 +797,15 @@ X_new[3, "PG13"] <- 1
797797
X_new[4, "R"] <- 1
798798
X_new[, "Budget"] <- 10
799799
800-
ypred.sc <- X_new %*% t(beta.sc) + rnorm(sqrt(sigma2.sc))
800+
ypred.sc <- X_new %*% t(beta.sc) +
801+
rep(rnorm(length(sigma2.sc), sd = sqrt(sigma2.sc)), each = nrow(X_new))
801802
pred.int.sc <- apply(ypred.sc,1, quantile, probs = c(0.025, 0.5, 0.975))
802803
pred.mean.sc <- rowMeans(ypred.sc)
803804
804-
ypred.hs <- X_new %*% t(beta.hs) + rnorm(sqrt(sigma2.hs))
805+
ypred.hs <- X_new %*% t(beta.hs) +
806+
rep(rnorm(length(sigma2.hs), sd = sqrt(sigma2.hs)), each = nrow(X_new))
807+
808+
805809
pred.int.hs <- apply(ypred.hs,1, quantile, probs = c(0.025, 0.5, 0.975))
806810
pred.mean.hs <- rowMeans(ypred.hs)
807811
```
@@ -818,7 +822,7 @@ if (pdfplots) {
818822
par(mfrow = c(1, 1))
819823
matplot(x = t(matrix(1:nf, ncol = 3, nrow = nf)),
820824
y = pred.int.sc, col = "blue", type = "l", pch = 16, lty = 1,
821-
ylim = c(8, 32), xlim = c(0.5, nf+0.5),
825+
ylim = c(0, 40), xlim = c(0.5, nf+0.5),
822826
xlab = "Scenarios", ylab = "Predicted box office sales", xaxt = "n")
823827
points(x = 1:nf, y = pred.int.sc[2, ], pch = 19, col = "blue", cex = 1.2)
824828
points(x = 1:nf, y = pred.mean.sc, pch = 16, col = "red")

0 commit comments

Comments
 (0)