This function creates default priors for brms-regression models, based on the same automatic prior-scale adjustment as in rstanarm.

auto_prior(formula, data, gaussian, locations = NULL)

Arguments

formula

A formula describing the model, which just needs to contain the model terms, but no notation of interaction, splines etc. Usually, you want only those predictors in the formula, for which automatic priors should be generated. Add informative priors afterwards to the returned brmsprior-object.

data

The data that will be used to fit the model.

gaussian

Logical, if the outcome is gaussian or not.

locations

A numeric vector with location values for the priors. If locations = NULL, 0 is used as location parameter.

Value

A brmsprior-object.

Details

auto_prior() is a small, convenient function to create some default priors for brms-models with automatically adjusted prior scales, in a similar way like rstanarm does. The default scale for the intercept is 10, for coefficients 2.5. If the outcome is gaussian, both scales are multiplied with sd(y). Then, for categorical variables, nothing more is changed. For numeric variables, the scales are divided by the standard deviation of the related variable.

All prior distributions are normal distributions. auto_prior() is intended to quickly create default priors with feasible scales. If more precise definitions of priors is necessary, this needs to be done directly with brms-functions like set_prior().

Note

As auto_prior() also sets priors on the intercept, the model formula used in brms::brm() must be rewritten to something like y ~ 0 + intercept ..., see set_prior.

Examples

data(efc)
efc$c172code <- as.factor(efc$c172code)
efc$c161sex <- as.factor(efc$c161sex)

mf <- formula(neg_c_7 ~ c161sex + c160age + c172code)
auto_prior(mf, efc, TRUE)
#>             prior     class      coef group resp dpar nlpar   lb   ub source
#>  normal(0, 38.96) Intercept                                 <NA> <NA>   user
#>   normal(0, 9.74)         b  c161sex2                       <NA> <NA>   user
#>   normal(0, 0.73)         b   c160age                       <NA> <NA>   user
#>   normal(0, 9.74)         b c172code2                       <NA> <NA>   user
#>   normal(0, 9.74)         b c172code3                       <NA> <NA>   user

## compare to
# m <- rstanarm::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, prior = ap)

# add informative priors
mf <- formula(neg_c_7 ~ c161sex + c172code)

auto_prior(mf, efc, TRUE) +
  brms::prior(normal(.1554, 40), class = "b", coef = "c160age")
#>               prior     class      coef group resp dpar nlpar   lb   ub source
#>    normal(0, 38.95) Intercept                                 <NA> <NA>   user
#>     normal(0, 9.74)         b  c161sex2                       <NA> <NA>   user
#>     normal(0, 9.74)         b c172code2                       <NA> <NA>   user
#>     normal(0, 9.74)         b c172code3                       <NA> <NA>   user
#>  normal(0.1554, 40)         b   c160age                       <NA> <NA>   user

# 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)
auto_prior(mf, efc, FALSE)
#>            prior     class      coef group resp dpar nlpar   lb   ub source
#>    normal(0, 10) Intercept                                 <NA> <NA>   user
#>   normal(0, 2.5)         b  c161sex2                       <NA> <NA>   user
#>  normal(0, 0.19)         b   c160age                       <NA> <NA>   user
#>   normal(0, 2.5)         b c172code2                       <NA> <NA>   user
#>   normal(0, 2.5)         b c172code3                       <NA> <NA>   user
#>  normal(0, 0.31)         b    e17age                       <NA> <NA>   user