Modelling spatiotemporal random effects results in

Just a note: it is possible that the problem is not Sigma_phi, but something else. The error is not about some values being immediately problematic, but rather that the gradient is infinite - this is unfortunately a bit harder to debug. The possibilities include:

  • Some of the denominators in computing H_pre04 / H_04 being very close to 0.
  • f large leading to exp(y) very large
  • m < 0 (but I think that would give a different error, but I am not sure)

In all cases, you can use print statements to get output from the model and see a bit better what’s happening. I would also suggest you try to simplify the model further - most notably, which terms of the covariance matrix can you remove and still see the issue?

EDIT: Additionally, in older versions of Stan (I think before 2.23, which includes the CRAN version of rstan), there were some numerical instabilities in neg_binomial_2 which might also be partly responsible.

1 Like