I was going to do a simple poisson GLM for my class, but got a warning (and a c++ error…later perhaps). So I tried the simplest poisson model to investigate. No c++ error, but I get a warning. Can you help me to get rid of this?
Thanks,
Jay
First, some info:
I’m using RStan 2.16.2 (stan 2.16.0) on an iMac running Sierra (10.12.6).
To be sure, I don’t get the c++ error with this simple code. But, below is a very simple Poisson GLM that does give the c++ error. (I checked the data (lung cancer and radon data) …okay…runs in R’s glm fine…)
…i omitted the lower bound on the linear predictor variable (I was trying y ~ poisson and got the same c++ exception and thought y~ poisson_log might help but forgot to change lower bound…still get the same c++ exception
This is a bug in the Mac binary for rstan on CRAN. It doesn’t give you the full output from Stan’s parser. I believe this is fixed for the next release (coming soon). It’s definitely a problem when trying to debug models! For the time being you can get the full parser output on Mac by installing rstan from source instead of binary (you can add type="source" when calling install.packages).
In this particular case the full error message you received should have been
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
require unconstrained. found range constraint.
error in 'model_test' at line 12, column 25
-------------------------------------------------
10: }
11: model {
12: real<lower=0> lnmu [N];
^
13: lnmu = offsetlnE + b0 + b1 * x;
-------------------------------------------------
which is telling you that it wants you to remove the lower=0 constraint in the model block. You can put constraints on parameters but not on intermediate quantities computed from those parameters in the model block. But in this case I don’t think lnmu even needs to be positive since you’re using poisson_log (instead of just poisson). poisson_log accepts in input on the log scale and exponentiates for you so you don’t need the argument to poisson_log to be positive.
data {
int<lower=1> N;
int<lower=0> y[N];
vector<lower=0>[N] offsetlnE; // changed from real array to vector
vector<lower=0>[N] x; // changed from real array to vector
}
and then your model block to
model {
vector[N] lnmu = offsetlnE + b0 + b1 * x;
y ~ poisson_log(lnmu);
}
Using vectors instead of real arrays for offsetlnE and x lets you do multiplication and addition the way you want. If you kept the arrays you’d have to loop.