Error "Priors do not correspond to any parameter" when setting priors in a model with the "Categorical" family

Hi everyone,

I know there’s two previous posts on a similar subject, but there were not helpful to me.

I’m trying to run a model with a categorical family. My original outcome has only two responses (healthy, or has a certain disease). I’m trying to calculate the risk of having the disease, based on various numerical factors, and the nominal variable of sex (male and female). My hope was to run the regression and then extract odds ratios. I was wanting to set subjective priors, but I always get the error message that the priors I have set do not correspond to any within the model. When I consult prior_summary() or get_priors(), I get the exact same names as I have in my set_prior() code.

I’ve produced a repex for you with the iris data. My operating system is Mac OS 14.1.1, with brms version 2.20.4.

 irismodel <- brm(data=iris,family=categorical("logit",refcat = "virginica"),Species~1+Sepal.Width+Sepal.Length, prior=set_prior("normal(0,1)",class="b",coef="Sepal.Width"),sample_prior=TRUE)
Error: The following priors do not correspond to any model parameter: 
b_Sepal.Width ~ normal(0,1)
Function 'get_prior' might be helpful to you.

My guess is that I’m missing some theoretical background knowledge to help me understand my problem. If anyone could point me in the correct direction for further reading and/or help me with a piece of code to solve my problem, I would be ever so grateful.

Thank you and happy weekend!

With the categorical family, each outcome category (except for the reference level) gets its own set of coefficients. So Sepal.Width in the model formula actually results in two different coefficients in the model, each with its own prior. set_prior uses the dpar (“distributional parameter”) argument to specify these separate predictors. In your example, the prior would be set as follows:

c(set_prior("normal(0,1)", class="b", coef="Sepal.Width", dpar="muversicolor"),
  set_prior("normal(0,1)", class="b", coef="Sepal.Width", dpar="musetosa"))

You can see a list of all the coefficients associated with a model formula and family by running get_prior:

get_prior(Species ~ 1 + Sepal.Width + Sepal.Length, 
          data=iris, family=categorical("logit", refcat="virginica"))

Note the dpar column in the output.

                prior     class         coef group resp         dpar nlpar lb ub       source
               (flat)         b                             musetosa                  default
               (flat)         b Sepal.Length                musetosa             (vectorized)
               (flat)         b  Sepal.Width                musetosa             (vectorized)
 student_t(3, 0, 2.5) Intercept                             musetosa                  default
               (flat)         b                         muversicolor                  default
               (flat)         b Sepal.Length            muversicolor             (vectorized)
               (flat)         b  Sepal.Width            muversicolor             (vectorized)
 student_t(3, 0, 2.5) Intercept                         muversicolor                  default
1 Like

Hi, thank you so much for your explanation and code! This solved my problem. Happy weekend to you!

1 Like

For binary and ordinal logistic models the R rmsb package’s blrm function provides a way to specify priors on a set of user-specified contrasts, and these priors on contrasts are automatically propagated by Stan back to the original model coefficients. This provides a natural and flexible way to specify priors without the user needing to be aware of the model’s parameterization (choice of reference cell, for example). Examples are here.