Hi, I’m new to Stan and just finished figuring out how to get rstan working on my Macbook M1 Pro ARM computer with Monterey (downloaded latest versions of r and rstudio). I tried running the first example “Eight Schools” from here: RStan Getting Started · stan-dev/rstan Wiki · GitHub and I get an error that Stan failed to parse. Could anyone help me try to figure out what’s going on? I wasn’t sure if there was something wrong with my rstan installation on my mac as it was quite a challening process, but I actually also tried this on a windows laptop I have, and got the same error. Here’s the code and error:
Function:
fit ← stan(file = ‘schools.stan’, data = schools_dat)
Error:
PARSER FAILED TO PARSE INPUT COMPLETELY
STOPPED AT LINE 35:
data {
int<lower=0> J; // number of schools
real y[J]; // estimated treatment effects
real<lower=0> sigma[J]; // standard error of effect estimates
}
parameters {
real mu; // population treatment effect
real<lower=0> tau; // standard deviation in treatment effects
vector[J] eta; // unscaled deviation from mu by school
}
transformed parameters {
vector[J] theta = mu + tau * eta; // school treatment effects
}
model {
target += normal_lpdf(eta | 0, 1); // prior log-density
target += normal_lpdf(y | theta, sigma); // log-likelihood
}
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model ‘schools’ due to the above error.
Thanks for your response. Unfortunately, restarting my r session did not fix the problem. I don’t know enough about coding to understand what would need to be done in the solution provided within another post from the thread you posted. If anyone has a means of explaining the solution, or another possible workaround (if available) I would appreciate it, thank you!
What I will say is I have run other code in stan successfully in a recent prstatistics course I took–so I’m not sure why this stan modile file/code in particular is giving me issues.
Hi - I had the same error. I determined that the cause was that my stan script had a “#”(pound/hash/number sign) - even though the # was in a comment. Removing the “#” fixed the issue.
Hi there,
I am new to Stan and I am getting the following errors. Could you please help?
0,248,Js_of_ocaml__Js.Error,16,TypeError: not a function
0,248,Js_of_ocaml__Js.Error,16,TypeError: not a function
Error in stanc(filename, allow_undefined = TRUE) : parser failed badly
In addition: Warning message:
In system(paste(CPP, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘gcc’ not found
0,248,Js_of_ocaml__Js.Error,16,TypeError: not a function
0,248,Js_of_ocaml__Js.Error,16,TypeError: not a function
Hi
I am getting this error. I am new to this forum.
0,248,Js_of_ocaml__Js.Error,18,TypeError: not a function
Error in stanc(filename, allow_undefined = TRUE) :
parser failed badly; maybe try installing the V8 package
In addition: Warning message:
In readLines(file, warn = TRUE) :
incomplete final line found on ‘model1.stan’
0,248,Js_of_ocaml__Js.Error,18,TypeError: not a function
I have also started getting this error after updating. Is there an issue with the most recent version of rstan?
0,248,Js_of_ocaml__Js.Error,18,TypeError: not a function
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
parser failed badly; maybe try installing the V8 package
Edit: Solved: remove any hasgtags in your model code, even if they are after ‘//’ (I had them in as shorthand for “number” in my comments
0,248,Js_of_ocaml__Js.Error,18,TypeError: not a function
Error in model_cppcode$errors : $ operator is invalid for atomic vectors
0,248,Js_of_ocaml__Js.Error,18,TypeError: not a function
Error in model_cppcode$errors : $ operator is invalid for atomic vectors
Hi,
I recently updated rstan to version 2.217 (using stan. version 2.21.0). Code that used to have no problem with the old parser now results in declaration errors with the updated parser. It seems the new parser is perhaps stricter with variable declarations. I’ve solved some problems but can’t sort the declaration error (variable vector does not exist). I’ve tried different declarations (E.g., replace vector with real) but no luck. Any help would be appreciated
transformed parameters{
//No problem with the following two declarations
vector[Nages] vuluse;
vector[2] vulest;
vuluse[1]=0; vuluse[4]=1.0;vuluse[5]=1.0;vuluse[6]=1.0;
vulest[1]=inv_logit(logit_vulest[1]);
vulest[2]=inv_logit(logit_vulest[2]);
vuluse[2]=vulest[1];vuluse[3]=vulest[2];
//Declaration for mattuse causes parser error ‘variable “vector” does not exist’
vector[Nages] mattuse;
vector[Nages-2] bmattest;
mattuse[1]=0.0;mattuse[Nages]=1.0;
for(iage in 2:(Nages-1)){
bmattest[iage-1]=inv_logit(est_logit_bmatt[iage-1]);
mattuse[iage]=bmattest[iage-1];
}
}
That is extremely out of date - the current CRAN version is 2.32.6
I’ve solved some problems but can’t sort the declaration error (variable vector does not exist)
The error is occurring because you have a parameter declaration after parameter/value assignments. If you move the declarations of mattuse and bmattest to the top of the block (with vuluse and vulest), it should compile.
This behaviour was fixed in later versions of Stan, so you also shouldn’t receive this error if you update your rstan version