I have a model named Model2.stan that I think is correct, because I do not have any error when running with rstan:
stan_model(file=“Model2.stan”)
But when I try to fit my model, I have an error: PARSER FAILED TO PARSE INPUT COMPLETELY
STOPPED AT LINE 1
I am new in stan this is my first model, and I really do not understand this error. It seems that it should be a problem with my input data, maybe the data specified in R do not have the good format. In particular I should specify arrays of integers. I tried several syntax in R without any success. Following is the model, the specified data and the fitting command which ends with an error.
The model:
//
// The input data:
// 'n0' an array of integers,
// 'n' an array if integers,
// 'n0' and 'n' of length 'N'.
data {
int<lower=1> N;
int<lower=0> n0[N];
int<lower=0> n[N];
}
// The parameters of the model.
parameters {
vector<lower=0>[N] lambda;
}
// Transformed parameters. Here theta and delta calculated from lambda
transformed parameters {
vector[N] theta;
vector[N] delta;
// real delta[N];
theta = cumulative_sum(lambda);
delta = exp(-theta);
}
// The model to be estimated.
model {
vector[N] logitlambda;
real temp;
logitlambda = logit(lambda);
// prior
for (i in 1:61){
logitlambda[i] ~ normal(0, 1000);
}
temp ~ normal(0, 1000);
for (i in 62:N){
logitlambda[i] = temp;
}
n0 ~ binomial(n,delta);
}
The data specified in R:
n0 <- array(as.integer(c(6,4,5,6,6,1,6,4,8,1,6,9,5,8,10,7,10,7,22,11,22,52,34,22,23,22,30,31,30,32,34,34,39,17,27,24,26,40,16,22,22,30,25,21,20,22,24,22,22,21,26,27,10,22,14,17,16,11,23,5,25,33,9,16,7,13,8,6,3,9,11,13,4,5,4,8,1,5,4,0,3,6,1,0,2,1,0,0,1,0,0,1,0,0,1)))
n <- array(as.integer(c(6,4,5,6,6,1,6,4,8,1,6,9,5,8,1,7,10,7,22,11,22,52,34,22,23,22,30,31,30,32,34,34,39,17,27,24,26,40,16,22,22,30,25,21,20,22,24,22,22,21,26,27,10,22,14,17,16,11,23,5,25,33,9,16,7,13,8,6,3,9,11,13,4,5,4,8,1,5,4,0,3,6,1,0,2,1,0,0,1,0,0,1,0,0,1)))
dat = list(
N = length(n0),
n0 = n0,
n = n
)
And the fitting ending with an error:
fit = stan(
model_code = "Model2.stan",
data = dat,
iter = 200,
warmup = 100,
chains = 4,
seed=4938483
)
Any help would be greatly appreciated, because this is my first modeling with stan and I’m starting to get discouraged (I had problems specifying my model too).