trouble with nimble ecology dDHMMo distribution

18 views
Skip to first unread message

Kirsty Laurenson

unread,
Apr 20, 2026, 10:14:51 AM (2 days ago) Apr 20
to nimble-users

Hi all, 


I have a multistate CMR model that forms part of a larger IPM that I am trying to marginalise using the distributions from NimbleEcology as the run time for my IPM is approaching the time limit for jobs on my University’s HPC. However, I’m running into some issues which I haven’t been able to solve after reading through the introduction to NimbleEcology page, or the relevant conversation threads in this group. 


When I run ‘nimbleModel’ on my model, I get the message telling me my model is not fully initialised, and when I investigate this using model$initializeInfo(), I get: Missing values (NAs) or non-finite values were found in model variables: omega. Omega is my observation matrix. When I look closer at model$omega, the values for omega at the last occasion are all NA. Additionally, after compiling the model and MCMC and trying to run the model, I get the ‘logProb of data node is NA’ warnings, which I suspect is linked to the issues with omega. 


I have attached a script with the model code to run on simulated data. The script includes the non-marginalised model, which runs fine, and a version of the model where I have tried to use the dDHMMo distribution, without success. I get the same warnings when I run the dDHMMo model on the simulated data and my real data. I have a feeling these problems are arising because I haven’t quite coded the model correctly using the dHMMo distribution, but after reading the relevant conversation threads on this forum and the intro to nimble ecology, I still haven’t been able to wrap my head around it! Any help or suggestions would be greatly appreciated!


Best, 

Kirsty

simulate_mscmr_necology.R

Thomas Riecke

unread,
Apr 20, 2026, 11:17:03 AM (2 days ago) Apr 20
to Kirsty Laurenson, nimble-users
Hi Kirsty,

I've struggled a bit with Nimble's marginalized capture history functions in the past, but have some working code I could share, and I'm sure experienced nimble users will have better advice. Before diving down that rabbit hole though, a couple of quick potentially useful thoughts:

If you don't have individual covariates (all covariates are cohort-level or based on t), marginalizing capture histories by individual is generally a very slow way to do things:
It looks like you’re using Schaub-type code. The IPMbook also has examples for multistate m-arrays which typically run much faster (orders of magnitude). You could run this on a good laptop instead of an HPC. Note that there is a minor error in the code as written in the IPM book, it’s corrected in the erratum. Mike Meredith wrote some really nice code here with Michael, Richard Chandler has built some similar code, all based on Williams et al. (2002). You could also marginalize across all individuals with identical capture histories (following Yackulic et al. 2020, EcoApps), but I think that's generally slower than the multinomial approach as well.

You could (and should?) substantially reduce your number of states as well, regardless of whether you have individual covariates or not, by simply making the transition to breeder conditional on time since release.
for (t in f[i]:T){
   psi[pre-breeder, i, t, breeder] <- alpha[t - f[i] + 1] * phi[whatever]
}
This would also greatly reduce runtime. Something like this would still give you different alpha's for each age, rather than having them move forward through a bunch of temporary classes. Then you would have fledglings, non-breeders, and breeders as your states instead of NB2, NB3, .... , NB6+. The absorbing state can be marginalized out. This will substantially reduce the model's complexity. There are many different ways to index these parameters. Dan used a similar trick in one of our papers, there are lots of other good examples:

Hope that's helpful and not too off-topic, just a note that rethinking how you write the model may be more helpful here than fixing the code.

Thomas

--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/nimble-users/0ab480ae-a395-49d2-a2de-cc03611e3322n%40googlegroups.com.

Kirsty Laurenson

unread,
Apr 20, 2026, 11:45:44 AM (2 days ago) Apr 20
to nimble-users
Hi Thomas, 

Thanks for sharing your thoughts! I've had a quick look at your suggestions and those links to papers and code you've shared and I think they will be very helpful!

Best, 
Kirsty

Reply all
Reply to author
Forward
0 new messages