Package 'LifeTables'

Title: Two-Parameter HMD Model Life Table System
Description: Functions supplied in this package will implement discriminant analysis to select an appropriate life table family, select an appropriate alpha level based on a desired life expectancy at birth, produce a model mortality pattern based on family and level as well as plot the results.
Authors: David J. Sharrow, GUI by Hana Sevcikova
Maintainer: David J. Sharrow <[email protected]>
License: GPL (>= 2)
Version: 1.0
Built: 2024-11-29 08:42:44 UTC
Source: CRAN

Help Index


HMD Model Life Tables

Description

Provides functions for using a model life table system generated from the Human Mortality Database

Details

Package: LifeTables
Type: Package
Version: 1.0
Date: 2015-08-07
License: GPL (>= 2)
LazyLoad: yes

mortmod is the mortality model that is the basis for the system. The user can supply the two input parameters - family and level - and a complete mortality rate schedule can be generated. If the user has some measure of child mortality (or a partial schedule) and optionally 45q15, the function hmd.DA can be used to find the appropriate family. Then alpha.e0 can calculate an alpha value to generate a life table with a desired life expectancy. The function mod.lt combines the steps outlined above. It will find the family and level based on the child (and possibly adult) mortality indicator and a desired life expectancy and return a complete life table generated with the appropriate input parameter values.

There is a graphical user interface implemented in the package that allows for generating model life tables, exporting them and plotting various measures of the life table. It can be invoked using the function modelLT.gui().

Note: In version 1.0, the calibration data set has been updated. Most recent HMD calibration data downloaded February 2015.

Author(s)

David J. Sharrow, GUI by Hana Sevcikova

Maintainer: David Sharrow <[email protected]>

References

S. Clark and D. Sharrow (2011) "Contemporary Model Life Tables for Developed Countries: An Application of Model-Based Clustering." Paper presented at the annual meeting of the Population Association of America. http://paa2011.princeton.edu/abstracts/111808

C. Fraley and A. E. Raftery (2002) "Model-based clustering, discriminant analysis, and density estimation." Journal of the American Statistical Association 97:611-631.

C. Fraley, A. E. Raftery, T. B. Murphy, L. Scrucca (2012) "mclust Version 4 for R: Normal Mixture Modeling for Model-Based Clustering, Classification, and Density Estimation", Technical Report no. 597, Department of Statistics, University of Washington

Human Mortality Database University of California, Berkeley (USA), and Max Planck Institute for Demographic Research (Germany). Available at www.mortality.org or www.humanmortality.de (data downloaded February 2015).

Examples

# first get the appropriate family #
hmd.DA(x=.09, sex="male", child.mort=4, adult.mort=.28)$classification

# then get the appropriate level (alpha) #
alpha.e0(pattern=1, e0.target=59, sex="male")

# put in the family and alpha to model to produce complete schedule #
mortmod(pattern=1, alpha=.034, sex="male")

Alpha to match life expectancy

Description

Finds the alpha value to reproduce a desired life expectancy given a life table family/pattern

Usage

alpha.e0(pattern, e0.target, sex="female")

Arguments

pattern

An integer (1-7) which indicates the desired life table family

e0.target

The desired life expectancy

sex

"male" or "female"

Details

An appropriate life table family (pattern) can be found using hmd.DA or hmd.DA.mx

Value

The alpha value to produce the life expectancy entered in e0.target

Author(s)

David J. Sharrow

See Also

lt.mx, mortmod, hmd.DA

Examples

alpha.e0(pattern=2, e0.target=65, sex="male")

Discriminant analysis to determine life table family

Description

Returns the results of a discriminant analysis to find the appropriate life table family based on either a single indicator of child mortality (1m0, 5m0, 1q0, 5q0) or one of the four child indicators and 45q15

Usage

hmd.DA(x, child.mort=4, sex="female", adult.mort = NULL)

Arguments

x

A numeric value for the child mortality indicator to be classified expressed as a proportion (e.g. x=0.05)

sex

"male" or "female" indicates the sex for the indicators

child.mort

An integer (1-4) to indicate which child mortality indicator is being supplied (1 - 1m0; 2 - 5m0; 3 - 1q0; 4 - 5q0)

adult.mort

The value for 45q15 (if no value is supplied, defaults to NULL and uses just the single child mortality measure to classify)

Details

The training models based on the known classification of the training data can be found in the workspace MLTobs in the "data" sub-directory of this package.

Value

train

The output from the function MclustDA, the parameters and other summary information for the model best fitting each class according to BIC.

