Dear all,
I hope this message finds you well. I have been using Stan for sometime now and its quite fun. I have implemented an ICAR model inspired by Prof. Mitzi Morris’ tutorial [HERE]
functions {
real icar_normal_lpdf(vector phi, int N, array[] int node1, array[] int node2) {
return -0.5 * dot_self(phi[node1] - phi[node2]);
}
}
data {
int<lower=0> N;
int<lower=0> N_edges;
array[N_edges] int<lower=1, upper=N> node1;
array[N_edges] int<lower=1, upper=N> node2;
array[N] int<lower=0> Y;
vector<lower=0>[N] E;
}
transformed data {
vector[N] log_exposure = log(E);
}
parameters {
real alpha;
real<lower=0> sigma;
vector[N] phi;
}
model {
phi ~ icar_normal(N, node1, node2);
Y ~ poisson_log(log_exposure + alpha + phi*sigma);
alpha ~ normal(0.0, 1.0);
sigma ~ normal(0.0, 1.0);
sum(phi) ~ normal(0, 0.001*N);
}
generated quantities {
vector[N] eta = alpha + phi*sigma;
vector[N] mu = exp(eta);
}
The above code works perfectly on one of my machines (i.e., Mac-mini). However, I am using the same code on a different computer (i.e., MacBook pro) and I get this confusing “parser expected” warning in the function line.
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
error in 'model1443186a5e0b_icar_poisson_model' at line 2, column 43
-------------------------------------------------
1: functions {
2: real icar_normal_lpdf(vector phi, int N, array[] int node1, array[] int node2) {
^
3: return -0.5 * dot_self(phi[node1] - phi[node2]);
-------------------------------------------------
PARSER EXPECTED: <argument declaration or close paren ) to end argument declarations>
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model 'icar_poisson_model' due to the above error.
I am having difficulties overcoming this issue on my MacBook Pro. Also, I don’t understand why don’t get this ‘parser’ problem on one of my computer, but it appearing in another machine. I am developing a practical session of an MSc module and I can imagine different students writing the same code but this parser warning appearing on different machines.
Any help or solutions will be appreciated. Thank you.
Anwar.