Skip to contents

Template for the label argument of brm_prior_archetype().

Usage

brm_prior_template(archetype)

Arguments

archetype

An informative prior archetype generated by a function like brm_archetype_successive_cells().

Value

A tibble with one row per fixed effect parameter and columns to map Stan code to each parameter. After manually writing Stan code in the code column of the template, you can supply the result to the label argument of brm_prior_archetype() to build a brms prior for your model.

Details

The label argument of brm_prior_archetype() is a tibble which maps Stan code for univariate priors to fixed effect parameters in the model. Usually this tibble is built gradually using multiple calls to brm_prior_label(), but occasionally it is more convenient to begin with a full template and manually write Stan code in the code column. brm_prior_template() creates this template.

Prior labeling

Informative prior archetypes use a labeling scheme to assign priors to fixed effects. How it works:

1. First, assign the prior of each parameter a collection
  of labels from the data. This can be done manually or with
  successive calls to [brm_prior_label()].
2. Supply the labeling scheme to [brm_prior_archetype()].
  [brm_prior_archetype()] uses attributes of the archetype
  to map labeled priors to their rightful parameters in the model.

For informative prior archetypes, this process is much more convenient and robust than manually calling brms::set_prior(). However, it requires an understanding of how the labels of the priors map to parameters in the model. This mapping varies from archetype to archetype, and it is documented in the help pages of archetype-specific functions such as brm_archetype_successive_cells().

See also

Examples

set.seed(0L)
data <- brm_simulate_outline(
  n_group = 2,
  n_patient = 100,
  n_time = 3,
  rate_dropout = 0,
  rate_lapse = 0
) |>
  dplyr::mutate(response = rnorm(n = dplyr::n())) |>
  brm_simulate_continuous(names = c("biomarker1", "biomarker2")) |>
  brm_simulate_categorical(
    names = c("status1", "status2"),
    levels = c("present", "absent")
  )
archetype <- brm_archetype_successive_cells(data)
label <- brm_prior_template(archetype)
label$code <- c(
  "normal(1, 1)",
  "normal(1, 2)",
  "normal(1, 3)",
  "normal(2, 1)",
  "normal(2, 2)",
  "normal(2, 3)"
)
brm_prior_archetype(label = label, archetype = archetype)
#>         prior class             coef group resp dpar nlpar   lb   ub source
#>  normal(1, 1)     b x_group_1_time_1                       <NA> <NA>   user
#>  normal(1, 2)     b x_group_1_time_2                       <NA> <NA>   user
#>  normal(1, 3)     b x_group_1_time_3                       <NA> <NA>   user
#>  normal(2, 1)     b x_group_2_time_1                       <NA> <NA>   user
#>  normal(2, 2)     b x_group_2_time_2                       <NA> <NA>   user
#>  normal(2, 3)     b x_group_2_time_3                       <NA> <NA>   user