I want to fit a quasipoisson model using stan, the code is as follows. R showed an error at the line
target += poisson_log_lpdf(y[i] | lambda[i] + X[i,]*beta);
Could anyone give some suggestions on the code? Thank you!
stan.code<-“
data {
int<lower=0> N;
int<lower=0> k;
matrix[N, k] X;
real y[N];
}
parameters {
vector[k] beta;
vector[N] lambda;
real<lower=0> tau;
}
transformed parameters {
real<lower=0> sigma;
sigma = 1.0 / sqrt(tau);
}
model {
target += cauchy_lpdf(tau | 0, 5);
target += normal_lpdf(beta | 0, 10);
for (i in 1:N) {
target += normal_lpdf(lambda[i] | 0, sigma);
target += poisson_log_lpdf(y[i] | lambda[i] + X[i,]*beta);
}
}”