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)
plot of chunk loadplot
bamp() automatically performs a check for MCMC convergence using Gelman and Rubin’s convergence diagnostic. We can manually check the convergence again:
## [1] TRUE
Now we have a look at the model results. This includes estimates of smoothing parameters and deviance and DIC:
##
## Model:
## age (rw1) - period (rw1) - cohort (rw1) model
## Deviance: 231.03
## pD: 36.69
## DIC: 267.73
##
##
## Hyper parameters: 5% 50% 95%
## age 0.404 1.047 2.236
## period 68.994 200.213 607.918
## cohort 34.270 59.168 97.495
We can plot the main APC effects using point-wise quantiles:
More quantiles are possible:
## [1] TRUE
##
## Model:
## age (rw2) - period (rw2) - cohort (rw2) model
## Deviance: 246.32
## pD: 33.69
## DIC: 280.01
##
##
## Hyper parameters: 5% 50% 95%
## age 2.014 6.246 16.696
## period 55.490 307.804 2827.581
## cohort 37.044 74.924 146.403
model3<-bamp(cases, population, age="rw1", period=" ", cohort="rw2",
periods_per_agegroup = 5)
checkConvergence(model3)
## [1] TRUE
##
## Model:
## age (rw1) cohort (rw2) model
## Deviance: 276.60
## pD: 29.99
## DIC: 306.59
##
##
## Hyper parameters: 5% 50% 95%
## age 0.301 0.797 1.644
## cohort 38.018 74.193 139.638
(model4<-bamp(cases, population, age="rw1", period="rw1", cohort="rw1",
cohort_covariate = cov_c, periods_per_agegroup = 5))
##
## Model:
## age (rw1) - period (rw1) - cohort (rw1) model
## Deviance: 231.32
## pD: 36.92
## DIC: 268.25
##
##
## Hyper parameters: 5% 50% 95%
## age 0.406 1.040 2.252
## period 65.700 196.123 626.652
## cohort 34.013 59.356 97.958
(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.22
## pD: 36.81
## DIC: 268.04
##
##
## Hyper parameters: 5% 50% 95%
## age 0.394 1.039 2.197
## period 66.652 195.959 625.782
## cohort 34.518 59.524 98.195