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.