Visualizing predictions

Bayesian Regression Modeling with rstanarm

Jake Thompson

Psychometrician, ATLAS, University of Kansas

Plotting new predictions

stan_model <- stan_glm(kid_score ~ mom_iq + mom_hs, data = kidiq)
predict_data <- data.frame(mom_iq = 110, mom_hs = c(0, 1))

posterior <- posterior_predict(stan_model, newdata = predict_data) posterior[1:10,]
              1         2
 [1,]  76.75484  96.26407
 [2,]  74.39001 100.38898
 [3,]  90.90370  70.00591
 [4,]  70.43835 120.82787
 [5,] 113.98411  82.40497
 [6,]  56.15829 121.84269
 [7,]  90.46640  92.77966
 [8,]  98.56337 110.17948
 [9,] 108.86147 123.67762
[10,]  94.29429  83.77102
Bayesian Regression Modeling with rstanarm

Formatting the data

posterior <- as.data.frame(posterior)

colnames(posterior) <- c("No HS", "Completed HS")
plot_posterior <- gather(posterior, key = "HS", value = "predict")
head(plot_posterior)
     HS   predict
1 No HS  76.75484
2 No HS  74.39001
3 No HS  90.90370
4 No HS  70.43835
5 No HS 113.98411
6 No HS  56.15829
Bayesian Regression Modeling with rstanarm

Creating the plot

ggplot(plot_posterior, aes(x = predict)) +
  facet_wrap(~ HS, ncol = 1) +
  geom_density()

Bayesian Regression Modeling with rstanarm

Let's practice

Bayesian Regression Modeling with rstanarm

Preparing Video For Download...