library(sjmisc)
data(efc)
efc$c172code <- as.factor(efc$c172code)
efc$c161sex <- to_label(efc$c161sex)
mf <- formula(neg_c_7 ~ c161sex + c160age + c172code)
if (requireNamespace("brms", quietly = TRUE))
auto_prior(mf, efc, TRUE)
## compare to
# library(rstanarm)
# m <- stan_glm(mf, data = efc, chains = 2, iter = 200)
# ps <- prior_summary(m)
# ps$prior_intercept$adjusted_scale
# ps$prior$adjusted_scale
## usage
# ap <- auto_prior(mf, efc, TRUE)
# brm(mf, data = efc, priors = ap)
# add informative priors
mf <- formula(neg_c_7 ~ c161sex + c172code)
if (requireNamespace("brms", quietly = TRUE)) {
auto_prior(mf, efc, TRUE) +
brms::prior(normal(.1554, 40), class = "b", coef = "c160age")
}
# example with binary response
efc$neg_c_7d <- ifelse(efc$neg_c_7 < median(efc$neg_c_7, na.rm = TRUE), 0, 1)
mf <- formula(neg_c_7d ~ c161sex + c160age + c172code + e17age)
if (requireNamespace("brms", quietly = TRUE))
auto_prior(mf, efc, FALSE)
Run the code above in your browser using DataLab