Exception: gamma_lpdf: Inverse scale parameter[1] is -xxx, but must be positive finite!

Hello,

I am trying to run the following model in r:

brms::brm(formula = acc ~ cond * run + (cond | subj) + (1 | block),
  data = data, family = Gamma(link = "identity"), 
  warmup = 1000, iter = 10000, chains = 4,
  control = list(adapt_delta = 0.99, stepsize = 0.0001, max_treedepth = 30))

Distribution of my data is the following:


So all data are positive and distribution is close to gamma.

When I run it, I get several errors of this kind:

Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: Exception: gamma_lpdf: Inverse scale parameter[13] is -0.0240896, but must be positive finite! (in 'anon_model', line 86, column 4 to column 49)
Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: Exception: gamma_lpdf: Inverse scale parameter[39] is -7.9367, but must be positive finite! (in 'anon_model', line 86, column 4 to column 49)
Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: Exception: gamma_lpdf: Inverse scale parameter[1] is -0.849606, but must be positive finite! (in 'anon_model', line 86, column 4 to column 49)
...

If I try to run the same model with the log as link function, no errors are popping up.

Do you know why negative initial values are generated when I use the identity link function?
Is this an hint telling me I should use the log?
I don’t have any hypothesis for which the link function should be log.

Thank you very much in advance!

  • Operating System: Ubuntu 18.04.5 LTS
  • brms Version: ‘2.18.3’

The gamma likelihood is only defined for certain parameter ranges; a positive mean and positive inverse scale parameter. I guess that you could in theory have data that does not lead to a violation of those constraints, but your data obviously leads to posterior draws for parameters, that are not valid after the identity link transformation.

So the question is more, do you have a good reason to try the identity link (which is unbounded) for a family, that has limited support (ie. they are bounded) on it’s parameters?

1 Like

Yes, “this [is] an hint telling [you you] should use the log.”

No, I just thought I did not have reasons to use the log, hence the identity link would have affected less my model. Still, it works quite well (also looking at quality plots) when using the log.

Do you have some tests to check which link family is better, knowing my fixed factor is a categorical variable?

Ok, thanks!!
I am now using the log link.

Maybe same question that I asked to Scholz, do you have some tests to check which link family is better, knowing my fixed factor is a categorical variable?

Thank you again!

Not really. This is just knowledge from the streets. Basically, if you have a lower limit of 0 and no clear upper boundary, the log link tends to work. If you have clearly-defined lower and upper limits, the logit or probit links tend to work well.

1 Like