I am trying to follow along with a series of Stan modelling tutorials and demos for demographic analysis, which are based on models and code in Kéry and Schaub’s 'Bayesian Population Analysis'. I have encountered some parsing failures out of the box and I am unfamiliar with Stan code. I checked the deprecated features in the stan reference manual (available for download here) but the code looks current as far as I can tell.
Here is some session info: R version 4.0.3, rstan_2.21.5, StanHeaders_2.21.0-7, Rcpp_1.0.9, RcppParallel_5.1.5
I get the same error when I run any of the example models on the linked GitHub site:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
error in 'modelxyz' at line 6, column 20
-------------------------------------------------
4:
5: functions {
6: int first_capture(array[] int y_i) {
^
PARSER EXPECTED: <argument declaration or close paren ) to end argument declarations>
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model 'cjs_age' due to the above error.
In addition: Warning message:
In readLines(file, warn = TRUE) :
incomplete final line found on '~/example-models/BPA/Ch.07/cjs_age.2.stan'
Take, for instance, the R script to call the Stan model at the link provided called "7.7_Models_with_age_effects.R" with the model "cjs_age.stan" and data "cjs_age.data.R". I also looked for missing semicolons in the code but everything looks right to me, granted I'm not well versed in the stan syntax. Any help would be appreciated very much.
I've never seen that way to declare an int
array as input before. Either that's a really old STAN version or a really new one, or an alternative way that I'm not aware of. Anyway, you should be able to fix the code by specifying int
arrays like that instead:
functions {
int first_capture(int[] y_i) {