# NOT RUN {
library(performance)
if (require("rstanarm") && require("rstantools")) {
model <- stan_glm(mpg ~ wt + cyl, data = mtcars, chains = 1, iter = 500, refresh = 0)
r2_bayes(model)
model <- stan_lmer(
Petal.Length ~ Petal.Width + (1 | Species),
data = iris,
chains = 1,
iter = 500,
refresh = 0
)
r2_bayes(model)
}
# }
# NOT RUN {
if (require("BayesFactor")) {
data(mtcars)
BFM <- generalTestBF(mpg ~ qsec + gear, data = mtcars, progress = FALSE)
FM <- lm(mpg ~ qsec + gear, data = mtcars)
r2_bayes(FM)
r2_bayes(BFM[3])
r2_bayes(BFM, average = TRUE) # across all models
# with random effects:
mtcars$gear <- factor(mtcars$gear)
model <- lmBF(
mpg ~ hp + cyl + gear + gear:wt,
mtcars,
progress = FALSE,
whichRandom = c("gear", "gear:wt")
)
r2_bayes(model)
}
if (require("brms")) {
model <- brms::brm(mpg ~ wt + cyl, data = mtcars)
r2_bayes(model)
model <- brms::brm(Petal.Length ~ Petal.Width + (1 | Species), data = iris)
r2_bayes(model)
}
# }
Run the code above in your browser using DataLab