13.3 Predictions and Comparisons

  • predict - produces a single value (the average)
new <- data.frame(income = 5)
predict(fit_1, type = "response", newdata = new)
##         1 
## 0.5557417

response here puts the result on the probability scale.

Note: this is the nearly same as the point estimate:

invlogit(coef(fit_1)[1] + coef(fit_1)[2]*5)
## (Intercept) 
##   0.5562355
  • posterior_linpred - samples of linear prediction in the logit scale
linpred <- posterior_linpred(fit_1, newdata = new)
length(linpred)
## [1] 4000
  • posterior_epred - samples ofprediction on the probability scale (just invlogit linpred)
epred <- posterior_epred(fit_1, newdata = new)
length(epred)
## [1] 4000

As usual, the advantage of Bayesian is we can get the mean and standard deviation of the predicted probability:

print(c(mean(epred), sd(epred)))
## [1] 0.55574173 0.02974654

Note that mean(epred) is exactly what predict returned (with type = ‘response’)

  • posterior_predict - generate random predictions using the posterior probability .
ppred <- posterior_predict(fit_1, newdata = new)
length(ppred)
## [1] 4000
ppred[0:10]
##  [1] 0 1 1 0 0 0 0 0 1 1
mean(ppred)
## [1] 0.55575