# selected data
ages <- 50:100
years <- 1950:2006
death <- selectHMDdata("Japan", "Deaths", "Females",
ages = ages, years = years)
exposure <- selectHMDdata("Japan", "Exposures", "Females",
ages = ages, years = years)
# fit with BIC
fitBIC <- Mort2Dsmooth(x=ages, y=years, Z=death, offset=log(exposure))
fitBIC
summary(fitBIC)
# plot age 50 log death rates (1st row)
plot(years, log(death[1,]/exposure[1,]),
main="Mortality rates, log-scale. Japanese females, age 50, 1950:2006")
lines(years, log(fitted(fitBIC)[1,]/exposure[1,]), col=2, lwd=2)
# plot over age and years fitted log death rates from fitBIC
grid. <- expand.grid(list(ages=ages, years=years))
grid.$lmx <- c(log(fitted(fitBIC)/exposure))
levelplot(lmx ~ years * ages , grid.,
at=quantile(grid.$lmx, seq(0,1,length=10)),
col.regions=rainbow(9))
# about Extra-Poisson variation (overdispersion)
# checking the presence of overdispersion
fitBIC$psi2
# fitting accounting for overdispersion
fitBICover <- Mort2Dsmooth(x=ages, y=years, Z=death,
offset=log(exposure),
overdispersion=TRUE)
# difference in the selected smoothing parameters
fitBIC$lambdas;fitBICover$lambdasRun the code above in your browser using DataLab