In RaOS, figure 11.1 shows a nice way to plot inferential uncertainty of a model, as I understand it.
I’m searching for a similarly easy way to plot predictive uncertainty, both in the given range of the predictor (momiq in this case) and extrapolated (for a mom with an IQ above the 140 in the data).
You can reproduce fig. 11.1 with these lines from https://raw.githubusercontent.com/avehtari/ROS-Examples/master/KidIQ/kidiq.R
#' ## Displaying uncertainty in the fitted regression
#'
#' #### A single continuous predictor
library("rstanarm")
library("ggplot2")
library("bayesplot")
theme_set(bayesplot::theme_default(base_family = "sans"))
library("foreign")
#' #### Load children's test scores data
kidiq <- read.csv(root("KidIQ/data","kidiq.csv"))
print(fit_2)
sims_2 <- as.matrix(fit_2)
n_sims_2 <- nrow(sims_2)
subset <- sample(n_sims_2, 10)
plot(kidiq$mom_iq, kidiq$kid_score,
xlab="Mother IQ score", ylab="Child test score")
for (i in subset){
abline(sims_2[i,1], sims_2[i,2], col="gray")
}
abline(coef(fit_2)[1], coef(fit_2)[2], col="black")
There’s also a ggplot2 version following that in the linked code.
I figure there’s probably an easy, idiomatic approach, but I haven’t found it yet.
Operating System: Linux, Windows
Interface Version: rstanarm