out.dens

The output from the function predict(MclustDA model name), A matrix in which the [i,j]th entry is the density for observation i in the model for class j.

classification

The classification for the test data

Author(s)

David Sharrow

References

S. Clark and D. Sharrow (2011) "Contemporary Model Life Tables for Developed Countries: An Application of Model-Based Clustering." Paper presented at the annual meeting of the Population Association of America. http://paa2011.princeton.edu/abstracts/111808

C. Fraley and A. E. Raftery (2002) "Model-based clustering, discriminant analysis, and density estimation." Journal of the American Statistical Association 97:611-631.

C. Fraley, A. E. Raftery, T. B. Murphy, L. Scrucca (2012) "mclust Version 4 for R: Normal Mixture Modeling for Model-Based Clustering, Classification, and Density Estimation", Technical Report no. 597, Department of Statistics, University of Washington

Human Mortality Database University of California, Berkeley (USA), and Max Planck Institute for Demographic Research (Germany). Available at www.mortality.org or www.humanmortality.de (data downloaded February 2015).

See Also

MclustDA, Mclust, MLTobs

Examples

# classifying with 1m0
examp.out <- hmd.DA(x=.05, sex="male", child.mort=1)
examp.out$classification

# classifying with 5q0 and 45q15 
examp.out2 <- hmd.DA(x=.03, sex="male", child.mort=4, adult.mort=.18)
examp.out2$classification

Model Life Table Discriminant Analysis

Description

Training and testing steps to perform a discriminant analysis for a partial or complete human mortality rate schedule with the Human Mortality Database as the training set.

Usage

hmd.DA.mx(data, age, sex="female")

Arguments

data

Partial or complete human mortality rate schedule(s) to be classified. The set of age-specific mortality rates to be classified must match up with one of the age groups from the HMD data (standard 5-year age intervals 0, 1-4, 5-9, 10-14...110+) and be in the original scale (non-logged), i.e. one could classify mortality rates for ages 0, 1-5, 10-14, 20-24, 80-84, but cannot classify mortality rates for ages 0-5, 20-29, 30-39, etc. This argument can be either a single schedule or multiple schedules, but either way data must be a matrix with ages in columns.

age

The ages of the mortality rates to be classified. This argument tells the function which mortality rates from the HMD should be used for the training models. age is a vector of length equal to the number of columns in data with the starting ages of the intervals to be classified. (e.g. if the user wants to classify mortality rates from ages 20-24, 25-29, 30-34, 35-39, 50-54, enter age=c(seq(20,35,5),50)).

sex

"male" or "female". The sex for the schedule to be classified.

Value

train

The output from the function MclustDA, the parameters and other summary information for the model best fitting each class according to BIC.

out.dens

The output from the function predict(MclustDA model name), A matrix in which the [i,j]th entry is the density for observation i in the model for class j.

classification

The classification for the test data

Author(s)

David J. Sharrow

References

S. Clark and D. Sharrow (2011) "Contemporary Model Life Tables for Developed Countries: An Application of Model-Based Clustering." Paper presented at the annual meeting of the Population Association of America. http://paa2011.princeton.edu/abstracts/111808

C. Fraley and A. E. Raftery (2002) "Model-based clustering, discriminant analysis, and density estimation." Journal of the American Statistical Association 97:611-631.

C. Fraley, A. E. Raftery, T. B. Murphy, L. Scrucca (2012) "mclust Version 4 for R: Normal Mixture Modeling for Model-Based Clustering, Classification, and Density Estimation", Technical Report no. 597, Department of Statistics, University of Washington

Human Mortality Database University of California, Berkeley (USA), and Max Planck Institute for Demographic Research (Germany). Available at www.mortality.org or www.humanmortality.de (data downloaded February 2015).

See Also

MclustDA, Mclust, MLTobs

Examples

# some test data
data(MLTobs)

##48 Belgium 1860-64 (known class = 1)
##180 England 1925-29 (known class = 2)
##207 Estonia 2005-09 (known class = 7)
##266 France 1960-64 (known class = 3)
##410 Japan 2000-04 (known class = 5)
##607 Russia 1980-84 (known class = 6)
##798 USA 2000-04 (known class = 4)

country.nums <- c(48,180,207,266,410,607,798)
test.mx <- t(flt.mx[3:10,country.nums]) # mortality rates for ages 5-40
test.age <- seq(5,40,5)

# classify the test data matrix
examp.out <- hmd.DA.mx(data=test.mx, age=test.age, sex="female")
examp.out$classification

