# selected data
years <- 1950:2006
death <- selectHMDdata("Japan", "Deaths", "Females",
ages = 80, years = years)
exposure <- selectHMDdata("Japan", "Exposures", "Females",
ages = 80, years = years)
# various fits
# default using Bayesian Information Criterion
fitBIC <- Mort1Dsmooth(x=years, y=death, offset=log(exposure))
fitBIC
summary(fitBIC)
# subjective choice of the smoothing parameter lambda
fitLAM <- Mort1Dsmooth(x=years, y=death, offset=log(exposure),
lambda=10000, method=3)
# plot
plot(years, log(death/exposure),
main="Mortality rates, log-scale. Japanese females, age 80, 1950:2006")
lines(years, log(fitted(fitBIC)/exposure), col=2, lwd=2)
lines(years, log(fitted(fitLAM)/exposure), col=3, lwd=2)
legend("topright", c("Actual", "BIC", "lambda=10000"),
col=1:3, lwd=c(1,2,2), lty=c(-1,1,1),
pch=c(1,-1,-1))
# about Extra-Poisson variation (overdispersion)
# checking the presence of overdispersion
fitBIC$psi2 # quite larger than 1
# fitting accounting for overdispersion
fitBICover <- Mort1Dsmooth(x=years, y=death, offset=log(exposure),
overdispersion=TRUE)
# difference in the selected smoothing parameters
fitBIC$lambda;fitBICover$lambda
# plotting both situations
plot(fitBICover)
lines(years, log(fitBIC$fitted) - fitBIC$offset, col=4, lwd=2, lty=2)Run the code above in your browser using DataLab