I have the following dataset -
d = data.frame(year=1976:1985,
fatal_accidents = c(24,25,31,31,22,21,26,20,16,22),
passenger_deaths = c(734,516,754,877,814,362,764,809,223,1066),
death_rate = c(0.19,0.12,0.15,0.16,0.14,0.06,0.13,0.13,0.03,0.15))
d$miles_flown = d$passenger_deaths/d$death_rate
I'd like to hierarchically model the passenger deaths($Y_{i}$) using a Poisson distribution with the parameter consisting of miles_flown ($x_{i}$), i.e - $Y_{i} = Poisson(x_{i}\lambda_{i})$
Given the above information, my mid-level model follows a Gamma distribution ($Gamma(\alpha, \beta)$), since it is conjugate to the Poisson.
In order to model, my $\alpha$ and $\beta$, I decided to use a uniform distribution, i.e - $\alpha \sim Uniform(0, a_{0})$ $\beta \sim Uniform(0, b_{0})$,
wherein I decided to manually pick $a_{0}, b_{0}$ values. Here is my Stan code -
library("rstan")
set.seed(8889)
model_default_prior = "
data {
int<lower=0> N;
vector[N] miles_flown;
int<lower=0> fatal_accidents[N];
}
parameters {
real<lower=0> lambda[N];
real<lower=0> alpha;
real<lower=0> beta;
}
model {
// Uninformative prior
alpha ~ uniform(0, 100);
beta ~ uniform(0, 100);
// implicit joint distributions
lambda ~ gamma(alpha,beta);
fatal_accidents~poisson(lambda);
}
"
d.dat = list(fatal_accidents = d$fatal_accidents, miles_flown = d$miles_flown, N = nrow(d))
m = stan_model(model_code=model_default_prior)
r.d = sampling(m, d.dat, c("alpha","beta","lambda"), iter=10000, control = list(adapt_delta = 0.9))
r.d
However, after running the above code, I am running into 14372 divergent transitions. This seems like I have made some serious error with my code or model.