# NOT RUN {
library(bayestestR)
prior <- data.frame(
X = rnorm(100),
X1 = rnorm(100),
X3 = rnorm(100)
)
posterior <- data.frame(
X = rnorm(100, .4),
X1 = rnorm(100, -.2),
X3 = rnorm(100)
)
hyps <- c(
"X > X1 & X1 > X3",
"X > X1"
)
bayesfactor_restricted(posterior, hypothesis = hyps, prior = prior)
# }
# NOT RUN {
# rstanarm models
# ---------------
if (require("rstanarm") && require("emmeans")) {
fit_stan <- stan_glm(mpg ~ wt + cyl + am,
data = mtcars
)
hyps <- c(
"am > 0 & cyl < 0",
"cyl < 0",
"wt - cyl > 0"
)
bayesfactor_restricted(fit_stan, hypothesis = hyps)
# emmGrid objects
# ---------------
# replicating http://bayesfactor.blogspot.com/2015/01/multiple-comparisons-with-bayesfactor-2.html
disgust_data <- read.table(url("http://www.learnbayes.org/disgust_example.txt"), header = TRUE)
contrasts(disgust_data$condition) <- contr.bayes # see vignette
fit_model <- stan_glm(score ~ condition, data = disgust_data, family = gaussian())
em_condition <- emmeans(fit_model, ~condition)
hyps <- c("lemon < control & control < sulfur")
bayesfactor_restricted(em_condition, prior = fit_model, hypothesis = hyps)
# > # Bayes Factor (Order-Restriction)
# >
# > Hypothesis P(Prior) P(Posterior) Bayes Factor
# > lemon < control & control < sulfur 0.17 0.75 4.49
# > ---
# > Bayes factors for the restricted model vs. the un-restricted model.
}
# }
Run the code above in your browser using DataLab