Does brms ever fit using a negative sigma?

I have defined sigma inside my formula as:

bf(...) +
nlf(sigma ~ sigmaA + sigmaB * exp(sigmaC * y)) +
lf(sigmaA + sigmaB + sigmaC ~ 1)

and inside my priors sigmaA is unbounded while sigmaB & sigmaC are positive.

The problem is that the brms fit goes on to give a negative estimate for sigmaA so that if sigma is plotted as a function of y in the range of the available data y then there are some regions of the data where sigma is negative. I checked the raw Stan code (using brms::make_stancode() on the formula object) and there is no mention of sigma, only sigmaA, sigmaB & sigmaC. Therefore I cannot be sure that when Stan runs it is forbidding any (sigmaA, sigmaB, sigmaC) combinations that give a negative sigma, and thus it is only constraining for the lb = 0 I have set in the sigmaB & sigmaC priors.

  1. How do you constrain sigma to be above zero when it is defined by a relationship of other parameters?
    a) One brute force way would be defining nlf(sigma ~ abs(sigmaA + sigmaB * exp(sigmaC * y))).
    b) I’m guessing you may say to just apply an lb = 0 bound to the sigmaA but that could miss perfectly good parameter combos that don’t give a negative sigma in the range of the data.
  • Operating System: 5.10.16.3-microsoft-standard-WSL2
  • brms Version: 2.18.0

Have you checked what link function it is? I was thinking that when you model sigma, brms switches to default log link.

Hi @jd_c, family = gaussian() with the log link function. All the data is positive and above 1.

Isn’t using the log link to model sigma what constrains it to be positive? It can be negative on the scale of the linear predictor but then still a small positive value on the outcome scale

Yes that makes complete sense that the fitting would occur on the log scale. The only problem is it can lead to strange parameters ‘through the backdoor’ since when sigma as a function of y is plotted (therefore on the outcome scale) it can lead to negative sigma. Going to tag this as a bug.