Sampling error with hierarchical model


I am trying to fit a hierarchical model to (log) count data, modelling the logcounts as gaussians, using MatlabStan. I extended the model from the 8 schools example.
For some runs of the model I get the error “- is either mistyped or misplaced”, apparently after the compilation stage. I’m not sure what this refers to. Weirdly the error seems to be data dependent, it runs fine for some dataset but then crashes for others. Any help would be much appreciated, I’m kind of lost as to how to debug this.

Stan is sampling with 4 chains…
output-1.csv: - is either mistyped or misplaced.
output-1.csv: Failed to parse arguments, terminating Stan
Warning: Stan seems to have exited badly.
In StanFit/process_exit_failure (line 290)
In StanFit/process_exit (line 170)
In StanFit>@(src,evnt)process_exit(self,src,evnt)
In processState/set.exitValue (line 30)
In processManager.pollTimerStop (line 508)
In timer/timercb (line 34)
In timercb (line 24)
In timer/start (line 33)
In processManager/start (line 403)
In StanModel/sampling (line 768)
In stan (line 138)

data {
   int<lower=0> J; // number of regions
   int<lower=0> G; // number of groups
   int<lower=0> T; // number of parameters (J x G)
   int<lower=0> M; // number of measurements
   int<lower=1> regionid[M]; // vector of region indices
   int<lower=1> groupid[M]; // vector of group indices
   real y[M]; // logcounts for each region
parameters {
    real<lower=1,upper=3.5>  mu; // mean of logcounts across all regions (across groups)
    real<lower=0> tau; // spread of mean logcounts across all regions (across groups)
   real<lower=1,upper=3.5>  mupergroup[J]; // mean of logcounts across groups
   real<lower=0> taupergroup[J]; // spread of mean logcounts across groups
   real eta[T]; // shifted mean cell counts per region
   real<lower=0> sigma; // sampling variability of log counts
transformed parameters {
    real<lower=-10,upper=10> theta[T];
    for (j in 1:J)
    for (g in 1:G)
    theta[j+(g-1)*J] = mupergroup[j] + taupergroup[j] * eta[j+(g-1)*J];
model {
   mu ~ normal(2.3,1);
   mupergroup ~ normal(2.3,2);
   eta ~ normal(0, 1);
   sigma ~ cauchy(0,1);
   tau ~ cauchy(0,0.5);
   taupergroup ~ cauchy(0,0.5);
   for (i in 1:M)
   y[i] ~ normal(theta[regionid[i] + (groupid[i]-1)*J], sigma); // observed data


this looks like a possible bug in MatlabStan - the errors seem to be connected to the way input/output files are encoded. It is possible that the format has changed over time and MatlabStan is not in sync with the latest version. Since MatlabStan is not supported by the core Stan team and seems to not be actively maintained, you either have to hunt the bug down yourself or try using older version of CmdStan with Matlab.