Hi folks,
I’m very new to Stan, and I am currently using capture-recapture models from Kery & Schaub’s Bayesian Population Analysis to estimate population abundance. I’ve used many of these models for several years in JAGS and am quite comfortable with them, but I’m a complete novice when it comes to Stan syntax. With some much needed help from Hiroki Ito, I’ve been modifying his Stan conversions from the BPA book: https://github.com/stan-dev/example-models/blob/master/BPA/Ch.10/js_super_indran.stan . Now I’ve got four different model formulations that I’ve run on my dataset, and after about ten days of computer time, I realized for the first time that Stan does not automatically compute DIC or the metrics necessary for calculating WAIC, LOO, etc. for model comparison. I’m trying to figure out how to calculate a log_lik using a user defined function, and am hitting a wall (no doubt due to my Stan ignorance).
Following this example, I tried adding the following code to the generated quantities block:
// Log Likelihood for WAIC:
{
real log_lik;
log_lik = js_super_lpn(y, first, last, p, phi, psi, nu, chi);
}
But I receive the following error:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Sampling statements (~) and increment_log_prob() are
only allowed in the model block or lp functions.
The Stan model code is almost identical to the BPA-converted code above, minus individual effects and with the user defined function name changed to js_super_lpn (because I learned from a previous error message that functions ending in _lp cannot go in the generated quantities block). I’ve attached my code here as well.
Many thanks in advance for your input
js_super_ll.stan (8.6 KB)
.
Cheers,
Josh