Parser failed to parse input completely stopped at line 93:

I am not sure why I get this error message:

PARSER FAILED TO PARSE INPUT COMPLETELY*
STOPPED AT LINE 93:
}
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model ‘noncov2’ due to the above error.

My rstan codes are as follows:


// Our model is:

// Level 1
// y_ti | pi_0i, pi_1i, pi_2i, sigma ~ normal(pi_0i + pi_1i(Tti) + pi_2i(Tti)^2, SIGMA^2) Capital sigma for the overall one;
// pi_0i | beta00, sigma00 ~ normal(beta00, sigma00^2)
// pi_1i | beta10, sigma01 ~ normal(beta10, sigma10^2)
// pi_2i | beta20, sigma02 ~ normal(beta20, sigma20^2)
// sigma^2 ~ inv_gamma(nu/2, nu * lambda/2)

// Level 2
// beta00 ~ N(mu_beta00, tau00^2)
// beta10 ~ N(mu_beta10, tau10^2)
// beta20 ~ N(mu_beta20, tau20^2)


data {
  int<lower = 0> n; // number of data points
  int<lower = 1> i; // number of individuals as cluster
  vector[n] y; // outcome
  vector[n] t; // time
  vector[n] t2; // time^2
  real mu_beta00; // prior mean for intercept 
  real<lower = 0> tau00; // prior sd for intercept 
  real mu_beta10; // prior mean for slope1 
  real<lower = 0> tau10; // prior sd for slope1 
  real mu_beta20; // prior mean for slope2 
  real<lower = 0> tau20; // prior sd for slope2 
  real<lower = 0> nu; // for the prior shape parameter for std_sigma^
  real<lower = 0> lambda; // for the prior rate for std_sigma^2

  int<lower = 1, upper = i> child[n];      // student id
}

// The model parameters: Stan will sample from the posterior of all things declared here
parameters {

  vector[i] pi_0i_aux;
  vector[i] pi_1i_aux;
  vector[i] pi_2i_aux;
  real beta00;
  real beta10;
  real beta20;
  real<lower = 0> SIGMA2;
  real<lower = 0> sigma00;
  real<lower = 0> sigma10;
  real<lower = 0> sigma20;
}

// the transformed parameters block
transformed parameters{
  vector[n] MU;
  real<lower = 0> SIGMA;
  vector[i] pi_0i;
  vector[i] pi_1i;
  vector[i] pi_2i;

  SIGMA = sqrt(SIGMA2);
  
  pi_0i = beta00 + sigma00*pi_0i_aux;
  pi_1i = beta10 + sigma10*pi_1i_aux;
  pi_2i = beta20 + sigma20*pi_2i_aux;
  
  for(h in 1:n){
  MU[h] = pi_0i[child[h]] + pi_1i[child[h]]*t[h] + pi_2i[child[h]]*t2[h];
  }
}

// The actual statistical model
model {
  // level 1
  SIGMA2 ~ inv_gamma(0.5 * nu, 0.5 * nu * lambda);
  
  for (k in 1:i){
  pi_0i_aux[k] ~ normal(beta00, sigma00); 
  pi_1i_aux[k] ~ normal(beta10, sigma10);
  pi_2i_aux[k] ~ normal(beta20, sigma20);
  }
  
  // level 2
  beta00 ~ normal(mu_beta00, tau00);
  beta10 ~ normal(mu_beta10, tau10);
  beta20 ~ normal(mu_beta20, tau20);
  
  sigma00 ~ cauchy(0, 5);
  sigma10 ~ cauchy(0, 5);
  sigma20 ~ cauchy(0, 5);
  
  //outcome
  y ~ normal(MU, SIGMA);
  
  }
  
}


I am not sure whether there is anything wrong with my models. Many thanks!

There’s an unpaired closing brace } on line 91. (Maybe a remnant of a for-loop that’s been vectorized?)

1 Like