| Type: | Package |
| Title: | Parametric Mortality Models, Life Tables and HMD |
| Version: | 2.2.0 |
| Maintainer: | Marius D. Pascariu <mpascariu@outlook.com> |
| Description: | Fit the most popular human mortality 'laws', and construct full and abridge life tables given various input indices. A mortality law is a parametric function that describes the dying-out process of individuals in a population during a significant portion of their life spans. For a comprehensive review of the most important mortality laws see Tabeau (2001) <doi:10.1007/0-306-47562-6_1>. Practical functions for downloading data from various human mortality databases are provided as well. |
| License: | MIT + file LICENSE |
| LazyData: | TRUE |
| Depends: | R (≥ 3.0.0) |
| Imports: | RCurl (≥ 1.95), pbapply (≥ 1.3-4), tidyr (≥ 0.8.1), rvest (≥ 1.0.3), httr (≥ 1.4.5), methods |
| Suggests: | testthat, knitr, rmarkdown |
| URL: | https://github.com/mpascariu/MortalityLaws |
| BugReports: | https://github.com/mpascariu/MortalityLaws/issues |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| VignetteBuilder: | knitr |
| NeedsCompilation: | no |
| Packaged: | 2026-05-05 06:43:17 UTC; masax |
| Author: | Marius D. Pascariu
|
| Repository: | CRAN |
| Date/Publication: | 2026-05-05 07:10:08 UTC |
MortalityLaws: Parametric Mortality Models, Life Tables and HMD
Description
Fit the most popular human mortality 'laws', and construct full and abridge life tables given various input indices. A mortality law is a parametric function that describes the dying-out process of individuals in a population during a significant portion of their life spans. For a comprehensive review of the most important mortality laws see Tabeau (2001) doi:10.1007/0-306-47562-6_1. Practical functions for downloading data from various human mortality databases are provided as well.
Details
To learn more about the package, start with the vignettes:
browseVignettes(package = "MortalityLaws")
Author(s)
Maintainer: Marius D. Pascariu mpascariu@outlook.com (ORCID) [copyright holder]
Other contributors:
Vladimir Canudas-Romo [contributor]
See Also
Useful links:
Report bugs at https://github.com/mpascariu/MortalityLaws/issues
AHMD sample
Data object generated by the ReadAHMD() function.
Description
AHMD sample
Data object generated by the ReadAHMD() function.
Usage
AHMD_sample
Format
An object of class ReadAHMD of length 5.
Value
A sample of demographic data in a data.frame
AIC function for MortalityLaw
Description
AIC function for MortalityLaw
Usage
## S3 method for class 'MortalityLaw'
AIC(object, ...)
Arguments
... |
further arguments passed to or from other methods. |
Value
model AIC value
region codes
Description
region codes
Usage
AUSregions()
Value
a vector
Country codes
Description
Country codes
Usage
CANregions()
Value
a vector
CHMD sample
Data object generated by the ReadCHMD() function.
Description
CHMD sample
Data object generated by the ReadCHMD() function.
Usage
CHMD_sample
Format
An object of class ReadCHMD of length 5.
Value
A sample of demographic data in a data.frame
HMD sample
Data object generated by the ReadHMD() function.
Description
HMD sample
Data object generated by the ReadHMD() function.
Usage
HMD_sample
Format
An object of class ReadHMD of length 5.
Value
A sample of demographic data in a data.frame
Country codes
Description
Country codes
Usage
HMDcountries()
Value
a vector
HMD Indices
Description
HMD Indices
Usage
HMDindices()
Value
a vector
Heligman-Pollard Mortality Law - 8 parameters - 1980
Description
Heligman-Pollard Mortality Law - 8 parameters - 1980
Usage
HP(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
HP(x = 0:100)
Heligman-Pollard 2 Mortality Law - 8 parameters
Description
Heligman-Pollard 2 Mortality Law - 8 parameters
Usage
HP2(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
HP2(x = 0:100)
Heligman-Pollard 3 Mortality Law - 9 parameters
Description
Heligman-Pollard 3 Mortality Law - 9 parameters
Usage
HP3(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
HP3(x = 0:100)
Heligman-Pollard 4 Mortality Law - 9 parameters
Description
Heligman-Pollard 4 Mortality Law - 9 parameters
Usage
HP4(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
HP4(x = 0:100)
JMD sample
Data object generated by the ReadJMD() function.
Description
JMD sample
Data object generated by the ReadJMD() function.
Usage
JMD_sample
Format
An object of class ReadJMD of length 5.
Value
A sample of demographic data in a data.frame
region codes
Description
region codes
Usage
JPNregions()
Value
the vector
Compute Life Tables from Parameters of a Mortality Law
Description
Generate a complete life table directly from the fitted parameters of a
parametric mortality model. This function evaluates the mortality law at
the given ages and passes the resulting death rates (mx) or death
probabilities (qx) to LifeTable for further
computation of all standard life-table columns (lx, dx,
Lx, Tx, ex, etc.).
Usage
LawTable(x, par, law, sex = NULL, lx0 = 1e+05, ax = NULL)
Arguments
x |
Numeric vector of ages at the beginning of each age interval.
For a full life table, use single-year ages (e.g., |
par |
The parameters of the mortality model. Can be:
|
law |
The name of the mortality law to be used (e.g., |
sex |
Sex of the population. Options are |
lx0 |
Radix, the starting population (or probability scale) at
age 0. Default is |
ax |
Numeric vector representing the average number of person-years
lived in the age interval by those who die in that interval. If
|
Details
This function is designed to work with models that have been fitted
externally (e.g., via MortalityLaw or by hand). The
par argument must contain the estimated coefficients of the
mortality law, and law must be one of the valid codes listed by
availableLaws.
Important caveat: age scaling during fitting
Several mortality laws (e.g., Gompertz, Makeham) internally scale
the age vector during optimisation to ensure numerical stability. If the
model was fitted using MortalityLaw over an age range [a, b],
the published coefficients correspond to the scaled ages, not the
original ages. Consequently, LawTable will only produce valid life
tables for ages \ge a (the lower bound of the fitting range).
Attempting to use the same coefficients at younger ages will yield
incorrect results (e.g., life expectancy at age 25 will equal that at
age 45).
To determine which models apply age scaling, run:
A <- availableLaws()$table
A[, c("CODE", "SCALE_X")]
Models with SCALE_X = TRUE rescale the age vector internally. When
using LawTable with such a model, make sure the x argument
starts from the same lower age bound used during fitting.
For models that do not scale (e.g., Heligman-Pollard "HP"),
this limitation does not apply, and LawTable can be used for any
age range.
Value
An object of class "LifeTable" containing the following
components:
lt |
A |
call |
The matched function call. |
process_date |
Timestamp of when the life table was computed. |
Author(s)
Marius D. Pascariu
See Also
LifeTable for constructing life tables from raw mortality
data;
MortalityLaw for fitting parametric mortality models;
availableLaws for the list of implemented laws and their
scaling behaviour.
Examples
# Example 1 --- Makeham --- multiple life tables from a matrix of parameters
x1 <- 45:100
L1 <- "makeham"
C1 <- matrix(
c(0.00717, 0.07789, 0.00363,
0.01018, 0.07229, 0.00001,
0.00298, 0.09585, 0.00002,
0.00067, 0.11572, 0.00078),
nrow = 4,
dimnames = list(1:4, c("A", "B", "C"))
)
LawTable(x = x1, par = C1, law = L1)
# ---- Important note on age scaling ----
# The Makeham model applies internal age scaling during fitting.
# If the coefficients above were estimated over ages 45-100, the life
# table produced by LawTable is valid only from age 45 onward.
# ---- Example 1B: correct usage ----
LawTable(x = 45:100, par = c(0.00717, 0.07789, 0.00363), law = L1)
# ---- Example 1C: incorrect usage ----
# The code below uses the same coefficients but starts at age 25.
# Because the model was fitted on scaled ages (starting at 45),
# the life table at age 25 will be meaningless (e.g., e25 equals e45).
## Not run:
LawTable(x = 25:100, par = c(0.00717, 0.07789, 0.00363), law = L1)
## End(Not run)
# ---- How to check which laws apply scaling ----
A <- availableLaws()$table
A[, c("CODE", "SCALE_X")]
# Example 2 --- Heligman-Pollard (no scaling) ---
x2 <- 0:110
L2 <- "HP"
C2 <- c(0.00223, 0.01461, 0.12292, 0.00091,
2.75201, 29.01877, 0.00002, 1.11411)
LawTable(x = x2, par = C2, law = L2)
# Because "HP" does NOT scale the age vector, the output is valid for
# any starting age. Compare:
LawTable(x = 3:110, par = C2, law = L2)
# Note that e3 = 70.31 in both tables, confirming consistency.
Compute Life Tables from Mortality Data
Description
Construct either a full (single-year age intervals) or an abridged (wider age intervals) life table from a variety of input data types. The function accepts:
Death counts and mid-interval population estimates (
Dx, Ex)Age-specific death rates (
mx)Death probabilities (
qx)Survivorship curve (
lx)Distribution of deaths (
dx)
Only one of these input options needs to be provided; the others
are ignored if present. The input can be a numeric vector,
matrix, or data.frame. When a matrix or
data.frame with multiple columns is supplied, the function
computes one life table per column.
Usage
LifeTable(x, Dx = NULL, Ex = NULL,
mx = NULL,
qx = NULL,
lx = NULL,
dx = NULL,
sex = NULL,
lx0 = 1e5,
ax = NULL)
Arguments
x |
Numeric vector of ages at the beginning of each age interval.
For a full life table, use single-year ages (e.g., |
Dx |
Death counts. Each element represents the total number of
deaths during the calendar year to persons aged |
Ex |
Exposure-to-risk in the period. This is usually approximated
by the mid-year population aged |
mx |
Age-specific death rate in the age interval |
qx |
Probability of dying within the age interval |
lx |
Probability of surviving to exact age |
dx |
Number of deaths in the life-table population occurring in
the age interval |
sex |
Sex of the population. Options are |
lx0 |
Radix, the starting population (or probability scale) at
age 0. Default is |
ax |
Numeric vector representing the average number of person-years
lived in the age interval by those who die in that interval. If
|
Details
A life table (also called a mortality table or actuarial table) summarises the mortality experience of a population. For each age (or age interval) it reports:
Death rates (
mx) and death probabilities (qx)Survivorship (
lx)Distribution of deaths (
dx)Person-years lived (
Lx) and total person-years remaining (Tx)Life expectancy (
ex)
The life table is constructed sequentially: from the input data the
function derives mx, then qx, then lx, dx,
Lx, Tx, and finally ex. The constant-force-of-mortality
(CFM) assumption is used to convert between mx and qx.
If the sex argument is supplied, the first two values of the
ax column are adjusted using the Coale-Demeny method, which
accounts for the different infant mortality patterns between males
and females.
Value
An object of class "LifeTable" containing the following
components:
lt |
A |
call |
The matched function call. |
process_date |
Timestamp of when the life table was computed. |
Author(s)
Marius D. Pascariu
See Also
LawTable for generating life tables from a fitted
parametric mortality law;
convertFx for converting between mortality measures.
Examples
# Example 1 --- Full life tables with different inputs ------------
y <- 1900
x <- as.numeric(rownames(ahmd$mx))
Dx <- ahmd$Dx[, paste(y)]
Ex <- ahmd$Ex[, paste(y)]
LT1 <- LifeTable(x, Dx = Dx, Ex = Ex)
LT2 <- LifeTable(x, mx = LT1$lt$mx)
LT3 <- LifeTable(x, qx = LT1$lt$qx)
LT4 <- LifeTable(x, lx = LT1$lt$lx)
LT5 <- LifeTable(x, dx = LT1$lt$dx)
LT1
LT5
ls(LT5)
# Example 2 --- Compute multiple life tables at once ------------
LTs <- LifeTable(x, mx = ahmd$mx)
LTs
# A warning is printed if the input contains missing values.
# Some of the missing values can be handled automatically.
# Example 3 --- Abridged life table -----------------------------
x <- c(0, 1, seq(5, 110, by = 5))
mx <- c(.053, .005, .001, .0012, .0018, .002, .003, .004,
.004, .005, .006, .0093, .0129, .019, .031, .049,
.084, .129, .180, .2354, .3085, .390, .478, .551)
LT6 <- LifeTable(x, mx = mx, sex = "female")
LT6
# Example 4 --- Abridged life table using a custom 'ax' --------
# This example reuses the ages (x) and death rates (mx) from Example 3.
# Note that 'ax' must have the same length as 'x', otherwise an error
# will be returned.
my_ax <- c(0.1, 1.5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1)
LT7 <- LifeTable(x = x, mx = mx, ax = my_ax)
Check LifeTable input
Description
Check LifeTable input
Usage
LifeTable.check(input)
Arguments
input |
A list containing the input arguments of the LifeTable functions. |
Value
A list of life table validated data
LifeTable.core
Description
LifeTable.core
Usage
LifeTable.core(x, Dx, Ex, mx, qx, lx, dx, sex, lx0, ax)
Arguments
x |
Numeric vector of ages at the beginning of each age interval.
For a full life table, use single-year ages (e.g., |
Dx |
Death counts. Each element represents the total number of
deaths during the calendar year to persons aged |
Ex |
Exposure-to-risk in the period. This is usually approximated
by the mid-year population aged |
mx |
Age-specific death rate in the age interval |
qx |
Probability of dying within the age interval |
lx |
Probability of surviving to exact age |
dx |
Number of deaths in the life-table population occurring in
the age interval |
sex |
Sex of the population. Options are |
lx0 |
Radix, the starting population (or probability scale) at
age 0. Default is |
ax |
Numeric vector representing the average number of person-years
lived in the age interval by those who die in that interval. If
|
Value
A data.frame containing life table results
Fit Mortality Laws
Description
Fit parametric mortality models given a set of input data. The data can be
supplied as death counts and mid-interval population estimates
(Dx, Ex), age-specific death rates (mx), or death
probabilities (qx). Use the law argument to specify the
model to be fitted. Over 30 parametric models are currently implemented;
run availableLaws to see the full list. Models can be fitted
using maximum likelihood or by optimising a loss function. See the
availableLF function for the implemented options.
Usage
MortalityLaw(x, Dx = NULL, Ex = NULL, mx = NULL, qx = NULL,
law = NULL,
opt.method = "LF2",
parS = NULL,
fit.this.x = x,
custom.law = NULL,
show = FALSE, ...)
Arguments
x |
Numeric vector of ages at the beginning of each age interval.
For a full life table, use single-year ages (e.g., |
Dx |
Death counts. Each element represents the total number of
deaths during the calendar year to persons aged |
Ex |
Exposure-to-risk in the period. This is usually approximated
by the mid-year population aged |
mx |
Age-specific death rate in the age interval |
qx |
Probability of dying within the age interval |
law |
The name of the mortality law to be used (e.g., |
opt.method |
The function to optimise. Available options:
See |
parS |
Optional starting parameter values for the optimisation. If
|
fit.this.x |
A subset of |
custom.law |
A user-defined function for fitting a model not included
in the package. The function must accept arguments |
show |
Logical. If |
... |
Additional arguments passed to or from other methods. |
Details
Optimisation: The PORT routines (via nlminb) are used
for unconstrained and box-constrained optimisation. Parameters are estimated
on the log scale to ensure positivity, and the routine is set to allow up to
5000 iterations. When the optimisation method is "poissonL" or
"binomialL", the AIC, BIC and log-likelihood are computed from the
likelihood. Otherwise these are set to NaN.
Scaling of the age vector: For models that cover only a portion
of the lifespan (e.g., adult or old-age mortality), the age vector x
is automatically re-scaled as x = x - min(x) + 1 before fitting.
This transformation improves numerical stability and helps the optimisation
algorithm converge, especially when the starting age is far from zero.
Models that apply this scaling are flagged with SCALE_X = TRUE in
the table returned by availableLaws. When using
predict.MortalityLaw or LawTable with such
models, the same scaling is applied internally, so predictions remain
consistent with the fitted coefficients.
Handling matrix input: If Dx, Ex, mx or
qx are provided as matrices (with one column per population or
time period), the function iterates over the columns and fits a separate
model to each, returning a collection of results.
Value
An object of class "MortalityLaw", which is a list with the following
components:
input |
List of input arguments, stored for reproducibility. |
info |
Model information (name, formula, date of fitting). |
coefficients |
Estimated parameters of the mortality law. A named vector for a single fit, or a matrix for multiple fits. |
fitted.values |
Fitted hazard rates (or death probabilities) evaluated
at the input ages |
residuals |
Deviance residuals, computed as observed minus fitted values. |
goodness.of.fit |
List or matrix of goodness-of-fit measures: AIC, BIC and log-likelihood (available only for likelihood-based methods). |
opt.diagnosis |
Object returned by the optimisation routine, useful for checking convergence. |
df |
Number of parameters and residual degrees of freedom. |
deviance |
Sum of squared log-residuals, used as a deviance measure. |
Author(s)
Marius D. Pascariu
See Also
availableLaws for a list of all implemented models;
availableLF for loss function details;
LifeTable for life table construction;
ReadHMD for downloading data from the Human Mortality Database.
Examples
# Example 1: Fitting the Makeham model --------------------------
x <- 45:75
Dx <- ahmd$Dx[paste(x), "1950"]
Ex <- ahmd$Ex[paste(x), "1950"]
M1 <- MortalityLaw(x = x, Dx = Dx, Ex = Ex, law = 'makeham')
M1
ls(M1)
coef(M1)
summary(M1)
fitted(M1)
predict(M1, x = 45:95)
plot(M1)
# Example 2: --------------------------
# We can fit the same model using a different data format
# and a different optimization method.
x <- 45:75
mx <- ahmd$mx[paste(x), ]
M2 <- MortalityLaw(x = x, mx = mx, law = 'makeham', opt.method = 'LF1')
M2
fitted(M2)
predict(M2, x = 55:90)
# Example 3: --------------------------
# Now let's fit a mortality law that is not defined
# in the package, say a reparameterized Gompertz in
# terms of modal age at death
# hx = b*exp(b*(x-m)) (here b and m are the parameters to be estimated)
# A function with 'x' and 'par' as input has to be defined, which returns
# at least an object called 'hx' (hazard rate).
my_gompertz <- function(x, par = c(b = 0.13, M = 45)){
hx <- with(as.list(par), b*exp(b*(x - M)) )
return(as.list(environment()))
}
M3 <- MortalityLaw(x = x, Dx = Dx, Ex = Ex, custom.law = my_gompertz)
summary(M3)
# predict M3 for different ages
predict(M3, x = 85:130)
# Example 4: --------------------------
# Fit Heligman-Pollard model for a single
# year in the dataset between age 0 and 100 and build a life table.
x <- 0:100
mx <- ahmd$mx[paste(x), "1950"] # select data
M4 <- MortalityLaw(x = x, mx = mx, law = 'HP', opt.method = 'LF2')
M4
plot(M4)
LifeTable(x = x, qx = fitted(M4))
Download the Australian Human Mortality Database (AHMD)
Description
Download detailed mortality and population data for different provinces and territories in Australia, in a single object from the Australian Human Mortality Database.
Usage
ReadAHMD(what, regions = NULL, interval = "1x1", save = FALSE, show = TRUE)
Arguments
what |
What type of data are you looking for? The following options might be available for some or all the countries and regions:
|
regions |
Specify the region specific data you want to download by adding the AHMD region code/s. Options:
|
interval |
Datasets are given in various age and time formats based on which the records are aggregated. Interval options:
|
save |
Do you want to save a copy of the dataset on your local machine?
Logical. Default: |
show |
Choose whether to display a progress bar. Logical.
Default: |
Details
(Description taken from the AHMD website).
The Australian Human Mortality Database (AHMD) was created to provide detailed Australian mortality and population data to researchers, students, journalists, policy analysts, and others interested in the history of human longevity. The project is an achievement of the Mortality, Ageing & Health research team in the ANU School of Demography under the supervision of Associate Professor Vladimir Canudas-Romo, in collaboration with demographers at the Max Plank Institute for Demographic Research (Rostock, Germany) and the Department of Demography, University of California at Berkeley.
The AHMD is a "satellite" of the Human Mortality Database (HMD), an international database which currently holds detailed data for multiple countries or regions. Consequently, the AHMD's underlying methodology corresponds to the one used for the HMD.
The AHMD gathers all required data (deaths counts, births counts, population size, exposure-to-risk, death rates) to compute life tables for Australia, its states and its territories. One of the great advantages of the database is to include data that is validated and corrected, when required, and rendered comparable, if possible, for the period ranging from 1971 thru 2016. For comparison purposes, various life tables published by governmental organizations are also available for download in PDF format.
Value
A ReadAHMD object that contains:
input |
List with the input values; |
data |
Data downloaded from AHMD; |
download.date |
Time stamp; |
years |
Numerical vector with the years covered in the data; |
ages |
Numerical vector with ages covered in the data. |
Author(s)
Marius D. Pascariu
See Also
Examples
# Download demographic data for Australian Capital Territory and
# Tasmania regions in 5x1 format
# Death counts. We don't want to export data outside R.
AHMD_Dx <- ReadAHMD(what = "Dx",
regions = c('ACT', 'TAS'),
interval = "5x1",
save = FALSE)
AHMD_Dx
# Download life tables for female population in all the states and export data.
LTF <- ReadAHMD(what = "LT_f", interval = "5x1", save = FALSE)
LTF
Download the Canadian Human Mortality Database (CHMD)
Description
Download detailed mortality and population data for different provinces and territories in Canada, in a single object from the Canadian Human Mortality Database.
Usage
ReadCHMD(what, regions = NULL, interval = "1x1", save = FALSE, show = TRUE)
Arguments
what |
What type of data are you looking for? The following options are available:
|
regions |
Specify the region specific data you want to download by adding the CHMD region code/s. Options:
|
interval |
Datasets are given in various age and time formats based on which the records are aggregated. Interval options:
|
save |
Do you want to save a copy of the dataset on your local machine?
Logical. Default: |
show |
Choose whether to display a progress bar. Logical.
Default: |
Details
(Description taken from the CHMD website).
The Canadian Human Mortality Database (CHMD) was created to provide detailed Canadian mortality and population data to researchers, students, journalists, policy analysts, and others interested in the history of human longevity. The project is an achievement of the Mortality and Longevity research team at the Department of Demography, Universite de Montreal, under the supervision of Professor Robert Bourbeau, in collaboration with demographers at the Max Plank Institute for Demographic Research (Rostock, Germany) and the Department of Demography, University of California at Berkeley. Nadine Ouellette, researcher at the Institut national d'etudes demographiques in Paris and member of the Mortality and Longevity research team at the Universite de Montreal, is in charge of computing all CHMD life tables and updating the CHMD web site.
The CHMD is a "satellite" of the Human Mortality Database (HMD), an international database which currently holds detailed data for multiple countries or regions. Consequently, the CHMD's underlying methodology corresponds to the one used for the HMD.
The CHMD gathers all required data (deaths counts, births counts, population size, exposure-to-risk, death rates) to compute life tables for Canada, its provinces and its territories. One of the great advantages of the database is to include data that is validated and corrected, when required, and rendered comparable, if possible, for the period ranging from 1921 thru 2011. For comparison purposes, various life tables published by governmental organizations are also available for download in PDF format.
Value
A ReadCHMD object that contains:
input |
List with the input values; |
data |
Data downloaded from CHMD; |
download.date |
Time stamp; |
years |
Numerical vector with the years covered in the data; |
ages |
Numerical vector with ages covered in the data. |
Author(s)
Marius D. Pascariu
See Also
Examples
# Download demographic data for Quebec and Saskatchewan regions in 1x1 format
# Death counts. We don't want to export data outside R.
CHMD_Dx <- ReadCHMD(what = "Dx",
regions = c('QUE', 'SAS'),
interval = "1x1",
save = FALSE)
# Download life tables for female population. To export data use save = TRUE.
LTF <- ReadCHMD(what = "LT_f",
regions = c('QUE', 'SAS'),
interval = "1x1",
save = FALSE)
Download The Human Mortality Database (HMD)
Description
Download detailed mortality and population data for different countries and regions in a single object from the Human Mortality Database.
Usage
ReadHMD(
what,
countries = NULL,
interval = "1x1",
username,
password,
save = FALSE,
show = TRUE
)
Arguments
what |
What type of data are you looking for? The following options might be available for some or all the countries and regions:
|
countries |
Specify the country data you want to download by adding the
HMD country code/s. Options:
|
interval |
Datasets are given in various age and time formats based on which the records are aggregated. Interval options:
|
username |
Your HMD username. If you don't have one you can sign up for free on the Human Mortality Database website. |
password |
Your HMD password. |
save |
Do you want to save a copy of the dataset on your local machine?
Logical. Default: |
show |
Choose whether to display a progress bar. Logical.
Default: |
Details
The Human Mortality Database (HMD) was created to provide detailed mortality and population data to researchers, students, journalists, policy analysts, and others interested in the history of human longevity. The project began as an outgrowth of earlier projects in the Department of Demography at the University of California, Berkeley, USA, and at the Max Planck Institute for Demographic Research in Rostock, Germany (see history). It is the work of two teams of researchers in the USA and Germany (see research teams), with the help of financial backers and scientific collaborators from around the world (see acknowledgements). The Center on the Economics and Development of Aging (CEDA) French Institute for Demographic Studies (INED) has also supported the further development of the database in recent years.
Value
A ReadHMD object that contains:
input |
List with the input values (except the password). |
data |
Data downloaded from HMD. |
download.date |
Time stamp. |
years |
Numerical vector with the years covered in the data. |
ages |
Numerical vector with ages covered in the data. |
Author(s)
Marius D. Pascariu
Examples
## Not run:
# Download demographic data for 3 countries in 1x1 format
age_int <- 1 # age interval: 1,5
year_int <- 1 # year interval: 1,5,10
interval <- paste0(age_int, "x", year_int) # --> 1x1
# And the 3 countries: Sweden Denmark and USA. We have to use the HMD codes
cntr <- c('SWE', 'DNK', 'USA')
# Download death counts. We don't want to export data outside R.
HMD_Dx <- ReadHMD(what = "Dx",
countries = cntr,
interval = interval,
username = "user@email.com",
password = "password",
save = FALSE)
HMD_Dx
# Download life tables for female population and export data.
LTF <- ReadHMD(what = "LT_f",
countries = cntr,
interval = interval,
username = "user@email.com",
password = "password",
save = TRUE)
LTF
## End(Not run)
Function to Download Data for a one Country
Description
Function to Download Data for a one Country
Usage
ReadHMD.core(what, country, interval, username, password, link)
Arguments
what |
What type of data are you looking for? The following options might be available for some or all the countries and regions:
|
country |
HMD country code for the selected country. Character; |
interval |
Datasets are given in various age and time formats based on which the records are aggregated. Interval options:
|
username |
Your HMD username. If you don't have one you can sign up for free on the Human Mortality Database website. |
password |
Your HMD password. |
link |
the main link to the database. |
Value
A data.frame containing demographic data
Download the Japanese Mortality Database (JMD)
Description
Download detailed mortality and population data of the 47 prefectures in Japan, in a single object. The source of data is the Japanese Mortality Database.
Usage
ReadJMD(what, regions = NULL, interval = "1x1", save = FALSE, show = TRUE)
Arguments
what |
What type of data are you looking for? The following options might be available for some or all the countries and regions:
|
regions |
Specify the region specific data you want to download by
adding the JMD region code/s. Options: |
interval |
Datasets are given in various age and time formats based on which the records are aggregated. Interval options:
|
save |
Do you want to save a copy of the dataset on your local machine?
Logical. Default: |
show |
Choose whether to display a progress bar. Logical.
Default: |
Details
(Description taken from the JMD website).
The Japanese Mortality Database is a comprehensively-reorganized mortality database that is optimized for mortality research and consistent with the Human Mortality Database. This database is provided as a part of the research project "Demographic research on the causes and the socio-economic consequence of longetivity extension in Japan" (2011-2013), "Demographic research on longevity extension, population aging, and their effects on the social security and socio-economic structures in Japan" (2014-2016), and "Comprehensive research from a demographic viewpoint on the longevity revolution" (2017-2019) at the National Institute of Population and Social Security Research.
The Japanese Mortality Database is designed to provide the life tables to all the people who are interested in Japanese mortality including domestic and foreign mortality researchers for the purpose of mortality research. Especially because we have structured it to conform with the HMD, our database is suitable for international comparison, we put emphasis on the compatibility with the HMD more than our country's particular characteristics. Therefore, the life tables by JMD do not necessarily exhibit the same values as ones by the official life tables prepared and released by the Statistics and Information Department, Minister's Secretariat, Ministry of Health, Labor and Welfare according to the different base population or the methods for estimating the tables. When doing things other than mortality research, if life table that statistically displays our country's mortality situation is necessary, please use the official life table that has been prepared by the Statistics and Information Department, Minister's Secretariat, Ministry of Health, Labor and Welfare.
At the present time, we offer the data for All Japan and by prefecture. The project team is studying the methodology for estimating life tables along with data preparation. Therefore, the data may be updated when a new methodology is adopted. Please refer to "Methods" for further information.
Value
A ReadJMD object that contains:
input |
List with the input values; |
data |
Data downloaded from JMD; |
download.date |
Time stamp; |
years |
Numerical vector with the years covered in the data; |
ages |
Numerical vector with ages covered in the data. |
Author(s)
Marius D. Pascariu
See Also
Examples
# Download demographic data for Fukushima and Tokyo regions in 1x1 format
# Death counts. We don't want to export data outside R.
JMD_Dx <- ReadJMD(what = "Dx",
regions = c('Fukushima', 'Tokyo'),
interval = "1x1",
save = FALSE)
JMD_Dx
# Download life tables for female population in all the states and export data.
LTF <- ReadJMD(what = "LT_f", interval = "5x5", save = FALSE)
LTF
Retrieve model-specific details for fitting
Description
Based on the chosen mortality law (or a custom law), this function retrieves the default starting parameters, the model information table, and whether the age vector should be scaled before fitting.
Usage
addDetails(law, custom.law = NULL, parS = NULL)
Arguments
law |
The name of the mortality law to be used (e.g., |
custom.law |
A user-defined function for fitting a model not included
in the package. The function must accept arguments |
parS |
Optional starting parameter values for the optimisation. If
|
Value
A list with components:
law |
Internal law name (e.g., |
parS |
Starting parameter values for the optimisation. |
model |
Model information data frame (from |
scale.x |
Logical; whether the age vector should be re-scaled
( |
What age(s) are we looking at?
Description
What age(s) are we looking at?
Usage
ageMsg(what, x)
Arguments
x |
An object of class |
Value
A scalar or character indicating age groups
MortalityLaws Test Data
Description
Dataset containing altered death rates (mx), death counts (Dx)
and exposures (Ex) for the female population living in
England & Wales in four different years: 1850, 1900, 1950 and 2010.
This dataset is provided for testing purposes only.
Download the actual data free of charge from https://www.mortality.org.
Once a username and a password are created on the website, the function
ReadHMD can be used for downloading.
Usage
ahmd
Format
An object of class list of length 3.
Source
See Also
Examples
head(ahmd$mx)
Check Data Availability in HMD
Description
Returns information about the data available in the Human Mortality Database (HMD), including the range of years covered by the life tables for each country or region.
Usage
availableHMD(link = "https://www.mortality.org/Data/DataAvailability")
Arguments
link |
URL to the HMD available data. Default: "https://www.mortality.org/Data/DataAvailability" |
Value
A tibble.
Author(s)
Marius D. Pascariu
See Also
Examples
availableHMD()
Check Available Loss Functions
Description
Returns information about the loss functions implemented for use with the
optimisation procedure in the MortalityLaw function.
Usage
availableLF()
Value
A list of class availableLF with the components:
table |
Table with loss functions and codes to be used in |
legend |
Table with details about the abbreviation used. |
Author(s)
Marius D. Pascariu
See Also
Examples
availableLF()
Check Available Mortality Laws
Description
The function returns information about the parametric models that can be
called and fitted in the MortalityLaw function.
For a comprehensive review of the most important mortality laws,
Tabeau (2001) is a good starting point.
Usage
availableLaws(law = NULL)
Arguments
law |
Optional. Default: |
Value
The output is of the "availableLaws" class with the following
components:
table |
Table with mortality models and codes to be used in |
legend |
Table with details about the section of the mortality curve. |
Author(s)
Marius D. Pascariu
References
Gompertz, B. (1825). On the Nature of the Function Expressive of the Law of Human Mortality, and on a New Mode of Determining the Value of Life Contingencies. Philosophical Transactions of the Royal Society of London, 115, 513-583.
Makeham, W. (1860). On the Law of Mortality and Construction of Annuity Tables. The Assurance Magazine and Journal of the Institute of Actuaries, 8(6), 301-310. doi:10.1017/S204616580000126X
Thiele, T. (1871). On a Mathematical Formula to express the Rate of Mortality throughout the whole of Life, tested by a Series of Observations made use of by the Danish Life Insurance Company of 1871. Journal of the Institute of Actuaries and Assurance Magazine, 16(5), 313-329. doi:10.1017/S2046167400043688
Oppermann, L. H. F. (1870). On the graduation of life tables, with special application to the rate of mortality in infancy and childhood. The Insurance Record Minutes from a meeting in the Institute of Actuaries, 42.
Wittstein, T. and D. Bumsted. (1883). The Mathematical Law of Mortality. Journal of the Institute of Actuaries and Assurance Magazine, 24(3), 153-173.
Steffensen, J. (1930). Infantile mortality from an actuarial point of view. Skandinavisk Aktuarietidskrift 13, 272-286. doi:10.1080/03461238.1930.10416902
Perks, W. (1932). On Some Experiments in the Graduation of Mortality Statistics. Journal of the Institute of Actuaries, 63(1), 12-57. doi:10.1017/S0020268100046680
Harper, F. S. (1936). An actuarial study of infant mortality. Scandinavian Actuarial Journal 1936 (3-4), 234-270. doi:10.1080/03461238.1936.10405113
Weibull, W. (1951). A statistical distribution function of wide applicability. Journal of applied mechanics 103, 293-297. doi:10.1115/1.4010337
Beard, R. E. (1971). Some aspects of theories of mortality, cause of death analysis, forecasting and stochastic processes. Biological aspects of demography 999, 57-68.
Vaupel, J., Manton, K.G., and Stallard, E. (1979). The impact of heterogeneity in individual frailty on the dynamics of mortality. Demography 16(3): 439-454. doi:10.2307/2061224
Siler, W. (1979), A Competing-Risk Model for Animal Mortality. Ecology, 60: 750-757. doi:10.2307/1936612
Heligman, L., & Pollard, J. (1980). The age pattern of mortality. Journal of the Institute of Actuaries, 107(1), 49-80. doi:10.1017/S0020268100040257
Rogers A and Planck F (1983). MODEL: A General Program for Estimating Parametrized Model Schedules of Fertility, Mortality, Migration, and Marital and Labor Force Status Transitions. IIASA Working Paper. IIASA, Laxenburg, Austria: WP-83-102
Martinelle S. (1987). A generalized Perks formula for old-age mortality. Stockholm, Sweden, Statistiska Centralbyran, 1987. 55 p. (R&D Report, Research-Methods-Development, U/STM No. 38)
Carriere J.F. (1992). Parametric models for life tables. Transactions of the Society of Actuaries. Vol.44
Kostaki A. (1992). A nine-parameter version of the Heligman-Pollard formula. Mathematical Population Studies. Vol. 3 277-288. doi:10.1080/08898489209525346
Thatcher AR, Kannisto V and Vaupel JW (1998). The force of mortality at ages 80 to 120. Odense Monographs on Population Aging Vol. 5, Odense University Press, 1998. 104, 20 p. Odense, Denmark
Tabeau E. (2001). A Review of Demographic Forecasting Models for Mortality. In: Tabeau E., van den Berg Jeths A., Heathcote C. (eds) Forecasting Mortality in Developed Countries. European Studies of Population, vol 9. Springer, Dordrecht. doi:10.1007/0-306-47562-6_1
Finkelstein M. (2012) Discussing the Strehler-Mildvan model of mortality Demographic Research, Vol. 26(9), 191-206. doi:10.4054/DemRes.2012.26.9
See Also
Examples
availableLaws()
Beard Model - 1971
Description
Beard Model - 1971
Usage
beard(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
beard(x = 50:100)
Makeham-Beard Model - 1971
Description
Makeham-Beard Model - 1971
Usage
beard_makeham(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
beard_makeham(x = 0:100)
Bring or Rename Starting Parameters in the Law Functions
Description
Bring or Rename Starting Parameters in the Law Functions
Usage
bring_parameters(law, par = NULL)
Arguments
law |
The name of the mortality law to be used (e.g., |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
Vector or initial model parameters
Carriere Mortality Law - 1992
Description
Carriere1 = weibull + invweibull + gompertz
Usage
carriere1(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
carriere1(x = 0:100)
Carriere Mortality Law - 1992
Description
Carriere2 = weibull + invgompertz + gompertz
Usage
carriere2(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
carriere2(x = 0:100)
Function to check input data in MortalityLaw
Description
Function to check input data in MortalityLaw
Usage
check.MortalityLaw(input)
Arguments
input |
A list containing all input arguments to |
Value
No return value, called for side effects
Check input ReadAHMD
Description
Check input ReadAHMD
Usage
check_input_ReadAHMD(x)
Arguments
x |
a list containing the input arguments from ReadAHMD function |
Value
No return value, called for checking stuff
Check input for ReadCHMD
Description
Check input for ReadCHMD
Usage
check_input_ReadCHMD(x)
Arguments
x |
A list with the input values for ReadCHMD |
Value
No return value, called for input validation
Check input ReadHMD
Description
Check input ReadHMD
Usage
check_input_ReadHMD(x)
Arguments
x |
a list containing the input arguments from ReadHMD function |
Value
No return value, called for validating input data
Check input ReadJMD
Description
Check input ReadJMD
Usage
check_input_ReadJMD(x)
Arguments
x |
a list containing the input arguments from ReadJMD function |
Value
No return value, called for validating input data
Run the optimisation routine
Description
This is the core optimisation function for MortalityLaw. It:
Subsets the data to the fitting ages (
fit.this.x).Scales the age vector if required by the chosen model.
Obtains default starting parameters (if not provided).
Minimises the objective function using
nlminb(PORT routines) with the parameters on the log scale.Transforms parameters back to the original scale, computes the fitted hazard, and derives goodness-of-fit measures (AIC, BIC, log-likelihood) where applicable.
Usage
choose_optim(input)
Arguments
input |
A list containing all input arguments to |
Value
A list with components:
x |
Age vector (original). |
new.x |
Age vector after optional scaling. |
opt |
Object returned by |
C |
Estimated parameters on the original scale. |
hx |
Fitted hazard values evaluated at |
logLik, AIC, BIC |
Goodness-of-fit measures ( |
Find ax[1:2] indicators using Coale-Demeny coefficients Here we adjust the first two values of ax to account for infant mortality more accurately
Description
Find ax[1:2] indicators using Coale-Demeny coefficients Here we adjust the first two values of ax to account for infant mortality more accurately
Usage
coale.demeny.ax(x, mx, ax, sex)
Arguments
x |
Numeric vector of ages at the beginning of each age interval.
For a full life table, use single-year ages (e.g., |
mx |
Age-specific death rate in the age interval |
ax |
Numeric vector representing the average number of person-years
lived in the age interval by those who die in that interval. If
|
sex |
Sex of the population. Options are |
Value
A vector of coefficients
Find ax indicator
Description
Find ax indicator
Usage
compute.ax(x, mx, qx)
Arguments
x |
Numeric vector of ages at the beginning of each age interval.
For a full life table, use single-year ages (e.g., |
mx |
Age-specific death rate in the age interval |
qx |
Probability of dying within the age interval |
Value
ax - the point in the age interval where 50
have already occurred
Convert Life Table Indicators
Description
Easily convert between different life table indicators (e.g., from death
rates mx to death probabilities qx, or from survivorship
lx to life expectancy ex). The function wraps
LifeTable internally, so the conversion relies on the
same constant-force-of-mortality (CFM) assumption and life-table
methodology used throughout the package.
Usage
convertFx(x, data, from, to, ...)
Arguments
x |
Numeric vector of ages at the beginning of each age interval.
For a full life table, use single-year ages (e.g., |
data |
A numeric |
from |
The type of indicator supplied in |
to |
The desired output indicator. One of:
|
... |
Further arguments passed to |
Details
This function provides a convenient interface for converting a single
mortality indicator into another, without having to call
LifeTable directly and extract the desired column.
The supported input types (from) are:
mx, qx, dx, and lx.
The supported output types (to) are:
mx, qx, dx, lx, Lx, Tx, and
ex.
There are 28 possible from-to combinations (4 inputs
\times 7 outputs). All conversions pass through the full life-table
computation; for example, converting mx to ex will
internally compute qx, lx, dx, Lx, and
Tx in sequence.
When data is a vector, the function returns a named vector.
When data is a matrix or data.frame with multiple
columns, the function applies the conversion column-wise and returns a
matrix with the same row and column names as the input.
Value
A numeric vector or matrix containing the converted life table indicator. If the input was a named object, the output retains those names.
Author(s)
Marius D. Pascariu
See Also
LifeTable for the underlying life-table construction;
LawTable for generating life tables from parametric
mortality laws.
Examples
# ---- Basic conversions ----
x <- 0:110
mx <- ahmd$mx
# Convert death rates to death probabilities
qx <- convertFx(x, data = mx, from = "mx", to = "qx")
# Convert death rates to death distribution
dx <- convertFx(x, data = mx, from = "mx", to = "dx")
# Convert death rates to survivorship
lx <- convertFx(x, data = mx, from = "mx", to = "lx")
# ---- All 28 possible conversions ----
from <- c("mx", "qx", "dx", "lx")
to <- c("mx", "qx", "dx", "lx", "Lx", "Tx", "ex")
K <- expand.grid(from = from, to = to)
for (i in 1:nrow(K)) {
In <- as.character(K[i, "from"])
Out <- as.character(K[i, "to"])
N <- paste0(Out, "_from_", In)
cat(i, " Create", N, "\n")
assign(N, convertFx(x = x, data = get(In), from = In, to = Out))
}
Data formats
Description
Data formats
Usage
data_format()
Value
a vector
deviance function for MortalityLaw
Description
deviance function for MortalityLaw
Usage
## S3 method for class 'MortalityLaw'
deviance(object, ...)
Arguments
... |
further arguments passed to or from other methods. |
Value
model deviance value
df.residual function for MortalityLaw
Description
df.residual function for MortalityLaw
Usage
## S3 method for class 'MortalityLaw'
df.residual(object, ...)
Arguments
... |
further arguments passed to or from other methods. |
Value
model residual value
dx to lx
Description
Function to convert dx into lx and back
Usage
dx_lx(ux, out = c("dx", "lx"))
Arguments
ux |
A vector of dx or lx data. |
out |
Type of the output: dx or lx. |
Value
A vector containing dx or lx values
Function that identifies the case/problem we have to solve
Description
Function that identifies the case/problem we have to solve
Usage
find.my.case(Dx = NULL, Ex = NULL, mx = NULL, qx = NULL, lx = NULL, dx = NULL)
Arguments
Dx |
Death counts. Each element represents the total number of
deaths during the calendar year to persons aged |
Ex |
Exposure-to-risk in the period. This is usually approximated
by the mid-year population aged |
mx |
Age-specific death rate in the age interval |
qx |
Probability of dying within the age interval |
lx |
Probability of surviving to exact age |
dx |
Number of deaths in the life-table population occurring in
the age interval |
Value
A list containing problem solving details
Gamma-Gompertz Model as in Vaupel et al. (1979)
Description
Gamma-Gompertz Model as in Vaupel et al. (1979)
Usage
ggompertz(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
ggompertz(x = 50:120)
Gompertz Mortality Law - 1825
Description
Gompertz Mortality Law - 1825
Usage
gompertz(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
gompertz(x = 45:90)
Gompertz Mortality Law - informative parameterization
Description
Gompertz Mortality Law - informative parameterization
Usage
gompertz0(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
gompertz0(x = 45:90)
Summary function - display head and tail in a single data.frame The original code for this function was first written for 'psych' R package here we have modified it a bit
Description
Summary function - display head and tail in a single data.frame The original code for this function was first written for 'psych' R package here we have modified it a bit
Usage
head_tail(x, hlength = 4, tlength = 4, digits = 4, ellipsis = TRUE)
Arguments
x |
A matrix or data frame or free text |
hlength |
The number of lines at the beginning to show |
tlength |
The number of lines at the end to show |
digits |
Round off the data to digits |
ellipsis |
separate the head and tail with dots |
Value
Print table's head and tail
Inverse-Gompertz Mortality Law - informative parameterization
Description
m - is a measure of location because it is the mode of the density, m > 0 sigma - represents the dispersion of the density about the mode, sigma > 0
Usage
invgompertz(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
invgompertz(x = 15:25)
Inverse-Weibull Mortality Law
Description
The Inverse-Weibull proves useful for modelling the childhood and teenage years, because the logarithm of h(x) is a concave function. m > 0 is a measure of location sigma > 0 is measure of dispersion
Usage
invweibull(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
invweibull(x = 1:20)
Kannisto Mortality Law - 1998
Description
Kannisto Mortality Law - 1998
Usage
kannisto(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
kannisto(x = 85:120)
Kannisto-Makeham Mortality Law - 1998
Description
Kannisto-Makeham Mortality Law - 1998
Usage
kannisto_makeham(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
kannisto_makeham(x = 85:120)
Kostaki Model - 1992
Description
Kostaki Model - 1992
Usage
kostaki(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
kostaki(x = 0:100)
logLik function for MortalityLaw
Description
logLik function for MortalityLaw
Usage
## S3 method for class 'MortalityLaw'
logLik(object, ...)
Arguments
... |
further arguments passed to or from other methods. |
Value
Model log-likelihood value
Make HTTP request
Description
Make HTTP request
Usage
make_http_request(url)
Arguments
url |
URL |
Value
url response
Makeham Mortality Law - 1860
Description
Makeham Mortality Law - 1860
Usage
makeham(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
makeham(x = 45:90)
Makeham Mortality Law - informative parameterization
Description
Makeham Mortality Law - informative parameterization
Usage
makeham0(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
makeham0(x = 45:90)
Martinelle Model - 1987
Description
Martinelle Model - 1987
Usage
martinelle(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
martinelle(x = 0:100)
mx to qx
Description
Function to convert mx into qx and back, using the constant force of mortality assumption (CFM).
Usage
mx_qx(x, nx, ux, out = c("qx", "mx"))
Arguments
x |
Numeric vector of ages at the beginning of each age interval.
For a full life table, use single-year ages (e.g., |
nx |
Length of the age-intervals. |
ux |
A vector of mx or qx. |
out |
Type of the output: mx or qx. |
Value
A vector of rates
Objective function to minimise during optimisation
Description
Given a set of parameters (on the log scale), this function evaluates the chosen loss function or negative log-likelihood by comparing observed mortality values (Dx/Ex, mx, or qx) against the hazard rates predicted by the specified mortality law.
Usage
objective_fun(par, x, Dx, Ex, mx, qx, law, opt.method, custom.law)
Arguments
par |
Parameter vector on the log scale. |
x |
Numeric vector of ages at the beginning of each age interval.
For a full life table, use single-year ages (e.g., |
Dx |
Death counts. Each element represents the total number of
deaths during the calendar year to persons aged |
Ex |
Exposure-to-risk in the period. This is usually approximated
by the mid-year population aged |
mx |
Age-specific death rate in the age interval |
qx |
Probability of dying within the age interval |
law |
The name of the mortality law to be used (e.g., |
opt.method |
The function to optimise. Available options:
See |
custom.law |
A user-defined function for fitting a model not included
in the package. The function must accept arguments |
Details
Parameters are transformed back to the original scale via exp(par)
when calling the mortality law function. Infinite hazard values are capped
to 1, and large penalties are applied for missing or out-of-range values
to guide the optimiser away from invalid regions.
Value
A scalar loss value to be minimised.
Opperman Mortality Law - 1870
Description
Opperman Mortality Law - 1870
Usage
opperman(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
opperman(x = 1:25)
Perks Model - 1932
Description
Perks Model - 1932
Usage
perks(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
perks(x = 50:100)
Plot Method for MortalityLaw
Description
Plot Method for MortalityLaw
Usage
## S3 method for class 'MortalityLaw'
plot(x, ...)
Arguments
x |
An object of class |
... |
Further arguments passed to graphical methods, such as
parameters (see |
Value
A plot is generated as a side effect.
Author(s)
Marius D. Pascariu
See Also
Examples
# See complete example in MortalityLaw help page
Predict function for MortalityLaw
Description
Predict function for MortalityLaw
Usage
## S3 method for class 'MortalityLaw'
predict(object, x, ...)
Arguments
object |
An object of class |
x |
Vector of ages to be considered in prediction |
... |
Additional arguments affecting the predictions produced. |
Value
A vector of predicted hazard rates
Author(s)
Marius D. Pascariu
See Also
Examples
# Extrapolate old-age mortality with the Kannisto model
# Fit ages 80-94 and extrapolate up to 120.
Mx <- ahmd$mx[paste(80:94), "1950"]
M1 <- MortalityLaw(x = 80:94, mx = Mx, law = 'kannisto')
fitted(M1)
predict(M1, x = 80:120)
# See more examples in MortalityLaw function help page.
Print LifeTable
Description
Print LifeTable
Usage
## S3 method for class 'LifeTable'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments passed to or from other methods. |
Value
Print data on the console
Print MortalityLaw
Description
Print MortalityLaw
Usage
## S3 method for class 'MortalityLaw'
print(x, ...)
Arguments
x |
an object of class |
... |
further arguments passed to or from other methods. |
Value
Print data on console
Print ReadCHMD
Description
Print ReadCHMD
Usage
## S3 method for class 'ReadAHMD'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments passed to or from other methods. |
Value
Print data on console
Print ReadCHMD
Description
Print ReadCHMD
Usage
## S3 method for class 'ReadCHMD'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments passed to or from other methods. |
Value
Print data on the console
Print ReadHMD
Description
Print ReadHMD
Usage
## S3 method for class 'ReadHMD'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments passed to or from other methods. |
Value
Print data on the console
Print ReadJMD
Description
Print ReadJMD
Usage
## S3 method for class 'ReadJMD'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments passed to or from other methods. |
Value
Print info on the console
Print availableLF
Description
Print availableLF
Usage
## S3 method for class 'availableLF'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments passed to or from other methods. |
Value
print info on the console
Print availableLaws
Description
Print availableLaws
Usage
## S3 method for class 'availableLaws'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments passed to or from other methods. |
Value
print info on the console
Print summary.MortalityLaw
Description
Print summary.MortalityLaw
Usage
## S3 method for class 'summary.MortalityLaw'
print(x, ...)
Arguments
x |
an object of class |
... |
additional arguments affecting the summary produced. |
Value
Print data on console
Quadratic Model
Description
Quadratic Model
Usage
quadratic(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
quadratic(x = 0:100)
Rogers-Planck Model - 1983
Description
Rogers-Planck Model - 1983
Usage
rogersplanck(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
rogersplanck(x = 0:100)
Print message when saving an object
Description
Print message when saving an object
Usage
saveMsg()
Value
No return value, called for side effects
Save Output in the working directory
Description
Save Output in the working directory
Usage
saveOutput(out, show, prefix)
Arguments
out |
Output file |
show |
Choose whether to display a progress bar. Logical.
Default: |
Value
No return value, called for side effects
Scale the age vector for stable optimisation
Description
For mortality laws that cover only a portion of the lifespan (e.g., adult or old-age mortality), the age vector is rescaled so that the minimum age becomes 1. This improves numerical stability by keeping the exponentiated terms in the hazard function within a reasonable range.
Usage
scale_x(x)
Arguments
x |
A numeric vector of ages. |
Value
A numeric vector of scaled ages, where min(x) == 1.
Siler Mortality Law - 1979
Description
Siler Mortality Law - 1979
Usage
siler(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
siler(x = 0:100)
Strehler-Mildvan Model - 1960
Description
Strehler-Mildvan Model - 1960
Usage
strehler_mildvan(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
strehler_mildvan(x = 30:85)
Extracting the last n characters from a string
Description
Extracting the last n characters from a string
Usage
substrRight(x, n)
Arguments
x |
a string |
n |
number of characters |
Value
A character vector of length n
Summary MortalityLaw
Description
Summary MortalityLaw
Usage
## S3 method for class 'MortalityLaw'
summary(object, ..., digits = max(3L, getOption("digits") - 3L))
Arguments
object |
an object of class |
... |
additional arguments affecting the summary produced. |
digits |
number of digits to display. |
Value
A list of model diagnosis
Thiele Mortality Law - 1871
Description
Thiele Mortality Law - 1871
Usage
thiele(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
thiele(x = 0:100)
Educate mx or qx on how to behave above age 100 if it gets in trouble (with NA's, zero's and Inf)
Description
Educate mx or qx on how to behave above age 100 if it gets in trouble (with NA's, zero's and Inf)
Usage
uxAbove100(x, ux, omega = 100, verbose = FALSE)
Arguments
x |
Numeric vector of ages at the beginning of each age interval.
For a full life table, use single-year ages (e.g., |
ux |
A vector of mx or qx. |
omega |
Threshold age. Default: 100. |
verbose |
A logical value. Set |
Value
A vector of rates
Van der Maen Model - 1943
Description
Van der Maen Model - 1943
Usage
vandermaen(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
vandermaen(x = 0:100)
Van der Maen 2 Model - 1943
Description
Van der Maen 2 Model - 1943
Usage
vandermaen2(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
vandermaen(x = 0:100)
Weibull Mortality Law - 1939
Description
Note that if sigma > m, then the mode of the density is 0 and hx is a non-increasing function of x, while if sigma < m, then the mode is greater than 0 and hx is an increasing function. m > 0 is a measure of location sigma > 0 is measure of dispersion
Usage
weibull(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
weibull(x = 1:20)
Wittstein Mortality Law - 1883
Description
Wittstein Mortality Law - 1883
Usage
wittstein(x, par = NULL)
Arguments
x |
vector of age at the beginning of the age classes |
par |
parameters of the selected model. If NULL the default values will be assigned automatically. |
Value
A list of rates and model parameters
Examples
wittstein(x = 0:100)