# classify the test data single schedule as matrix
examp.out2 <- hmd.DA.mx(data=t(as.matrix(test.mx[4,])), age=test.age, sex="female")
examp.out2$classification

Life tables from nmx

Description

Builds a life table by using the mortality rate schedule to calculate the subsequent columns of the table

Usage

lt.mx(nmx, sex="female", age = c(0,1,seq(5,110,5)), nax=NULL)

Arguments

nmx

A vector of age-specific mortality rates

age

The start age of each age interval (will also be the start age for each interval of the subsequent life table)

sex

"male" or "female". The sex determines the nax value for the childhood age intervals using the Coale and Demeney West values when nax=NULL and when under 5 mortality is split into 0-1 and 1-4.

nax

A set of nax values for the life table. Must have the same length as nmx and if no values are provided, this argument defaults to half the length of the age interval except for the first two childhood age groups.

Value

e0

Life expectancy at birth

lt

A life table with age intervals matching those of the nmx schedule on which the table is built and with columns for age, nax, nmx, nqx, npx, ndx, lx, nLx, Tx, and ex.

lt.5q0

The probability a newborn will die before age 5

lt.45q15

The probability a 15-year old will die before reaching age 60

Note

Depending on the mortality rates entered, the resulting life table may have fewer age groups than the length of the mortality rate schedule.

Author(s)

David Sharrow

Examples

# some data to build the table
data(MLTobs)
test.mx.m <- mlt.mx[,1]

# build the life table
lt.mx(nmx=test.mx.m, sex="male")

# another example with female data ages 0-85
test.mx.f <- flt.mx[1:19,1] ## ages 0-85
lt.mx(nmx=test.mx.f, sex="female", age=c(0,1,seq(5,85,5)))

Background objects necessary for certain functions

Description

This data set contains objects that are necessary for certain package functions and are described in detail below

Usage

data(MLTobs)

Format

  • averages.smooth A 48x7 matrix whose columns contain the seven underlying family patterns. Rows 1:24 are the male pattern and rows 25:48 are the female patterns. Used in mortmod.

  • class5 A vector of length 799 which contains the classification for the 799 HMD mortality rate schedules. Used in hmd.DA.mx.

  • f.csd.weight A function to determine the weight for the family-specific deviation. Used in mortmod.

  • Mx.svd.scores A 48x10 matrix whose columns contain the first 10 component score vectors a SVD of the HMD mortality rate schedules.

  • flt.mx A 24x799 matrix whose columns contain the 799 female mortality rate schedules in the Human Mortality Database

  • flt.mx.info A 799x28 matrix. The first four columns contain the Location ID, Location Name, Subgroup type and Period. The remaining columns contain the age-specific mortality rates contained in flt.mx.

  • hi.devs A 8x48 matrix whose first five rows contain the family-age-specific high deviations for when alpha is positive. The 8th row contains the age-specific high deviations from the entire HMD data set. Used in mortmod.

  • hmd.1m0.train.f Training models for females when the input parameters include 1m0. Used in hmd.DA.

  • hmd.1m0.train.m Training models for males when the input parameters include 1m0. Used in hmd.DA.

  • hmd.1m0a.train.f Training models for females when the input parameters include 1m0 and 45q15. Used in hmd.DA.

  • hmd.1m0a.train.m Training models for males when the input parameters include 1m0 and 45q15. Used in hmd.DA.

  • hmd.5m0.train.f Training models for females when the input parameters include 5m0. Used in hmd.DA.

  • hmd.5m0.train.m Training models for males when the input parameters include 5m0. Used in hmd.DA.

  • hmd.5m0a.train.f Training models for females when the input parameters include 5m0 and 45q15. Used in hmd.DA.

  • hmd.5m0a.train.m Training models for males when the input parameters include 5m0 and 45q15. Used in hmd.DA.

  • hmd.1q0.train.f Training models for females when the input parameters include 1q0. Used in hmd.DA.

  • hmd.1q0.train.m Training models for males when the input parameters include 1q0. Used in hmd.DA.

  • hmd.1q0a.train.f Training models for females when the input parameters include 1q0 and 45q15. Used in hmd.DA.

  • hmd.1q0a.train.m Training models for males when the input parameters include 1q0 and 45q15. Used in hmd.DA.

  • hmd.5q0.train.f Training models for females when the input parameters include 5q0. Used in hmd.DA.

  • hmd.5q0.train.m Training models for males when the input parameters include 5q0. Used in hmd.DA.

  • hmd.5q0a.train.f Training models for females when the input parameters include 5q0 and 45q15. Used in hmd.DA.

  • hmd.5q0a.train.m Training models for males when the input parameters include 5q0 and 45q15. Used in hmd.DA.

  • lo.devs A 8x48 matrix whose first five rows contain the family-age-specific low deviations for when alpha is positive. The 8th row contains the age-specific low deviations from the entire HMD data set. Used in mortmod.

  • mlt.mx A 24x799 matrix whose columns contain the 799 male mortality rate schedules in the Human Mortality Database

  • mlt.mx.info A 799x28 matrix. The first four columns contain the Location ID, Location Name, Subgroup type and Period. The remaining columns contain the age-specific mortality rates contained in mlt.mx.

  • opt.alpha.f A 33x7 matrix whose columns contain the female family-specific alpha values to produce life tables with life expectancies at 33 levels from 20-100 in 2.5 year increments

  • opt.alpha.m A 33x7 matrix whose columns contain the male family-specific alpha values to produce life tables with life expectancies at 33 levels from 20-100 in 2.5 year increments

  • Patterns.final.coeffs A 5x7 matrix whose columns contain the set of median coefficients for each family that are used to calculate the underlying family patterns

