Bayesian Age-Period-Cohort Modeling

Volker Schmid

2022-05-04

Data example

BAMP includes a data example.

data(apc)
plot(cases[,1],type="l",ylim=range(cases), ylab="cases", xlab="year", main="cases per age group")
for (i in 2:8)lines(cases[,i], col=i)

APC model with random walk first order prior

model1 <- bamp(cases, population, age="rw1", period="rw1", cohort="rw1",
              periods_per_agegroup = 5)

bamp() automatically performs a check for MCMC convergence using Gelman and Rubin’s convergence diagnostic. We can manually check the convergence again:

checkConvergence(model1)
## [1] TRUE

Now we have a look at the model results. This includes estimates of smoothing parameters and deviance and DIC:

print(model1)
## 
##  Model:
## age (rw1)  - period (rw1)  - cohort (rw1) model
## Deviance:     231.28
## pD:            37.06
## DIC:          268.34
## 
## 
##  Hyper parameters:                 5%           50%          95%         
## age                              0.356        0.924        1.867
## period                          72.116      203.812      629.495
## cohort                          34.051       58.293       96.889
## 
## 
## Markov Chains convergence checked succesfully using Gelman's R (potential scale reduction factor).

We can plot the main APC effects using point-wise quantiles:

plot(model1)

More quantiles are possible:

plot(model1, quantiles = c(0.025,0.1,0.5,0.9,0.975))

APC model with random walk second order prior

model2 <- bamp(cases, population, age="rw2", period="rw2", cohort="rw2",
              periods_per_agegroup = 5,
              mcmc.options=list("number_of_iterations"=200000, "burn_in"=100000, "step"=50, "tuning"=500),
              hyperpar=list("age"=c(1,.5), "period"=c(1,0.05), "cohort"=c(1,0.05)))
checkConvergence(model2)
## [1] TRUE
print(model2)
## 
##  Model:
## age (rw2)  - period (rw2)  - cohort (rw2) model
## Deviance:     234.09
## pD:            36.81
## DIC:          270.90
## 
## 
##  Hyper parameters:                 5%           50%          95%         
## age                              1.015        2.899        6.692
## period                          16.330       41.813       91.706
## cohort                          22.907       44.777       81.587
## 
## 
## Markov Chains convergence checked succesfully using Gelman's R (potential scale reduction factor).
plot(model2)

model3<-bamp(cases, population, age="rw1", period=" ", cohort="rw2",
              periods_per_agegroup = 5)
checkConvergence(model3)
## [1] TRUE
print(model3)
## 
##  Model:
## age (rw1) cohort (rw2) model
## Deviance:     276.43
## pD:            30.10
## DIC:          306.53
## 
## 
##  Hyper parameters:                 5%           50%          95%         
## age                              0.282        0.717        1.551
## cohort                          38.109       73.131      138.938
## 
## 
## Markov Chains convergence checked succesfully using Gelman's R (potential scale reduction factor).
plot(model3)

(model4<-bamp(cases, population, age="rw1", period="rw1", cohort="rw1",
             cohort_covariate = cov_c, periods_per_agegroup = 5))
## 
## Automatic check procedure removed 1 Markov chain. Please check for convergence using checkConvergence() and maybe change your model settings (maybe add overdispersion).
## Warning: MCMC chains did not converge!
## 
## WARNING! Markov Chains have apparently not converged! DO NOT TRUST THIS MODEL!
## 
##  Model:
## age (rw1)  - period (rw1)  - cohort (rw1) model
## Deviance:     231.36
## pD:            37.00
## DIC:          268.36
## 
## 
##  Hyper parameters:                 5%           50%          95%         
## age                              0.371        0.911        1.904
## period                          71.547      206.518      624.107
## cohort                          34.780       58.995       97.845
plot(model4)

(model5<-bamp(cases, population, age="rw1", period="rw1", cohort="rw1",
             period_covariate = cov_p, periods_per_agegroup = 5))
## 
##  Model:
## age (rw1)  - period (rw1)  - cohort (rw1) model
## Deviance:     231.41
## pD:            37.12
## DIC:          268.53
## 
## 
##  Hyper parameters:                 5%           50%          95%         
## age                              0.353        0.929        1.957
## period                          67.288      197.167      580.384
## cohort                          34.913       59.087       97.280
## 
## 
## Markov Chains convergence checked succesfully using Gelman's R (potential scale reduction factor).
plot(model5)