# \donttest{
if (require("rstanarm") && require("see") && interactive()) {
stan_m0 <- suppressWarnings(stan_glm(extra ~ 1,
data = sleep,
family = gaussian(),
refresh = 0,
diagnostic_file = file.path(tempdir(), "df0.csv")
))
stan_m1 <- suppressWarnings(stan_glm(extra ~ group,
data = sleep,
family = gaussian(),
refresh = 0,
diagnostic_file = file.path(tempdir(), "df1.csv")
))
res <- weighted_posteriors(stan_m0, stan_m1, verbose = FALSE)
plot(eti(res))
}
## With BayesFactor
if (require("BayesFactor")) {
extra_sleep <- ttestBF(formula = extra ~ group, data = sleep)
wp <- weighted_posteriors(extra_sleep, verbose = FALSE)
describe_posterior(extra_sleep, test = NULL, verbose = FALSE)
# also considers the null
describe_posterior(wp$delta, test = NULL, verbose = FALSE)
}
## weighted prediction distributions via data.frames
if (require("rstanarm") && interactive()) {
m0 <- suppressWarnings(stan_glm(
mpg ~ 1,
data = mtcars,
family = gaussian(),
diagnostic_file = file.path(tempdir(), "df0.csv"),
refresh = 0
))
m1 <- suppressWarnings(stan_glm(
mpg ~ carb,
data = mtcars,
family = gaussian(),
diagnostic_file = file.path(tempdir(), "df1.csv"),
refresh = 0
))
# Predictions:
pred_m0 <- data.frame(posterior_predict(m0))
pred_m1 <- data.frame(posterior_predict(m1))
BFmods <- bayesfactor_models(m0, m1, verbose = FALSE)
wp <- weighted_posteriors(
pred_m0, pred_m1,
prior_odds = as.numeric(BFmods)[2],
verbose = FALSE
)
# look at first 5 prediction intervals
hdi(pred_m0[1:5])
hdi(pred_m1[1:5])
hdi(wp[1:5]) # between, but closer to pred_m1
}
# }
Run the code above in your browser using DataLab