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.
install.packages("CoDa")
You can track and contribute to the development of CoDa
on GitHub. To install it:
Install the release version of devtools
from CRAN with install.packages("devtools")
.
Make sure you have a working development environment.
Xcode
from the Mac App Store.Install the development version of CoDa
.
devtools::install_github("mpascariu/CoDa")
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
library(CoDa)
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
The output is an object of class coda
with the components:
input
-- List with arguments provided in input. Saved for convenience;call
-- The unevaluated expression of the defined coda function.coefficients
-- Estimated coefficients;fitted
-- Fitted values of the estimated CoDa model;residuals
-- Deviance residuals;x
-- Vector of ages used in the fitting;y
-- Vector of years used in the fitting;ls(M)
summary(M)
CoDa
mortality modelTwo 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")
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 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)
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.
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.
Aitchison, J. 1986. The Statistical Analysis of Compositional Data. London: Chapman and Hall. 2015.
Ronald D. Lee and Lawrence R. Carter. 1992. Modeling and Forecasting U.S. Mortality, Journal of the American Statistical Association, 87:419, 659--671.
Wikipedia. Compositional data
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.