Greetings list member,
I am attempting to fit the age-structured state-space model of Millar and Meyer (2000) using Stan. Millar and Meyer (2000) used data originally from Myers and Cadigan (1995) and coded the model in WinBUGS. My initial attempt, using the same data, resulted in divergent transitions at every saved step (See code attached). Based on the suggestions from the manual and many online sources, I first tried to increase adapt_delt to 0.99, reducing stepsize to 0.5, increasing max_treedeth to 15, increased total iterations to 6000 discarding the first 1500, and continued to get divergent transitions at each step. I have also tried modifying the program using Neal’s trick for all parameters that have a normal prior, giving total mortality a beta prior, and simplifying total mortality to be constant across years and age. All of these attempts did not help and I continued to get divergent transitions at each step.
What other options do I have to get around the divergent transitions? I believe the next step is to reparametrize the model but given how simple the model is, I don’t think I can do that.
I would greatly appreciate any suggestions on what to do next.
Windows 10, 64-bit
Millar, R.B., and R. Meyer. 2000. Bayesian state-space modeling of age-structured data: fitting a model is just the beginning. Canadian Journal of Fisheries and Aquatic Sciences 57:43-50.
Myers, R.A., and N.G. Cadigan. 1994. Was an increase in natural mortality responsible for the collapse of northern cod? Canadian Journal of Fisheries and Aquatic Sciences 52:1274-1285.
RCodeSCA.R (3.2 KB)
SCABaseMod.stan (2.0 KB)
Are the divergences the only errors you’re getting from this model?
I ask in part because I’m not sure how this equation stays positive:
LogN[a,y] = log(exp(LogN[a-1,y-1]) * exp(-M[a-1,y-1]) - C[a-1,y-1] * exp(-0.5 * M[a-1,y-1]) );
I think you might have some constraints missing on the parameters.
Thanks for the reply.
Yes, the divergence errors are the only errors (but I also get “There were 1 transitions after warmup that exceeded the maximum treedepth.” if the max_treedepth is not set to 15).
However, if I do not specify sufficiently large starting values for LogN, LogRecruits, and LogInitials, the model give the following error.
Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: lognormal_lpdf: Location parameter is nan, but must be finite! (in ‘model26ec25344a01_SCABaseMod’ at line 65)
The very large values for LogN
The equation you asked about describes the decline in abundance of an individual cohort after one year and has experienced mortality (M) and reduction in catch ©. I modified the code to constrain M and LogN to lower=0 but still received convergence issues. Are there other parameters that I should be constraining?
I should also add, that I am only using one chain for diagnostics. I will run 3 chains after figuring out the divergence issue.
The point behind @sakrejda’s comment is that Stan requires every parameter value that satisifes the declared constraints have support in the model (finite log density). If you don’t constrain things that need to be positive to remain positive, you’ll run into problems.
I think you might want to try a non-centered parameterization for
M. It’s not the number of lines of code, it’s the posterior geometry. You might want to look at the manual discussion of the funnel or Betancourt and Girolami’s paper on hierarchical modeling with HMC.
Stan also works better on a unit scale in the posterior. Unless you expect values of
MeanLogM of +2000 or -2000, use a tighter prior than
normal(0, 1000). Fat priors can lead to difficult computations when Stan tries to explore the tails.