Parse error in replicating the example from user guide section 1.9

Trying to replicate the example of hierarchical logistic model in section 1.9 of the user guide : 1.9 Hierarchical logistic regression | Stan User’s Guide (
A parse error appeared when I tried to compile the original example code.

data {
  int<lower=1> D;
  int<lower=0> N;
  int<lower=1> L;
  array[N] int<lower=0, upper=1> y;
  array[N] int<lower=1, upper=L> ll;
  array[N] row_vector[D] x;
parameters {
  array[D] real mu;
  array[D] real<lower=0> sigma;
  array[L] vector[D] beta;
model {
  for (d in 1:D) {
    mu[d] ~ normal(0, 100);
    for (l in 1:L) {
      beta[l, d] ~ normal(mu[d], sigma[d]);
  for (n in 1:N) {
    y[n] ~ bernoulli(inv_logit(x[n] * beta[ll[n]]));

error in ‘model1de0632d175f_test’ at line 17, column 2

15:   int<lower=0> N;
16:   int<lower=1> L;
17:   array[N] int<lower=0, upper=1> y;
18:   array[N] int<lower=1, upper=L> ll;

Here is the error message:

PARSER EXPECTED: <one of the following:
a variable declaration, beginning with type,
(int, real, vector, row_vector, matrix, unit_vector,
simplex, ordered, positive_ordered,
corr_matrix, cov_matrix,
cholesky_corr, cholesky_cov
or ‘}’ to close variable declarations>
Error in stanc(filename, allow_undefined = TRUE) :
failed to parse Stan model ‘test’ due to the above error.

If your question relates to installation please provide the following information:

  • Operating System
  • RStan Version
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
  • Output of devtools::session_info("rstan")

It seems the array declaration was not recognized. Since the model code itself was directly copied from the user guide without any change, the code should be validated. Therefore I suppose there could be something wrong with my rstan setup and configuration. I have tried diagnostics on the start guide, and uninstall and reinstall rstan but made no progress.

This is because the version of Stan available in RStan is unfortunately slightly outdated. Try the examples from the older version of the guide instead: 1.9 Hierarchical Logistic Regression | Stan User’s Guide

1 Like

Oh I completely overlooked the stan version! Thank you very much!