Description

The CoDa R package contains the implementation of the Compositional Data Mortality Model (CoDa). This is a Lee-Carter (1992) type method that is used to modelling and forecasting the life table distribution of deaths (dx) using Principal Component Analysis. In the context of mortality forecasting the CoDa method was fist used in Bergeron-Boucher et al. (2017). The package includes functions for fitting the model, analysing it's goodness-of-fit and performing mortality projections.

Installation

  1. Make sure you have the most recent version of R
  2. Run the following code in your R console
install.packages("CoDa")

Updating to the latest version of the package

You can track and contribute to the development of CoDa on GitHub. To install it:

  1. Install the release version of devtools from CRAN with install.packages("devtools").

  2. Make sure you have a working development environment.

    • Windows: Install Rtools.
    • Mac: Install Xcode from the Mac App Store.
    • Linux: Install a compiler and various development libraries (details vary across different flavors of Linux).
  3. Install the development version of CoDa.

devtools::install_github("mpascariu/CoDa")

Help

All functions are documented in the standard way, which means that once you load the package using library(CoDa) you can just type ?coda to see the help file.

\newpage

Examples

library(CoDa)

Fit CoDa model

The model can be fitted using function coda and using a dataset containing mortality data (dx distributions) in for of a matrix or data.frame with ages as row and time as column. CoDa.data is an example of such a data set.

CoDa.data[1:5, 1:5]

CoDa.data is containing distribution of deaths for US female population between 1960 and 2014. The data is provided in the package for testing purposes only. By the time you are using it, it may be outdated. Download actual demographic data free of charge from Human Mortality Database. Once a username and a password is created on the website the MortalityLaws R package can be used to extract data directly into your R console.

M <- coda(data = CoDa.data, x = 0:110, y = 1960:2014)
M

Output objects

The output is an object of class coda with the components:

ls(M)

Summary

summary(M)

How to plot fitted parameters and fitted values of a CoDa mortality model

Two types of plots are available: "coef" to obtain representations of the three estimated series of parameters and "data" for visualising the input and fitted values.

plot(M, plotType = "coef", ylab = "values")
plot(M, plotType = "data")

Plot Residuals

Form the resulted deviance residuals, resid(M), three types of figures can be obtained. When plotType = "scatter" scatter plots of the residuals against age, calendar year and cohort (year of birth) are produced.

plot(resid(M), plotType = "scatter")

When plotType = "colourmap" a two dimensional colour map of the residuals is plotted. This is produced using function image.plot. See image.plot for further parameters that can be passed to this type of plots.

plot(resid(M), plotType = "colourmap")

When plotType = "signplot" a two dimensional black and white map of the residuals is plotted with dark grey representing negative residuals and light grey representing positive residuals. This is produced using function image.default.

plot(resid(M), plotType = "signplot")

Mortality projections

Mortality projections can be obtained using function predict. The example below shows how a 30 year mortality forcast is realised using the fitted coda model. For the computation of the jumpchoice there are two alternatives: actual (uses actual rates from final year) and fit (uses fitted rates).

P <- predict(M, h = 30, jumpchoice = 'actual')
P
# list of objects in predict
ls(P)

# Predicted distribution of death
head(P$predicted.values, 3)

References

  1. Bergeron-Boucher, M-P., Canudas-Romo, V., Oeppen, J. and Vaupel, W.J. 2017. Coherent forecasts of mortality with compositional data analysis. Demographic Research, Volume 17, Article 17, Pages 527--566.

  2. Oeppen, J. 2008. Coherent forecasting of multiple-decrement life tables: A test using Japanese cause of death data. Paper presented at the European Population Conference 2008, Barcelona, Spain, July 9-12, 2008.

  3. Aitchison, J. 1986. The Statistical Analysis of Compositional Data. London: Chapman and Hall. 2015.

  4. Ronald D. Lee and Lawrence R. Carter. 1992. Modeling and Forecasting U.S. Mortality, Journal of the American Statistical Association, 87:419, 659--671.

  5. Wikipedia. Compositional data



mpascariu/CoDa documentation built on May 5, 2019, 7 p.m.