I'm modeling camera trap data (counts) with camera site as a random effect and landscape-level covariates + season as fixed effects, and an offset for number of days the camera station was active, as below:
mod2 <- glmmTMB(Coyote ~ develop + PERCENTILE + season + (1|site),
offset = log(days.active),
data = all_dat, family = "nbinom2")
and am, as of today, encountering the following error message:
Error in fitTMB(TMBStruc) : negative log-likelihood is NaN at starting parameter values
I have about 400 observations in my data. I only get this error when the offset is included, and it happens with both a negative binomial and Poisson model. My code was working just fine until it suddenly didn't, so I assume the issue was related to the recent Matrix changes and associated dependencies in TMB, as detailed in similar questions here with the same error in glmmTMB and here with a similar issue in lme4. However, none of the solutions in the links have worked for me (I tried commenting instead of opening a new question but wasn't able to as my account is new). I'm on macOS 12.5.
I have tried:
- Reinstall Matrix to version 1.6-2 as suggested by an answer in the first link using install_versions from the remotes package
- Reinstall Matrix from source (version 1.6-3) and also reinstall TMB and glmmTMB as suggested by the Matrix dev in the second link -- I tried this both ways suggested in the answer, by installing TMB/glmmTMB from the source and then trying to install a compatible binary from CRAN
- Reinstall Matrix from the source (version 1.6-3) and only reinstall glmmTMB from source, as installing TMB from source resulted in version discrepancies between glmmTMB and TMB
- Updated R and tried all of the above again
Both reinstallation methods didn't work at all for me until I installed gfortran, but now they are at least installing -- just not solving my issue.
Thanks in advance for any help!
This is just a guess, but I can easily get this error if I have a 0 in the variable that I am logging in order to get the offset (which would be
any(all_dat$days.active == 0)
in your case):(However, this is not consistent with "it was working before but then it stopped working", as this error should have happened with previous versions of the package too ...)