I am trying to fit a binomial model with Rstan. However, I keep getting the error message:
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
c++ exception (unknown reason)
The model is a binomial model with logic link. I want to find alpha and beta.
I suspect that the error came from that data is from binomial with different size. And I tried to correct it but failed. Here is my code:
data {vector[8] n;
vector[8] x;
vector[8] r;
}
parameters {
real alpha;
real beta;
}
model {
vector[8] p;
p = inv_logit(alpha + beta * x);
alpha ~ normal( 0.0, 100);
beta ~ normal( 0.0, 100);
r ~ binomial(n, p);
}
df <- list(x = c(1.69, 1.72, 1.75, 1.78, 1.81, 1.83, 1.86, 1.88),
n = c(59, 60, 62, 56, 63, 59, 62, 60),
r = c(6, 13, 18, 28, 52, 53, 61, 60))
fit <- stan(file =‘filename.stan’, data=df, iter=1000, chains=4)
It is a very simple model, And I think the syntax is correct. I tried to replace the model by a for loop since as I mentioned, each data has different size. But still get the same error.