11.6 Residual standard deviation σ and explained variance R2
σ = residual standard deviation.
R2 = fraction of variance explained by the model:
R2=1−(σ2/s2y)
- For least squares, can compute R2 directing from ‘explained variance’:
R2=Vni=1ˆyi/s2y
Where the V operator capture the sample variance. I.e. this is the ratio of the variance in fitted outcome values to the variance in the unfitted outcome values.
11.6.1 Bayesian R2
Bayesian inference is not least squares, so the two formulas given previously can disagree. (Influence of the prior.)
Bayesian inference includes additional uncertainty beyond the point estimate that should be included
This leads to an alternative definition of R2 for each posterior draw s:
Bayesian R2s=Vni=1ˆysiVni=1ˆysi+σ2s
This can computed in R
using bayes_R2(fit)
. This will give draws of R2 which expresses also the uncertainty in R2.
For example for the model predicting child’s test score from given mothers score on IQ and mother’s high school status:
fit_iq <- stan_glm(kid_score ~ mom_hs + mom_iq, data = kidiq, refresh=0)
r2 <- bayes_R2(fit_iq)
hist(r2)