@@ -621,19 +621,43 @@ of genre comedy, with average values of and {Weeks} as well as the
621621sentiments and volumes of Twitter-posts set, but different values of .
622622
623623``` r
624- nf = 3
624+ nf = 4
625625X_new <- cbind(rep(1 ,nf ), matrix (0 ,nrow = nf ,ncol = p ))
626626colnames(X_new )<- colnames(X )
627- X_new [," Comedy" ]= rep(1 ,3 )
628- X_new [," Screens" ]= c(0 ,3 ,10 )
627+
628+ X_new [2 ," Comedy" ]= 1
629+ X_new [3 : 4 ," Thriller" ]= 1
630+ X_new [3 ," PG13" ]= 1
631+ X_new [4 ," R" ]= 1
632+
633+ X_new [," Budget" ]= c(10 )
629634
630635ypred.sc = X_new %*% t(beta.sc )+ rnorm(sqrt(sigma2.sc ))
631636pred.int.sc <- apply(ypred.sc ,1 , quantile , probs = c(0.025 ,0.5 , 0.975 ))
637+ pred.mean.sc <- rowMeans(ypred.sc )
632638
633639ypred.hs <- X_new %*% t(beta.hs )+ rnorm(sqrt(sigma2.hs ))
634640pred.int.hs <- apply(ypred.hs ,1 , quantile , probs = c(0.025 ,0.5 , 0.975 ))
641+ pred.mean.hs <- rowMeans(ypred.hs )
635642```
636643
637644plot predicted expectation,the median of the predictive distribution,
638645together with vertical bars indicating the pointwise equal-tailed
63964695%-predictive interval
647+
648+ ``` r
649+ par(mfrow = c(1 ,1 ))
650+
651+ matplot(x = t(matrix (1 : nf ,ncol = 3 , nrow = nf )),y = pred.int.sc ,col = " blue" ,type = " l" ,pch = 16 ,lty = 1 ,ylim = c(5 ,35 ), xlim = c(0 ,nf + 1 ), xlab = " Scenarios" , ylab = " Prediction" ,xaxt = " n" )
652+ points(x = 1 : nf , y = pred.int.sc [2 ,], pch = 16 ,col = " blue" )
653+ points(x = 1 : nf , y = pred.mean.sc , pch = 16 ,col = " red" )
654+
655+ matplot(x = t(matrix ((1 : nf )+ 0.2 ,ncol = 3 , nrow = nf )),y = pred.int.hs ,col = " blue" ,type = " l" ,pch = 16 ,lty = 1 ,add = TRUE )
656+
657+ points(x = (1 : nf )+ 0.2 , y = pred.int.hs [2 ,], pch = 16 ,col = " blue" )
658+ points(x = (1 : nf )+ 0.2 , y = pred.mean.hs , pch = 16 ,col = " red" )
659+
660+ axis(1 ,at = 1 : nf ,labels = c(" A" ," B" ," C" ," D" ))
661+ ```
662+
663+ ![ ] ( Chapter06_files/figure-html/unnamed-chunk-31-1.png )
0 commit comments