References

S. Clark and D. Sharrow (2011) "Contemporary Model Life Tables for Developed Countries: An Application of Model-Based Clustering." Paper presented at the annual meeting of the Population Association of America. http://paa2011.princeton.edu/abstracts/111808

C. Fraley and A. E. Raftery (2002) "Model-based clustering, discriminant analysis, and density estimation." Journal of the American Statistical Association 97:611-631.

C. Fraley, A. E. Raftery, T. B. Murphy, L. Scrucca (2012) "mclust Version 4 for R: Normal Mixture Modeling for Model-Based Clustering, Classification, and Density Estimation", Technical Report no. 597, Department of Statistics, University of Washington

Human Mortality Database University of California, Berkeley (USA), and Max Planck Institute for Demographic Research (Germany). Available at www.mortality.org or www.humanmortality.de (data downloaded February 2015).


Calculate a Model Life Table

Description

This function takes as arguments a value for child mortality, an indication of which child mortality indicator is supplied (defaults to 5q0), a possible value for 45q15, a possible target life expectancy to determine the level of mortality and the sex of the desired life table (defaults to "female"). The function selects the appropriate family (and level if a desired life expectancy is supplied or a value for alpha) and returns a life table. The resulting life table defaults to alpha=0.

Usage

mod.lt(child.value, child.mort=4, e0.target=NULL, adult.mort=NULL, 
	sex="female", alpha=0)

Arguments

child.value

A numeric value for one of four child mortality measures.

child.mort

An integer (1-4) to indicate which child mortality indicator is being supplied (1 - 1m0; 2 - 5m0; 3 - 1q0; 4 - 5q0). Defaults to 5q0.

e0.target

The desired life expectancy for the life table. If no life expectancy is supplied the resulting life table defaults to alpha=0.

sex

"male" or "female" indicates the sex for the desired life table. Defaults to "female".

adult.mort

Optional. If supplied, the function uses both the child mortality measure and 45q15 to select the family. Otherwise, just the child mortality indicator is used.

alpha

If e0.target is not supplied, alpha defaults to 0. This can be any number with negative values producing lower mortality and positive values producing higher mortality.

Value

lt.out

The life table output from the function lt.mx including $e0, life expectancy at birth, $lt.5q0, the probability of death between birth and age 5, $lt.4q15, the probability of death between age 15 and 60, and $lt, the complete, resulting life table with columns for age, nax, nmx, nqx, npx, ndx, lx, nLx, Tx, and ex.

alpha

The alpha value which produced the table. This value is either user supplied or calculated from the user supplied e0.target.

sex

Sex of the life table.

family

An integer (1-5) to indicate the life table family/pattern.

Author(s)

David Sharrow

References

S. Clark and D. Sharrow (2011) "Contemporary Model Life Tables for Developed Countries: An Application of Model-Based Clustering." Paper presented at the annual meeting of the Population Association of America. http://paa2011.princeton.edu/abstracts/111808

Human Mortality Database University of California, Berkeley (USA), and Max Planck Institute for Demographic Research (Germany). Available at www.mortality.org or www.humanmortality.de (data downloaded February 2015).

See Also

hmd.DA, alpha.e0, mortmod, lt.mx

Examples

## Example input data from USA females 1955-59 using a desired e0
mod.lt(child.value=0.02769, child.mort=4, sex="female", 
  adult.mort=0.13461, e0.target=72.5) 
  
