Why did horseshoe prior not work in hierarchical model regression with spline?

Hi, I want to fit a hierarchical model using horseshoe prior , I’ve considered two responses of y to x. One is linear response model (model 1):

fit_brm_linear <- brm(Y ~ X +(1 +X | group1) + (1 + X | group2),
                      data = dat,
                      family = exgaussian(),
                      chains = 3,
                      iter = 1000,
                      cores = 4,
                      control = list(adapt_delta=0.99),
                      prior=c(prior(horseshoe(1),class="b")),
                      seed = 1345
                      )

another one is non-linear response model (model2):

fit_brm_no_linear <- brm(Y ~ s(X) +(1 +X | group1) + (1 + X | group2),
                      data = dat,
                      family = exgaussian(),
                      chains = 3,
                      iter = 1000,
                      cores = 4,
                      control = list(adapt_delta=0.99),
                      prior=c(prior(horseshoe(1),class="b")),
                      seed = 1345
                      )

Model 1 worked fine, but model 2 reported an error:
Prior 'horseshoe(1)' is used in an invalid context. See ?set_prior for details on how to use special priors.

I’m confused about this. I think model 2 formula maybe is wrong but the model 2 work well when no prior is specified for it. Is there a specific non-linear formula when using horseshoe prior?

I would appreciate it if you could give me some advice.

1 Like

A quick guess: maybe the second model actually has no coefficients of class b? You can check which coefficients are used (and their classes/names) by calling get_prior.

Best of luck with your model!

Thanks very much! It still doesn’t work.

Do you need additional help? If so, please be a bit more specific than “doesn’t work”? What is the result you get when calling get_prior - are there any coefficients of class b? Did you try changing the class for the prior to match the get_prior results?

Hi,Thanks very much ! I just want to set a prior for my model that contains one predictor, because the posterior distribution is inconsistent with the data when set a flat prior. Here is what get from get_prior. I have try to specify coef='sX_1' in prior(), but there is still a error : Prior 'horseshoe(1)' is used in an invalid context. See ?set_prior for details on how to use special priors. Do I need to specify horseshoe() for each class and coef ? Could you give me some advice ?

        prior              class             coef          group        resp     dpar     nlpar     bound       source
        (flat)               b                                                                                  default
        (flat)               b               sX_1                                                           (vectorized)
        lkj(1)              cor                                                                                 default
        lkj(1)              cor                            group1                                           (vectorized)
        lkj(1)              cor                            group2                                           (vectorized)
    beta(1, 1)               hu                                                                                 default
student_t(3, 0, 2.5)      Intercept                                                                             default
student_t(3, 0, 2.5)        sd                                                                                  default
student_t(3, 0, 2.5)        sd                             group1                                           (vectorized)
student_t(3, 0, 2.5)        sd                X            group1                                           (vectorized)
student_t(3, 0, 2.5)        sd            Intercept        group1                                           (vectorized)
student_t(3, 0, 2.5)        sd                             group2                                           (vectorized)
student_t(3, 0, 2.5)        sd                X            group2                                           (vectorized)
student_t(3, 0, 2.5)        sd            Intercept        group2                                           (vectorized)
student_t(3, 0, 2.5)       sds                                                                                  default
student_t(3, 0, 2.5)       sds           s(X, k = 10)                                                       (vectorized)
student_t(3, 0, 2.5)     sigma                                                                                   default

Here is my data distribution( continuous variable from -1) and posteriori distribution.
数据分布
posteriori distribution

OK, so this might be a mild bug in brms, in that it probably should work as specified even with the spline term, but the model still is not very useful. The horseshoe prior is intended to provide shrinkage when you have multiple “fixed” predictors (e.g. Y ~ X1 + X2 + X3 + X4). In your model, you only have one predictor term, so the hyperparameters associated with the horseshoe prior will not be informed by the data in any way, so you might as well just put a normal or student_t prior on the single “fixed” coefficient to achieve almost exactly the same model as with the horseshoe prior.

This type of problem is very unlikely to be fixed by providing a narrower prior - having an overly wide prior can result in overfitting the data, but is unlikely to lead to underfitting/misfit as we see here. My best (quick) guess is that it is the negative values that are problematic for the model. In the exgaussian family as implemented in brms, only the gaussian component has support for negative values, which seem to be the majority of your data. At the same time the data are skewed, but the gaussian component can’t handle the skew. So maybe you need to transform your data or use a different response distribution.

Best of luck with your model!

Hi, thanks very much again ! I transformed Y to Y+1 and set hurdle_lognormal family, finally the posterior distribution fit data perfect.

1 Like