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 |
Provides functions for using a model life table system generated from the Human Mortality Database
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.
David J. Sharrow, GUI by Hana Sevcikova
Maintainer: David Sharrow <[email protected]>
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).
# 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")
# 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")
Finds the alpha value to reproduce a desired life expectancy given a life table family/pattern
alpha.e0(pattern, e0.target, sex="female")
alpha.e0(pattern, e0.target, sex="female")
pattern |
An integer (1-7) which indicates the desired life table family |
e0.target |
The desired life expectancy |
sex |
"male" or "female" |
An appropriate life table family (pattern) can be found using hmd.DA
or hmd.DA.mx
The alpha value to produce the life expectancy entered in e0.target
David J. Sharrow
alpha.e0(pattern=2, e0.target=65, sex="male")
alpha.e0(pattern=2, e0.target=65, sex="male")
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
hmd.DA(x, child.mort=4, sex="female", adult.mort = NULL)
hmd.DA(x, child.mort=4, sex="female", adult.mort = NULL)
x |
A numeric value for the child mortality indicator to be classified expressed as a proportion (e.g. |
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) |
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.
train |
The output from the function |
out.dens |
The output from the function |
classification |
The classification for the test data |
David Sharrow
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).
# 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
# 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
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.
hmd.DA.mx(data, age, sex="female")
hmd.DA.mx(data, age, sex="female")
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 |
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. |
sex |
"male" or "female". The sex for the schedule to be classified. |
train |
The output from the function |
out.dens |
The output from the function |
classification |
The classification for the test data |
David J. Sharrow
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).
# 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
# 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
Builds a life table by using the mortality rate schedule to calculate the subsequent columns of the table
lt.mx(nmx, sex="female", age = c(0,1,seq(5,110,5)), nax=NULL)
lt.mx(nmx, sex="female", age = c(0,1,seq(5,110,5)), nax=NULL)
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 |
A set of nax values for the life table. Must have the same length as |
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 |
Depending on the mortality rates entered, the resulting life table may have fewer age groups than the length of the mortality rate schedule.
David Sharrow
# 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)))
# 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)))
This data set contains objects that are necessary for certain package functions and are described in detail below
data(MLTobs)
data(MLTobs)
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
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).
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.
mod.lt(child.value, child.mort=4, e0.target=NULL, adult.mort=NULL, sex="female", alpha=0)
mod.lt(child.value, child.mort=4, e0.target=NULL, adult.mort=NULL, sex="female", alpha=0)
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. |
lt.out |
The life table output from the function |
alpha |
The alpha value which produced the table. This value is either user supplied or calculated from the user supplied |
sex |
Sex of the life table. |
family |
An integer (1-5) to indicate the life table family/pattern. |
David Sharrow
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).
hmd.DA
, alpha.e0
, mortmod
, lt.mx
## 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)
## 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)
The function launches a graphical user interface (GUI) from which various functionality of this package can be accessed.
modelLT.gui()
modelLT.gui()
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.
Hana Sevcikova, David Sharrow, Samuel Clark
## Not run: modelLT.gui() ## End(Not run)
## Not run: modelLT.gui() ## End(Not run)
This function generates a complete (up to age 110+) human mortality rate profile given a certain family and level of mortality
mortmod(pattern, sex="female", alpha=0)
mortmod(pattern, sex="female", alpha=0)
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. |
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.
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+ |
David J. Sharrow
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).
mortmod(pattern=2, alpha=0.5, sex="female") mortmod(pattern=5, alpha=-0.1, sex="male")
mortmod(pattern=2, alpha=0.5, sex="female") mortmod(pattern=5, alpha=-0.1, sex="male")
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
plotMLT(..., mx.out, sex, lt.col = "All", log = FALSE, age = c(0, 1, seq(5, 110, 5)))
plotMLT(..., mx.out, sex, lt.col = "All", log = FALSE, age = c(0, 1, seq(5, 110, 5)))
... |
Arguments to pass to |
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 |
age |
The start ages for each interval in the life table |
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.
David J. Sharrow
## 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)
## 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)