Hi all,
I am trying to implement and copy the model in the example ‘1.5 Ache Hunting with Age Trends’ from the book Bayesian Ideas and Data Analysis (Christensen et al., 2010). I have attached the relevant example pages from the book and the dataset used.
1.5 Ache Hunting with Age Trends.pdf (2.3 MB)
Exercise 1.5.csv (528 Bytes)
Some of the warning messages I am getting is below:
- There were 2963 divergent transitions after warmup.
- There were 2381 transitions after warmup that exceeded the maximum treedepth.
- There were 1 chains where the estimated Bayesian Fraction of Missing Information was low.
The rstan code to fit the model is:
stan(file=‘Exercise 1.5.stan’, data=data, chains=4, iter=6000, warmup=2000, thin=1, cores=4,
control=list(adapt_delta=0.99, max_treedepth=15))
I suspect that the issue may be relating to my Stan codes. Can someone please explain to me what I might be doing wrong? And what I can do to fix this?
The Stan codes are:
data {
int<lower=1> N;
vector<lower=0>[N] age;
int<lower=0> kills[N];
}
transformed data {
real mu_age = mean(age);
vector[N] ones = rep_vector(1, N);
vector[N] age_centred = age - mu_age;
vector[N] age_centred_squared = square(age_centred);
matrix[N, 3] X;
X = append_col(ones, append_col(age_centred, age_centred_squared));
}
parameters {
vector[3] beta;
real error;
real<lower=0> sigma_squared;
}
transformed parameters {
real<lower=0> sigma = sqrt(sigma_squared);
}
model {
// priors
beta ~ normal(0, 1000);
sigma_squared ~ inv_gamma(0.001, 0.001);
error ~ normal(0, sigma);
// likelihood
kills ~ poisson_log(X*beta + error);
}
Many thanks.