Response to Computation: 2.11.13 in RStan
Published in
1 min readOct 30, 2019
Following the structure of This, we will construct a model for part c) for 2.11.13 in Bayesian Data Analysis 3rd Edition by Andrew Gelman, John B. Carlin, Hal S. Stern, etc. Where instead of fatal accidents we will use passenger deaths.
so where ever we see FatAcc we will change it to Deaths.
```{r}
accidents$MilesE12 = 1e8 * accidents$Deaths / accidents$Rate / 1e12
``````{stan output.var="expmodel"}
data {
int<lower=0> N;
int<lower=0> Deaths[N];
real<lower=0> MilesE12[N];
real<lower=0> MilesE12new;
}
parameters {
real<lower=0> theta;
}
model {
theta ~ gamma(25.55, 1.07);
for(n in 1:N)
Deaths[n] ~ poisson(MilesE12[n]*theta);
}
generated quantities {
int<lower=0> DeathsPred;
DeathsPred = poisson_rng(MilesE12new*theta);
}
```
Fitting our model
```{r}
expfit = sampling(expmodel, data=list(
N = nrow(accidents), Deaths = accidents$Deaths,
MilesE12 = accidents$MilesE12, MilesE12new = 8e11/1e12
))```
and reading off our 95% predictive interval as (761.98, 881.00)