Parser error when running "birats" example in rstan

When running the birats demo in rstan, the parser seems to have an error with the model syntax.

However, looking at this page (5.6 Array data types | Stan Reference Manual), the syntax looks correct to me. Any thoughts on what may be going on?

Input

> rstan::stan_demo("birats")

Output

> N <-
+ 30

> T <-
+ 5

> y <-
+ structure(c(151, 145, 147, 155, 135, 159, 141, 159, 177, 134, 
+ 160, 143, 154, 171, 163, 160, 142, 156, 157, 152, 154, 139, 146, 
+ 157, 132 .... [TRUNCATED] 

> x <- c(8.0, 15.0, 22.0, 29.0, 36.0)

> xbar <- 22

> Omega <- 
+ structure(c(0.005, 0, 0, 5), .Dim = c(2, 2)) 
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
 error in 'model105ba1a71abb3_birats' at line 8, column 2
  -------------------------------------------------
     6:   int<lower=0> N;
     7:   int<lower=0> T;
     8:   array[T] real x;
         ^
     9:   real xbar;
  -------------------------------------------------

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(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'birats' due to the above error.

System Info

> packageVersion("rstan")  
[1] β€˜2.21.7’
─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.1 (2022-06-23)
 os       macOS Monterey 12.6.1
 system   x86_64, darwin17.0
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Chicago
 date     2022-11-03
 rstudio  2022.07.2+576 Spotted Wakerobin (desktop)
 pandoc   2.19.2 @ /usr/local/bin/pandoc

The version of rstan on cran is outdated and doesn’t support the array syntax, you’ll need to install the preview of the next version:

 # run the next line if you already have rstan installed
# remove.packages(c("StanHeaders", "rstan"))

install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
1 Like