Stan summary R2 or adjusted R2

Yes.

You can compute LOO-adjusted R2 with

looR2 <- function(fit) {
    y <- get_y(fit)
    ypred <- posterior_linpred(fit)
    ll <- log_lik(fit)
    r_eff <- relative_eff(exp(ll), chain_id = rep(1:4, each = 1000))
    psis_object <- psis(log_ratios = -ll, r_eff = r_eff)
    ypredloo <- E_loo(ypred, psis_object, log_ratios = -ll)$value
    eloo <- ypredloo-y
    return(1-var(eloo)/var(y))
}
round(looR2(fit),2)

This will be added some day to some package (hopefully before StanCon Helsinki)

I just realized that since I made that function quickly it has hard coded the number and the length of chains. I’ll change that later, but now it’s too late for me to think.

1 Like