Applying an Exponential Variance Function

Please also provide the following information in addition to your question:

  • Operating System: Ubuntu 16.04
  • brms Version: 2.10

Im trying to migrate some models from lme() (nlme package) to brms and I have problems replicating the variance functions (variance function structures - varFunc) in lme(). Currently Im working with the varExp class: ‘defined as s2(v) = exp(2* t * v), where t is the variance function coefficient and v the covariate’, and I want v to be the fitted values (or y_i). I have found code to achieve group specific variances in brms (similar to the varIdent in lme), but I cant find much on exp and power functions on sigma. These are usually very useful for handling increasing variance (maybe there are better ways in brms?).

My best try so far is something like:
b = bf(y ~ x + (1|id),
sigma ~ y)
brm(b, data = dat, family=brmsfamily(“gaussian”, link_sigma = “log”)

This seems to replicate varExp(form=~y) in lme() pretty well (residual variance is extracted through exp(sigma_Intercept ), and sigma_y is the exp parameter (t) given by lme() ). But I dont think it is exactly correct (x2 is not there for example). Also, this is not using the fitted values (the default in lme).

Any input on how to correctly specify these variance functions (exp, power) in brms is welcome.


1 Like

Hi! Welcome to the Stan forums! :)

Are you looking for something like this?

Edit: sorry! I didn’t read carefully enough… I don’t think think your code is doing what you want it to do. I’m not really sure if fitting the variance via fitted values is something that would work in a Bayesian regression, since in a Bayesian setting you fit mean parameters and variance parameters jointly. What about a Gamma regression or something similar?

1 Like

Thanks. I think you have a point regarding fitted values. Yes, Gamma or lognormal can sometimes be an option.

Also, if you are willing to go from brms to “proper” Stan, you would have a bit more flexibility to define variances. Not sure if those models would sample well, though. Just a thought. ;)

Currently, brms doesn’t IMHO support this. For next versions, it might be possible to force some coefficients to be equal across multiple formula, which would let you achieve what you need. You can also IMHO get a tiny bit of a similar effect via

b = bf(y ~ x + (1|a|id),
sigma ~ 1 + 1|a|id)

which would estimate the effects of id on sigma independently, but they will share a covariance structure with the effects on the outcome. The trick doesn’t work on fixed effects thought.

Obviously, when you move to plain stan, it should be possible to have exactly the behavior you seek.

OK. Thanks for you input on this.