stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.02k stars 264 forks source link

Hi, I got a parsing error when running the rats_fit code. #1038

Closed Shwoobly closed 1 year ago

Shwoobly commented 1 year ago

Hi, I got a parsing error when running the rats_fit code. The 8 schools example worked just fine. Using a Macbook M2.

STEPS FOLLOWED

y <- as.matrix(read.table('rats.txt', header = TRUE)) x <- c(8, 15, 22, 29, 36) xbar <- mean(x) N <- nrow(y) T <- ncol(y) rats_fit <- stan(file='rats.stan', data = list(N=N, T=T, y=y, x=x, xbar=xbar))

OUTPUT

PARSER FAILED TO PARSE INPUT COMPLETELY STOPPED AT LINE 1: / http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/Vol1.pdf // Page 3: Rats data { int N; int T; array[T] real x; array[N, T] real y; real xbar; } parameters { array[N] real alpha; array[N] real beta;

real mu_alpha; real mu_beta; // beta.c in original bugs model

real sigmasq_y; real sigmasq_alpha; real sigmasq_beta; } transformed parameters { real sigma_y; // sigma in original bugs model real sigma_alpha; real sigma_beta;

sigma_y = sqrt(sigmasq_y); sigma_alpha = sqrt(sigmasq_alpha); sigma_beta = sqrt(sigmasq_beta); } model { mu_alpha ~ normal(0, 100); mu_beta ~ normal(0, 100); sigmasq_y ~ inv_gamma(0.001, 0.001); sigmasq_alpha ~ inv_gamma(0.001, 0.001); sigmasq_beta ~ inv_gamma(0.001, 0.001); alpha ~ normal(mu_alpha, sigma_alpha); // vectorized beta ~ normal(mu_beta, sigma_beta); // vectorized for (n in 1 : N) { for (t in 1 : T) { y[n, t] ~ normal(alpha[n] + beta[n] (x[t] - xbar), sigma_y); } } } generated quantities { real alpha0; alpha0 = mu_alpha - xbar mu_beta; }

Error in stanc(file = file, model_code = model_code, model_name = model_name, : failed to parse Stan model 'rats' due to the above error.

Originally posted by @Shwoobly in https://github.com/stan-dev/rstan/issues/204#issuecomment-1435154455

bob-carpenter commented 1 year ago

If your file rats.stan starts with a single forward slash, that's the problem. Comments start with two slashes.

andrjohns commented 1 year ago

Closing this issue as appears resolved