Closed AndreaNOdell closed 2 years ago
Capturing what we already talked about as a general approach to debug (and steps you've already taken I think): 1) Start with a simple non-hierarchical model and build complexity from there once it's running 2) If it's a MCMC sampling issue, can start with tight priors around known values (e.g., a growth model fit outside STAN)
A couple of other things that stuck out to me with the STAN code when I was looking at it just now that may (or may not!) be causing trouble:
You may need to define the prior parameter values in the data block?
I think the random effects should be normally distributed, not lognormal https://github.com/AndreaNOdell/hake_growth/blob/604035f0d4c4cff5334e27b4f0905aec0401b2df/scripts/BayesGrowthModel.R#L20
I wonder if it would run differently if you set the mean of the likelihood equal to a variable and then stuck that variable, (e.g., pred[i]) into the likelihood instead? That's generally how I've set up models in jags in the past - I'm not sure if affects the sampling in STAN or just improves code readability though.
You maybe looked at this already, too, but here is the STAN code for a bayesian VGBF, just to compare syntax, etc. I think this may be the function you fit already.
Just some ideas to try if you're still stuck. Happy to chat tomorrow, too.
Gave those a shot (with no success) and spoke with Kiva who suggested using brms, a package that fits bayesian linear and nonlinear multilevel models. Brms worked immediately haha! I also switched the VB parameterization to the one used in the 2006 stock assessment. I first fit a nonlinear fixed effect model to check if it worked, and now currently running the rho random effect model and may check out a K random effect model.
Tried brms() and that was an easy solution!
Wrote up some code to fit a bayesian growth model using the VB growth model in the 2006 stock assessment which uses a L1 L2 parameterization. I am getting a lot of warnings about divergent transitions, low bulk/tail effective sample sizes, large Rhat, etc. I've only ever fit linear models using stan, so there may actually be an issue with my stan code - could you have a look at it? Warnings suggest increasing the number of iterations and max_treedepth, but wanted to check in with you before I keep running the code (it takes a while). The code can be found in scripts > BayesGrowthModel