Rstan parser error

Hi,

Recently when I tried to run one Stan code, the following error messages showed up:

Error in stanc(file = file, model_code = model_code, model_name = model_name, :
parser failed badly

May I ask about the possible reasons for that? ( I have tested the code before but no error happened in the past)

Thanks a lot.

Hi -

Are you able to share the Stan code which caused this error?

Hello,

I am also experiencing the same problem. My script was working fine until suddenly I started receiving the same error. Any Idea on how to solve the problem?

Error in stanc(file = file, model_code = model_code, model_name = model_name, :
parser failed badly

Are you able to share the Stan code you are using?

stancode:
data {
int<lower=2> K;
int<lower=0> N;
int<lower=1> D;
int<lower=1,upper=K> y[N];
row_vector[D] x[N];
}

parameters {
vector[D] beta;
ordered[K-1] c;
}

model {
beta ~ normal(0,10);
c ~ normal(0,10);
for (n in 1:N)
y[n] ~ ordered_logistic(x[n] * beta, c); //only intercept parameters
}

generated quantities{
vector[N] log_lik; //log-likelihood values

for (i in 1:N)
log_lik[i] = ordered_logistic_lpmf(y[i] | x[i] * beta, c);

#int<lower=1,upper=K> y_pred[N];

#for (i in 1:N)
  #y_pred[i] = ordered_logistic_rng(x[i] * beta, c); 

}

r code
K = length(unique(ytr))
N = length(ytr)
x_data = as.data.frame(tr[,c(-1,-5)])
x = model.matrix(~ ., x_data) #design matrix
D=ncol(x)
library(rstan) #to fit models with Stan
my_data = list( K = K, N = N, y = ytr, x = x,D=D) # data to be passed to Stan

fit1 = stan(file = ‘Trolley22.stan’, data = my_data) #fit the model

Rstan has a known bug to do with the # character, if you replace all comments with the // style, does the problem still occur?

Thanks, It worked

1 Like