I have estimated stan_lm models using rstanarm.
One of the estimates is labelled R2.
There is also the bayes_R2.stanreg function.
Both the single R2 estimate (with mean, sd, percentiles, etc) and the bayes_R2 vector of estimates come from the posterior draws.
I don’t understand the distinction/purposes of the two R2’s.
I haven’t found similar questions in the forum.
bayes_R2 function can be called on any generalized linear model (
stan_glm), even those with group-specific parameters (
stan_glmer). For the particular function
stan_lm, the R^2 is a primitive parameter whose posterior distribution is being estimated, whereas
bayes_R2 is essentially a generated quantity rather than a primitive parameter. Either way, they are referring to the same concept and should have the same distribution theoretically.
If you find bayes_R2 useful and want to report it in your work, I suggest you to try loo_R2 too, which tends to suffer less from potential overfitting. See https://avehtari.github.io/bayes_R2/bayes_R2.html for more info.
Thanks for the several comments. I have looked at the Am Stat paper with supplement.
My stan_lm model is log(continuous response) ~ 33 predictors (15 covariates and factors); the posterior sample size is 32000.
The “primitive” parameter R2 is 0.4 with 90% CI (0.4, 0.4), sd 0.0, mcse 0.0 and Rhat 1.001.
I attempted to use bayes_R2 and loo_R2 on the fitted object.
I am working in a container with 120 Gb on a linux server running R 3.6.1 and rstanarm 2.19.2.
Both the bayes_R2 and the loo_R2 calls returned:
Error: cannot allocate vector of size 263.3 Gb.
I will use the R2 reported with the fit.
Is the bayes_R2 error expected with the posterior sample size of my fit?
Could you try running again
bayes_R2 and type
traceback() immediately after the error? I’d like to see where exactly this allocation is being attempted.
That is all you need. The
bayes_R2 is no better of an estimate and
loo_R2 tends to differ only with small datasets. You might print yourself a second decimal place by doing
print(fit, digits = 2).