specifying initial values

89 views
Skip to first unread message

Kirsty Laurenson

unread,
May 16, 2025, 10:32:34 AM5/16/25
to nimble-users

Hi all, 

 

I’m trying to run an IPM for a seabird population in the UK, with mark-recapture data from birds ringed as chicks and adults, breeding success data, and count data from 1995-2021. I have a version of the model which runs without any issues; however, the model cannot estimate adult survival rates very well from the beginning as there were no birds ringed as adults in 1995, and therefore does not estimate overall population size very well. I decided to remove 1995 from all my datasets and run my IPM from 1996 onwards, however, I’m having trouble getting the initial values right. From my second MCMC chain onwards (never the first chain), I get a warning which says ‘log prob is -Inf’ for some of the population size nodes, then once the MCMC chain starts I get the ‘slice sampler reached maximum number of contractions’ warning. 

 

I understand that this is a problem with the initial values, but I don’t understand what’s wrong with the initial values I’ve specified as the model ran without issues with the data from 1995-2021; and I don’t know what initial values would be suitable! My code for the two models is attached (1995-2021 and 1996-2021), and I’m happy to share data off-list if anyone could help me get my initial values right!

 

Many thanks, 

Kirsty

ipm_1996_combined_phiad.R
ipm_1995_combined_phiad.R

Perry de Valpine

unread,
May 16, 2025, 11:29:29 AM5/16/25
to Kirsty Laurenson, nimble-users
Hi Kirsty,

Thanks for the question. Usually what you've described turns out to be a situation where the initial values provided make something impossible in the model, resulting in a probability of 0, or log probability of -Inf. In ecological models this has happened when there is something like

N2 ~ dbin(p, N1)

where the initial values have N2 > N1, which is impossible, or

z ~ dcat(p[1:T])

where z takes a value such that p[z]==0, which is impossible.


You can use the model object (you will have to use nimbleModel rather than going straight to nimbleMCMC) to inspect any calculated values and pinpoint exactly where impossible stochastic outcomes are occurring. 

Here is our user manual section on initialization issues, in case you haven't checked it out yet.

So your steps to debug would look something like this:

model <- nimbleModel(code = nimble.random.ipm,
                                           constants = my.constants,
                                           data = my.data,
                                           inits = initial.values)
# you may get a message warning your the model is not fully initialized. If so you can follow the instructions by running model$initializeInfo().

Either way, you can then dig into where there is a problem. For example:
model$calculate("NJ") # sum of log probs for all nodes in the variable NJ.
# If that is -Inf, you can look at the individual log probabilities in several ways
model$calculate("NJ[1]") # log prob for this single node
# or
model$calculate("NJ[1:10]") # sub of log probs for this set of single nodes
# or
model$logProb_NJ # vector of all log probabilities for NJ
# Say you find that NJ[5] has a logProb of -Inf. Then you can figure out why by inspecting its inputs:
model$p[4]
model$phi.1[4]
model$NB4[4]
# etc.

HTH
Perry


--
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/95d244ac-bf60-4cc8-adc1-245bd576cec4n%40googlegroups.com.

Kirsty Laurenson

unread,
Jun 9, 2025, 12:39:43 PM6/9/25
to Perry de Valpine, nimble-users
Hi Perry, all,

Thank you for your helpful response! I think my issue is stemming from the fact that I have some ages/stages that are 'absorbing' - non-breeders aged 5+ and breeders aged 6+ - which end up with larger numbers of birds than earlier ages/stages. I didn't know that this was impossible in nimble, so this is really helpful information. I've now successfully got that IPM running.

