# NOT RUN {
if (require("rstanarm") && require("see")) {
  stan_m0 <- stan_glm(extra ~ 1,
    data = sleep,
    family = gaussian(),
    refresh = 0,
    diagnostic_file = file.path(tempdir(), "df0.csv")
  )
  stan_m1 <- stan_glm(extra ~ group,
    data = sleep,
    family = gaussian(),
    refresh = 0,
    diagnostic_file = file.path(tempdir(), "df1.csv")
  )
  res <- weighted_posteriors(stan_m0, stan_m1)
  plot(eti(res))
}
## With BayesFactor
if (require("BayesFactor")) {
  extra_sleep <- ttestBF(formula = extra ~ group, data = sleep)
  wp <- weighted_posteriors(extra_sleep)
  describe_posterior(extra_sleep, test = NULL)
  describe_posterior(wp$delta, test = NULL) # also considers the null
}
## weighted prediction distributions via data.frames
if (require("rstanarm")) {
  m0 <- stan_glm(
    mpg ~ 1,
    data = mtcars,
    family = gaussian(),
    diagnostic_file = file.path(tempdir(), "df0.csv"),
    refresh = 0
  )
  m1 <- 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)
  wp <- weighted_posteriors(pred_m0, pred_m1,
    prior_odds = BFmods$BF[2]
  )
  # 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