## The user can also supply an alpha value directly
mod.lt(child.value=0.02769, child.mort=4, sex="female", 
  adult.mort=0.13461, alpha=0.233)

Graphical User Interface for the Model Life Table Functions

Description

The function launches a graphical user interface (GUI) from which various functionality of this package can be accessed.

Usage

modelLT.gui()

Details

In the main window of the GUI, select an indicator of child mortality and enter its value. Optionally, choose if an adult mortality should be added and if it is the case, enter its value. Then select a sex for the life table. Pressing the ‘Generate Life Table’ button creates a window containing the corresponding life table.

Now you can enter the desired life expectancy target (e0). Press the Enter key to update the life table and the alpha value. Alternatively, you can update the alpha value directly. Again, press the Enter key to update the content of the window.

To export the life table into a csv file, press the ‘Export’ button. To plot any of the life table columns as a function of age, select the column in the drop-list at the bottom of the window, choose if the y-axis should be on a log scale and press ‘Plot’. From here, you can save the plot in various formats.

For the GUI to run the user will first need to install GTK+.

GTK+ can be downloaded here http://www.gtk.org/download/index.php.

If the user does not first install GTK and invokes the GUI from the R console, a dialogue box will appear to ask if you want to install GTK.

Author(s)

Hana Sevcikova, David Sharrow, Samuel Clark

Examples

## Not run: 
modelLT.gui()
## End(Not run)

Underlying model in the HMD life table system

Description

This function generates a complete (up to age 110+) human mortality rate profile given a certain family and level of mortality

Usage

mortmod(pattern, sex="female", alpha=0)

Arguments

pattern

An integer from 1 to 7 indicating the underlying family pattern

sex

"male" or "female". Indicates the sex of the desired schedule

alpha

A scalar which determines the quantity to add or subtract from the underlying cluster pattern. Typical alpha values will not exceed an absolute value of 4, although it is possible to take on larger values. Defaults to 0.

Details

The pattern argument identifies the shape or pattern of mortality and then alpha determines the level by weighting a set of age-specific deviations to add or subtract (depending on the sign of alpha) to the underlying cluster pattern.

Value

model.patt

A vector of length 24 which contains a complete set of age-specific logged mortality rates for age intervals 0-1, 1-4, 5-9, 10-14, ..., 110+

Author(s)

David J. Sharrow

References

S. Clark and D. Sharrow (2011) "Contemporary Model Life Tables for Developed Countries: An Application of Model-Based Clustering." Paper presented at the annual meeting of the Population Association of America. http://paa2011.princeton.edu/abstracts/111808

Human Mortality Database University of California, Berkeley (USA), and Max Planck Institute for Demographic Research (Germany). Available at www.mortality.org or www.humanmortality.de (data downloaded February 2015).

See Also

hmd.DA, alpha.e0

Examples

mortmod(pattern=2, alpha=0.5, sex="female")
mortmod(pattern=5, alpha=-0.1, sex="male")

Plotting function for life table quantities

Description

Plots either a single column or scrolls through a plot for each column from a life table calculated from a user supplied mortality rate schedule

Usage

plotMLT(..., mx.out, sex, lt.col = "All", log = FALSE, 
	age = c(0, 1, seq(5, 110, 5)))

Arguments

...

Arguments to pass to par

mx.out

A mortality rate schedule with age groups 0-1, 1-4, 5-9, 10-14,..., up to any open interval.

sex

The sex for the calculated life table. "male" or "female"

lt.col

The desired life table quantity to plot. lt.col="All", the default, will scroll through a plot of each quantity when the user keys "return" after each plot. Otherwise a specific column can be selected by using the following integers (1-nmx, 2-nqx, 3-npx, 4-ndx, 5-lx, 6-nLx, 7-Tx, 8-ex)

log

Logical. If TRUE and lt.col is not set to "All", the y-axis will be in log scale.

age

The start ages for each interval in the life table

Details

If lt.col=3 (npx) and log=TRUE, a warning message will appear noting that a y value <= 0 is omitted. This is the probability of surviving the final interval, which is by definition, 0.

Author(s)

David J. Sharrow

See Also

lt.mx

Examples

## Not run: 
mx.examp <- exp(mortmod(pattern=1, alpha=.05, sex="male")) 
plotMLT(mx.out=mx.examp, sex="male", lt.col="All")

plotMLT(mx.out=mx.examp, sex="male", lt.col=3, log=TRUE)

## End(Not run)