I often save my priors for mean and sd as variables (e.g., SD_INTERCEPT), but I cannot pass these variables into my brms model. Is there a way to do this?
library(tidyverse)
library(brms)
df_demo =
tibble(
A = rbinom(1e3, 1, .5),
B = rbinom(1e3, 1, .51),
) |>
pivot_longer(
everything(),
names_to = "recipe",
values_to = "convert"
)
MU_INTERCEPT = 0
SD_INTERCEPT = 0.1003353
MU_TRT = 0
SD_TRT = 0.02000267
brm(
formula = "convert ~ recipe",
prior =
prior(normal(MU_INTERCEPT, SD_INTERCEPT), class = Intercept) +
prior(normal(MU_TRT, SD_TRT), class = b, coef=recipeB),
data = df_demo,
family = bernoulli
)
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
0
Semantic error in 'string', line 27, column 36 to column 48:
-------------------------------------------------
25: real lprior = 0; // prior contributions to the log posterior
26: lprior += normal_lpdf(b[1] | 0, 0.02000267);
27: lprior += normal_lpdf(Intercept | MU_INTERCEPT, SD_INTERCEPT);
^
28: }
29: model {
-------------------------------------------------
Identifier 'MU_INTERCEPT' not in scope.