However, I now want to turn my IPM into a PVA and project the population forward 20 years under different proposed climate scenarios, but I'm running into issues with my initial values again. I want to investigate the impact of weather on some demographic parameters, and how the population might change in the future with these weather effects. I want to include weather impacts on juvenile survival (phi.1 in my model), adult survival (phi.adult), and recruitment (alpha.6). However, when I run nimbleModel I'm getting this warning:

 [Note] Missing values (NAs) or non-finite values were found in model variables: phi.1, phi.adult, alpha.6, lifted_oPNB4_oB2_comma_t_cB_plus_NB5_dot_T_oB2_comma_t_cB_plus_NB6_dot_T_oB2_comma_t_cB_cP_L253, lifted_p_oBt_cB_over_2_times_phi_dot_1_oB2_comma_t_cB_L253, lifted_phi_dot_4_oBt_cB_times__oP1_minus_alpha_dot_4_oBt_cB_cP_L256, lifted_phi_dot_adult_oB2_comma_t_cB_times__oP1_minus_alpha_dot_5_oBt_cB_cP_L257, lifted_phi_dot_adult_oB2_comma_t_cB_times__oP1_minus_alpha_dot_6_oB2_comma_t_cB_cP_L258, lifted_phi_dot_4_oBt_cB_times_alpha_dot_4_oBt_cB_L259, lifted_phi_dot_adult_oB2_comma_t_cB_times_alpha_dot_5_oBt_cB_L260, lifted_oPphi_dot_adult_oB2_comma_t_cB_times_alpha_dot_6_oB2_comma_t_cB_cP_L262, lifted_oPNB4_oB3_comma_t_cB_plus_NB5_dot_T_oB3_comma_t_cB_plus_NB6_dot_T_oB3_comma_t_cB_cP_L283, lifted_p_oBt_cB_over_2_times_phi_dot_1_oB3_comma_t_cB_L283, lifted_phi_dot_4_oBt_cB_times__oP1_minus_alpha_dot_4_oBt_cB_cP_L286, lifted_phi_dot_adult_oB3_comma_t_cB_times__oP1_minus_alpha_dot_5_oBt_cB_cP_L287, lifted_phi_dot_adult_oB3_comma_t_cB_times__oP1_minus_alpha_dot_6_oB3_comma_t_cB_cP_L288, lifted_phi_dot_4_oBt_cB_times_alpha_dot_4_oBt_cB_L289, lifted_phi_dot_adult_oB3_comma_t_cB_times_alpha_dot_5_oBt_cB_L290, lifted_oPphi_dot_adult_oB3_comma_t_cB_times_alpha_dot_6_oB3_comma_t_cB_cP_L292.

I've tried following the advice for initial values in the nimble manual, but I'm still not sure how to get this sorted - especially for the lifted nodes, as this wasn't an issue before! Any advice or help would be greatly appreciated!! I've attached the latest version of my code, and I am happy to share data off-list.

Many thanks, 
Kirsty
predict_storm_impacts.R

Daniel Turek

unread,
Jun 9, 2025, 4:33:32 PM6/9/25
to Kirsty Laurenson, Perry de Valpine, nimble-users
Kristy, I'm not certain if you're able to (or if you already have) shared the multitude of csv data files which are used in your script.  If you are (or already have), that would help immeasurably for tracking down the issue.  Is that something you're able to do?  (sharing off-list is totally fine, as well).

Thanks,
Daniel


Chris Paciorek

unread,
Jun 10, 2025, 6:26:35 PM6/10/25
to Kirsty Laurenson, nimble-users
hi Kirsty, I'm not sure any of us on the dev team will be able to look at this in detail in the near future, but my high-level suggestions are:

1) I am wondering if the issue is the nodes that have the logit transformation on the left side and something is getting messed up there.

What do you see as the values for phi.1, phi.adult, alpha.6 in the model once it is built? And relatedly, what do you see for the values of mu.phi1, ep.phi1, mu.phiadult, ep.phiadult, mu.alpha6, ep.alpha6, which should be used to calculate phi.1, phi.adult, and alpha.6?

2) Focus on the non-lifted nodes, as the lifted nodes should get initialized deterministically based on non-lifted nodes. For example, you can dive a bit into the calculation of the lifted nodes and try to see what is going on. E.g.,  `lifted_oPNB4_oB2_comma_t_cB_plus_NB5_dot_T_oB2_comma_t_cB_plus_NB6_dot_T_oB2_comma_t_cB_cP_L253` is produced from `(NB4[2,t] + NB5.T[2,t] + NB6.T[2,t])`, so check the values of NB4, NB5.T, and NB6.T in the model.


-chris

Reply all
Reply to author
Forward
0 new messages