I am trying to pass a computed variable as part of a prior, e.g.
s <- ...
prs <- c(prior(normal(0, s), class='b', coef='age'), ...)
But I get an error message during Stan compilation. How should I do this? Note that I don’t want this to represent a hyperprior; it’s just a computed constant for the standard deviation of the prior.
Here’s the code and error message:
prs <- c(prior(student_t(3,0,10), class='Intercept'),
prior(normal(0, s1), class='b', coef='sexmale'),
prior(normal(0, s2), class='b', coef='age'))
fit_brms <- brm(response ~ sex + age, data=sex.age.response,
family=bernoulli("logit"), prior=prs, iter=5000)
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
variable "s1" does not exist.
error in 'model1d075d3cb4f5_file1d0711f5317d' at line 29, column 37
-------------------------------------------------
27: vector[N] mu = Xc * b + temp_Intercept;
28: // priors including all constants
29: target += normal_lpdf(b[1] | 0, s1);
^
30: target += normal_lpdf(b[2] | 0, s2);
-------------------------------------------------
Error in stanc(model_code = paste(program, collapse = "\n"), model_name = model_cppname, :
failed to parse Stan model 'file1d0711f5317d' due to the above error.
- Operating System: xubuntu 17.04
- brms Version: 2.2.0