# selected data
years <- 1980:2006
ages <- 80:100
death <- selectHMDdata("Denmark", "Deaths", "Females",
ages = ages, years = years)
exposure <- selectHMDdata("Denmark", "Exposures", "Females",
ages = ages, years = years)
# fit
fit <- Mort2Dsmooth(x=ages, y=years, Z=death, offset=log(exposure),
method=3, lambdas=c(100,500))
# predict and computing standard errors
pre <- predict(fit, se.fit=TRUE)
# plotting over ages and years
# !hard to distinguish between upper and lower confidence bounds
grid. <- expand.grid(x = ages, y = years, gr = 1:2)
grid.$lmx <- c(c(pre$fit - 2*pre$se.fit), c(pre$fit + 2*pre$se.fit))
wireframe(lmx ~ x * y, data = grid., groups = gr,
scales = list(arrows = FALSE),
drape = TRUE, colorkey = TRUE)
# plotting age 90
plot(years, log(death[11,] / exposure[11,]),
main="Mortality rates, log-scale. Danish females, age 90, 1980:2006")
lines(years, pre$fit[11,], lwd=2, col=2)
lines(years, pre$fit[11,] + 2*pre$se.fit[11,], lwd=2, col=2, lty=2)
lines(years, pre$fit[11,] - 2*pre$se.fit[11,], lwd=2, col=2, lty=2)
# compute log-death rates for each calendar month and calendar ages
newyears12 <- seq(1990, 2000, length=11*11)
newages12 <- seq(90, 100, length=11*11)
newdata12 <- list(x=newages12, y=newyears12)
pre12 <- predict(fit, newdata=newdata12, se.fit=TRUE)
# death rates in June 1995 at age 95.5
which.age <- which(newages12==95.5)
which.year <- which(newyears12==1995.5)
exp(pre12$fit[which.age, which.year] +
c(-2*pre12$se.fit[which.age, which.year], 0, 2*pre12$se.fit[which.age, which.year]))Run the code above in your browser using DataLab