Trouble running gamma model in brms

Hi all,

I’m attempting to run a model in brms with gamma distribution however, I’m not having much success. I’m new to brms (and modelling in general, honestly) so it’s very likely I’m missing something very simple.

My model is below. When I try to run this model I get the error message:
Error: The parameter ‘sigma’ is not a valid distributional or non-linear parameter. Did you forget to set ‘nl = TRUE’?

From what I understand this error message is suggesting I specify the model as non-linear, which actually I believe it is. However, I don’t know how to do this. I tried just adding nl= true to the model code but I still get the same error message. I tried it in a few different places without success. Instead of just continuing to aimlessly try to add it to different parts of the model I should probably gain a better understanding of where it belongs, why the error message says I need it, and what other information may be required to run this as a non-linear model. Any help and suggestions welcome!

Please let me know if there is any more information you require!

Thanks in advance.

m4_gam <-brm(bf(IVI ~ 1+ chicks + nestlingage + (1 + chicks + nestlingage| fyear) + (1 | fsite) + (1|fpair), 
                 sigma ~ fyear),
              data = data1, 
              family = Gamma(link = "log"),
              prior = NULL,
              warmup = 1000, 
              iter = 5000, 
              chains = 3,
              cores  = 2,
              control = list(adapt_delta = 0.99, max_treedepth = 15),
              backend = "cmdstanr", 
              threads = threading(2))

Hi Rebekah,

take this for what it is,

  1. Gamma doesn’t have a ‘sigma’, right? I don’t know how it is parameterized here…
  2. If you want to model this with nl = TRUE then have a look here: Estimating Non-Linear Models with brms
  3. May I ask what IVI is? How does it look like, i.e., what type of variable is it?
  1. Ah… That’ll certainly cause a problem then! Ha. The reason I was trying to run it with sigma is that I wanted to compare if there was a difference in estimates between modelling log transformed IVI (explained below) with poisson distributions and priors versus modelling untransformed IVI with gamma distributions. The model for logIVI is as follows:

m4_cor ← brm(bf(logIVI ~ 1+ chicks + nestlingage + (1 + chicks + nestlingage| fyear) + (1 | fsite) + (1|fpair),
sigma ~ fyear),
data = data1,
prior = c(set_prior(“normal(0, 0.5)”, class = “b”, coef = “nestlingage”),
set_prior(“normal(-0.1, 0.5)”, class = “b”, coef = “chicks”),
set_prior(“normal(6, 0.5)”, class = “Intercept”),
set_prior(“lkj(2)”, class = “cor”), # delete this line if you don’t want to estimate correlation among ranef
set_prior(“cauchy(0,1)”, class = “sd”)),
warmup = 1000,
iter = 5000,
chains = 3,
cores = 2,
control = list(adapt_delta = 0.99, max_treedepth = 15),
backend = “cmdstanr”,
threads = threading(2))

I am interested in looking at how residual variance differs across years to test hypotheses related to year specific differences in behaviour ( I study variance-sensitivity, formally termed risk-sensitivity, if you’re familiar with that by chance).

  1. I’ll take a look at that today. It may be something I need to incorporate in the above model too, by the sounds of it.

  2. IVI means inter-visit interval. In my case, it is the time between consecutive provisioning visits of adult peregrine falcons to the nest. It’s always positive. Lots of values < 1 hour (most), many within 2 hours, decreasing to a maximum of I believe around 8 hours.

Think about using a lognormal perhaps? :)