| Title: | Methods for Demographic Analysis |
|---|---|
| Description: | Implements life tables, fertility and mortality indicators, decomposition methods, Lee-Carter mortality forecasting, Leslie matrices, and population pyramids for demographic analysis. Methods are described in Preston et al. (2001, ISBN:1557864519) and Ustyuzhanin (2025) <doi:10.17323/demreview.v12i4.30415>. |
| Authors: | Vadim Ustyuzhanin [aut, cre] (ORCID: <https://orcid.org/0000-0003-3800-1108>) |
| Maintainer: | Vadim Ustyuzhanin <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.10 |
| Built: | 2026-05-27 22:38:41 UTC |
| Source: | https://github.com/vadvu/demor |
Split continuous ages to age groups
ages(x, groups, char = FALSE, below_min_val = NA)ages(x, groups, char = FALSE, below_min_val = NA)
x |
Numeric array. Values of age that should be grouped |
groups |
Numeric array. Values of lower boundaries of age groups |
char |
Logical. Should output be numeric ( |
below_min_val |
What value to return for x < min(groups) when char = |
If char = TRUE, a factor of the same length as x with age-group
labels. Otherwise, a numeric vector of the same length as x with the
lower boundaries from groups; values below the first group receive
below_min_val.
groups <- c(0, 1, 5, 10, 15, 20, 24, 45, 85) x <- 0:100 ages(x, groups, TRUE)groups <- c(0, 1, 5, 10, 15, 20, 24, 45, 85) x <- 0:100 ages(x, groups, TRUE)
Associated single decrement life table (ASDT) for causes of death (cause-deleted life table)
asdt(age, m_all, m_i, full = FALSE, method = "chiang1968", ...)asdt(age, m_all, m_i, full = FALSE, method = "chiang1968", ...)
age |
Numeric array of age intervals; for full life table = |
m_all |
Numeric array with age specific mortality rates of all causes of death (usual mx). |
m_i |
Numeric array with age specific mortality rates of some cause of death (i) |
full |
Logical. Is full table needed? |
method |
Character. The method of ASDT construction to use. Now just "chiang1968" is supported. |
... |
Optional. Additional arguments for |
If full = TRUE, a data frame with the full associated single
decrement life table, including the standard life-table columns and the
cause-deleted columns r_not_i, p_not_i, l_not_i, a_not_i,
d_not_i, L_not_i, T_not_i, and ex_without_i. If full = FALSE, a
reduced data frame with columns age, r_not_i, lx, qx, ax, ex,
p_not_i, l_not_i, a_not_i, and ex_without_i.
Chiang, L. (1968). Introduction to Stochastic Processes in Biostatistics. New York: John Wiley and Sons.
data(asdtex) asdt( age = asdtex$age, m_all = asdtex$all, m_i = asdtex$circulatory )[1:3, ]data(asdtex) asdt( age = asdtex$age, m_all = asdtex$all, m_i = asdtex$circulatory )[1:3, ]
Data on mortality of US men in 2002 by some causes
asdtexasdtex
age
age specific mortality rate (asmr) from Neoplasms
asmr from Diseases of the circulatory system
asmr from Diseases of the respiratory system
asmr from Diseases of the digestive system
asmr from other causes
overall asmr
Andreev & Shkolnikov spreadsheet, can be seen on this webpage
Cohort Component Model for Projecting Population.
ccm( Mx.f, Mx.m = NULL, Fx, Ix.f = NULL, Ix.m = NULL, age.mx, age.fx, N0.f, N0.m = NULL, srb = 100/205, ... )ccm( Mx.f, Mx.m = NULL, Fx, Ix.f = NULL, Ix.m = NULL, age.mx, age.fx, N0.f, N0.m = NULL, srb = 100/205, ... )
Mx.f |
Matrix or dataframe with mx for females, where row represents age, column represents a forecasted period. Thus, first column should be the first projected period, while each row represents age-specific mortality rate. |
Mx.m |
Optional. Matrix or dataframe with mx for males, where row represents age, column represents a forecasted period. Thus, first column should be the first projected period, while each row represents age-specific mortality rate. |
Fx |
Matrix or dataframe with fx, where row represents age, column represents a forecasted period. Thus, first column should be the first projected period, while each row represents age-specific fertility rate. |
Ix.f |
Optional. Matrix or dataframe with net number of female migrants, where row represents age, column represents a forecasted period. Thus, first column should be the first projected period, while each row represents net number of migrants. |
Ix.m |
Optional. Matrix or dataframe with net number of male migrants, where row represents age, column represents a forecasted period. Thus, first column should be the first projected period, while each row represents net number of migrants. |
age.mx |
Numeric vector. Age groups for Mx.f rows. |
age.fx |
Numeric vector. Age groups for Fx rows. |
N0.f |
Numeric vector. Female population in the initial period by age groups. |
N0.m |
Optional. Numeric vector. Male population in the initial period by age groups. |
srb |
Numeric. Sex ratio at birth for females. By default, it is 100/205. |
... |
Optional. Additional arguments for |
The model is calculated in matrix form as
where is a column vector of population for time with as a step of projection (it is the length of age interval), is Leslie matrix and is a column vector of net migration.
Note that the model assumes that in all age intervals are the same (i.e. is not permitted). Fortunately (and thanks to me), the function handles such situations automatically by transforming all age groups into a unified standard.
If Mx.m is NULL, a numeric matrix with projected female
population, where rows are age groups and columns are periods 0:h. If
male mortality is supplied, a list with matrices female, male, and
all, each with the same row/column structure.
age.mx <- seq(0, 80, 5) age.fx <- seq(15, 45, 5) Mx.f <- matrix( rep(seq(0.005, 0.12, length.out = length(age.mx)), 2), nrow = length(age.mx), ncol = 2 ) Fx <- matrix( rep(c(0.02, 0.08, 0.11, 0.09, 0.05, 0.02, 0.005), 2), nrow = length(age.fx), ncol = 2 ) N0.f <- round(100000 * exp(-0.04 * age.mx)) ccm(Mx.f = Mx.f, Fx = Fx, age.mx = age.mx, age.fx = age.fx, N0.f = N0.f)age.mx <- seq(0, 80, 5) age.fx <- seq(15, 45, 5) Mx.f <- matrix( rep(seq(0.005, 0.12, length.out = length(age.mx)), 2), nrow = length(age.mx), ncol = 2 ) Fx <- matrix( rep(c(0.02, 0.08, 0.11, 0.09, 0.05, 0.02, 0.005), 2), nrow = length(age.fx), ncol = 2 ) N0.f <- round(100000 * exp(-0.04 * age.mx)) ccm(Mx.f = Mx.f, Fx = Fx, age.mx = age.mx, age.fx = age.fx, N0.f = N0.f)
Age decomposition of mortality: single decrement process
decomp(mx1, mx2, sex = "m", age, method = "andreev", ax1 = NULL, ax2 = NULL)decomp(mx1, mx2, sex = "m", age, method = "andreev", ax1 = NULL, ax2 = NULL)
mx1 |
Numeric array with age specific mortality rates of population 1 (base population). |
mx2 |
Numeric array with age specific mortality rates of population 2 (compared population). |
sex |
Character. Sex. "m" for males and "f" for females. By default, |
age |
Numeric array of age intervals; for full life table = |
method |
Character. Decomposition method. "andreev" (1982), "arriaga" (1984) or "pollard" (1982) - slightly different in their results. By default, |
ax1 |
Optional. Numeric array with ax for the 1st population. By default, it is a the middle of the interval, while ax for age 0 is modeled as in Andreev & Kingkade (2015). |
ax2 |
Optional. Numeric array with ax for the 2nd population. By default, it is a the middle of the interval, while ax for age 0 is modeled as in Andreev & Kingkade (2015). |
Example of decomposition using Andreev (1982) formulas:
where is an absolute contribution of age to difference in between the second and the first population. are life table functions for population . is the last age group. Note,
A data frame with one row per age group. It always contains age,
ex12, and ex12_prc, where ex12 is the absolute age contribution to
the life-expectancy difference and ex12_prc is the percentage
contribution. Additional columns depend on method and contain
intermediate life-table quantities used in the decomposition.
Arriaga, E. E. (1984). Measuring and explaining the change in life expectancies. Demography, 21, 83-96.
Andreev, E. M. (1982). Metod komponent v analize prodolzhitel'nosti zhizni. Vestnik statistiki, 9, 42-47.
Pollard, J. H. (1982). The expectation of life and its relationship to mortality. Journal of the Institute of Actuaries, 109(2), 225–240.
mdecomp() for age and cause decomposition
age <- 0:5 mx1 <- c(0.02, 0.01, 0.012, 0.015, 0.02, 0.03) mx2 <- c(0.018, 0.009, 0.011, 0.014, 0.019, 0.028) decomp(mx1, mx2, age = age)$ex12age <- 0:5 mx1 <- c(0.02, 0.01, 0.012, 0.015, 0.02, 0.03) mx2 <- c(0.018, 0.009, 0.011, 0.014, 0.019, 0.028) decomp(mx1, mx2, age = age)$ex12
e-dagger
edagger(age, mx, ...)edagger(age, mx, ...)
age |
Numeric array of age intervals |
mx |
Numeric array with age specific mortality rates. |
... |
Optional. Additional arguments for |
A named numeric vector of the same length as age, where each
element is e^\dagger_x, the average remaining life years lost because of
death from age x onward.
age <- 0:5 mx <- c(0.02, 0.01, 0.012, 0.015, 0.02, 0.03) edagger(age, mx)[1:3]age <- 0:5 mx <- c(0.02, 0.01, 0.012, 0.015, 0.02, 0.03) edagger(age, mx)[1:3]
Fertility models for ASFR approximation
fert.approx(fx, age, model, start = NULL, se = FALSE, alpha = 0.05, bn = 1000)fert.approx(fx, age, model, start = NULL, se = FALSE, alpha = 0.05, bn = 1000)
fx |
Numeric vector of age specific fertility rates. |
age |
Numeric vector of ages. |
model |
Character. Model name to be estimated. Now "Hadwiger", "Gamma", "Brass" and "Beta" are supported. |
start |
Numeric vector with user-specific values of parameters for optimization. Default is |
se |
Logical. Should bootstrapped variance for ASFR approximation be calculated. Default is |
alpha |
Numeric. Used if |
bn |
Numeric. Used if |
This function runs least squares optimization (using default optim) of the selected fertility function with 1e-06 as tolerance parameter.
is age-specific fertility rate for age .
The model is as follows:
where are estimated parameters that do not have demographic interpretation. Sometimes is interpreted as mean age at childbearing.
The model is as follows:
where are estimated parameters. is gamma function. can be interpreted as fertility level (TFR) and as mean age at childbearing.
The model is as follows:
where are estimated parameters.
The model is as follows:
where is beta function, are estimated parameters, which can be interpreted as fertility level (TFR) and max and min age of childbearing respectively.
are
where are estimated parameters, where can be interpreted as mean age at childbearing. Thus, Beta model uses 5 parameters , where only has no demographic interpretation.
A list with two components: model, a list describing the fitted
fertility model (type, fitted params, rmse, and, if se = TRUE,
bootstrap covmat and parameter percentile intervals prc); and
predicted, a data frame with observed and fitted age-specific fertility
rates. When se = TRUE, predicted also includes bootstrap standard
errors and percentile intervals.
Peristera, P., & Kostaki, A. (2007). Modeling fertility in modern populations. Demographic Research, 16, 141-194.
age <- seq(15, 45, 5) fx <- c(0.03, 0.10, 0.14, 0.12, 0.07, 0.03, 0.01) fert.approx(fx = fx, age = age, model = "Hadwiger", se = FALSE)age <- seq(15, 45, 5) fx <- c(0.03, 0.10, 0.14, 0.12, 0.07, 0.03, 0.01) fert.approx(fx = fx, age = age, model = "Hadwiger", se = FALSE)
Download age-specific mortality, fertility, and population data from the
Russian Fertility and Mortality Database (RosBris) and return them as
long-format data frames for use in demor.
get_rosbris( dataset = c("mortality_1", "mortality_5", "fertility_1", "fertility_5"), refresh = FALSE )get_rosbris( dataset = c("mortality_1", "mortality_5", "fertility_1", "fertility_5"), refresh = FALSE )
dataset |
Character. Dataset to download and parse. One of
|
refresh |
Logical. If |
The function downloads official .zip archives from the RosBris website,
stores them in a user cache directory created by tools::R_user_dir(), reads
.txt tables from the archives, and converts them to long-format data frames.
Returned data have the following structure:
"mortality_1": year, code, territory, sex, age, mx, N,
Dx, name.
"mortality_5": year, code, territory, sex, age, mx, N,
Dx, name.
"fertility_1": year, code, territory, age, fx, N, Bx,
name.
"fertility_5": year, code, territory, age, fx, fx1, fx2,
fx3, fx4, fx5, N, Bx, Bx1, Bx2, Bx3, Bx4, Bx5,
name.
At the moment, get_rosbris() uses the legacy RosBris series corresponding
to the periods 1989-2014 and 2015-2022. Updated post-census series are
not used by this function.
A data frame with one row per year-region-age combination. Column
structure depends on dataset; see Details.
Russian Fertility and Mortality Database. Center for Demographic Research, Moscow (Russia). Available at https://www.nes.ru/research-main/research-centers/demogr/demogr-fermort-data
if (interactive()) { mort <- get_rosbris("mortality_5") rus2010 <- subset( mort, year == 2010 & code == 1100 & sex == "m" & territory == "t" ) head(rus2010) }if (interactive()) { mort <- get_rosbris("mortality_5") rus2010 <- subset( mort, year == 2010 & code == 1100 & sex == "m" & territory == "t" ) head(rus2010) }
Gini coefficient of a life table
gini(age, mx, ...)gini(age, mx, ...)
age |
Numeric array of age intervals |
mx |
Numeric array with age specific mortality rates. |
... |
Optional. Additional arguments for |
A list with two components: Gini, itself a list with the relative
Gini coefficient G0 and the absolute Gini coefficient G0_abs; and
plot, a data frame with columns Fx and Phix for drawing the Lorenz
curve.
age <- 0:5 mx <- c(0.02, 0.01, 0.012, 0.015, 0.02, 0.03) gini(age, mx)$Giniage <- 0:5 mx <- c(0.02, 0.01, 0.012, 0.015, 0.02, 0.03) gini(age, mx)$Gini
The Human Life Indicator (HLI)
hli(age, mx, ...)hli(age, mx, ...)
age |
Numeric array of age intervals; for full life table = |
mx |
Numeric array with age specific mortality rates. |
... |
Optional. Additional arguments for |
It is calculated as
where are the first and last age groups, is age, are life table functions (s.t. ).
A length-1 numeric value giving the Human Life Indicator, i.e. the geometric mean age at death implied by the life table.
Ghislandi, S., Sanderson, W.C., & Scherbov, S. (2019). A Simple Measure of Human Development: The Human Life Indicator. Population and Development Review, 45, 219–233.
age <- 0:5 mx <- c(0.02, 0.01, 0.012, 0.015, 0.02, 0.03) hli(age, mx)age <- 0:5 mx <- c(0.02, 0.01, 0.012, 0.015, 0.02, 0.03) hli(age, mx)
Lee-Carter model
leecart( data, n = 10, alpha = 0.05, model = "RWwD", ax_method = "classic", bx_method = "classic", boot = FALSE, bn = 1000, ktadj = "none", ... )leecart( data, n = 10, alpha = 0.05, model = "RWwD", ax_method = "classic", bx_method = "classic", boot = FALSE, bn = 1000, ktadj = "none", ... )
data |
Dataframe in the long format with the following columns: |
n |
Numeric. Forecasted horizon |
alpha |
Numeric. The level of uncertainty. By default, |
model |
Character. Model type for kt forecasting. Can be "RWwD" for random walk with drift (by default, for original Lee-Carter model) or "ARIMA" for ARIMA model which parameters are chosen automatically by |
ax_method |
Character. Method for ax calculation. Can be "classic" from original Lee-Carter model (by default), "last" or "last_smooth". See details. |
bx_method |
Character. Method for bx calculation. Can be "classic" from original Lee-Carter model (by default) and "rotate" for rotating bx (Li et al., 2013). |
boot |
Logical. Should bootstrap estimates for uncertainty be used? |
bn |
Numeric. Used if |
ktadj |
Character. Type of |
... |
Optional. Additional arguments for |
The model argument specifies the forecasting method.
model ="RWwD" – classic random walk option
model = "ARIMA" for selecting a more complex time series model
The ax_method argument allows to control how a_x is calculated.
ax_method = "classic" – classic option with the average of the logarithm of mortality rates (but there is so-called "jump-off bias").
ax_method = "last" uses the logarithm of mortality for the last available year (as proposed in Lee & Miller, 2001).
ax_method = "last_smooth" uses data for the last year with smoothing (see Ševčíková et al., 2016, p. 288).
The bx_method argument allows to control how b_x is calculated.
bx_method = "classic" for the original method.
bx_method = "rotate" for the rotational variant (see Li et al., 2013).
The ktadj argument allows to control how k_t is calculated.
ktadj = "none" for no adjustment.
ktadj = "Dmin" for minimizing the deviance of predicted/actual annual deaths (as proposed in the original Lee-Carter paper). This method requires data on the age-specific number of deaths (Dx column in the data) and the age-specific population (N column in the data).
ktadj = "e0min" for minimizing the deviance of predicted/actual life expectancy (as proposed in Lee & Miller, 2001).
ktadj = "poisson" for minimizing the deviance from a Poisson model, where the dependent variable is the age-specific annual number of deaths (as proposed in Booth et al., 2002). This method requires data on the age-specific number of deaths (Dx column in the data) and the age-specific population (N column in the data).
ktadj = "edaggermin" for minimizing the deviance of predicted/actual edagger (see edagger()) as proposed in Rabbi & Mazzuco, 2021.
A list with four components: model, the fitted time-series model
used to forecast kt; kt, a data frame with historical and forecast
mortality index values and confidence intervals; ex0, a data frame with
observed, fitted, and forecast life expectancy at birth and confidence
intervals; and mx, a data frame with observed, fitted, and forecast
age-specific mortality rates and confidence intervals.
Booth, H., Maindonald, J., & Smith, L. (2002). Applying Lee-Carter under conditions of variable mortality decline. Population Studies, 56(3), 325-336. doi:10.1080/00324720215935
Lee, R. D., & Carter, L. R. (1992). Modeling and forecasting US mortality. Journal of the American Statistical Association, 87(419), 659–671. doi:10.1080/01621459.1992.10475265
Lee, R., & Miller, T. (2001). Evaluating the performance of the Lee-Carter method for forecasting mortality. Demography, 38(4), 537–549. doi:10.1353/dem.2001.0036
Li, N., Lee, R., & Gerland, P. (2013). Extending the Lee-Carter Method to Model the Rotation of Age Patterns of Mortality Decline for Long-Term Projections. Demography, 50(6), 2037–2051. doi:10.1007/s13524-013-0232-2
Rabbi, A. M. F., & Mazzuco, S. (2021). Mortality forecasting with the Lee-Carter method: Adjusting for smoothing and lifespan disparity. European Journal of Population, 37(1), 97-120. doi:10.1007/s10680-020-09559-9
Ševčíková, H., Li, N., Kantorová, V., Gerland, P., & Raftery, A. E. (2016). Age-Specific Mortality and Fertility Rates for Probabilistic Population Projections. In R. Schoen (Ed.), Dynamic Demographic Analysis (Vol. 39, pp. 285–310). Springer International Publishing. doi:10.1007/978-3-319-26603-9_15
age <- 0:20 year <- 2000:2009 lc_data <- expand.grid(age = age, year = year) lc_data$mx <- exp(-7 + 0.09 * lc_data$age - 0.02 * (lc_data$year - min(year))) fit <- leecart(lc_data, n = 2) head(fit$kt)age <- 0:20 year <- 2000:2009 lc_data <- expand.grid(age = age, year = year) lc_data$mx <- exp(-7 + 0.09 * lc_data$age - 0.02 * (lc_data$year - min(year))) fit <- leecart(lc_data, n = 2) head(fit$kt)
Leslie Matrix
leslie(mx, fx, age.mx, age.fx, srb = 100/205, fin = TRUE, ...)leslie(mx, fx, age.mx, age.fx, srb = 100/205, fin = TRUE, ...)
mx |
Numeric array of age specific mortality rates. |
fx |
Numeric array of age specific fertility rates. |
age.mx |
Numeric array of ages for mx. |
age.fx |
Numeric array of ages for fx. |
srb |
Numeric. Sex ratio at birth. Usually it is assumed that for males it is |
fin |
Logical. Should the survival rate for the last age-group be nonzero? By default it is |
... |
Optional. Additional arguments for |
A square numeric matrix of class leslie with one row and one
column per age group. The first row contains fertility contributions and
the subdiagonal contains survival ratios.
summary.leslie() for leslie output that calculates , , and .
mx <- c(0.02, 0.01, 0.012, 0.015, 0.02) fx <- c(0.05, 0.08) leslie(mx = mx, fx = fx, age.mx = 0:4, age.fx = 1:2)mx <- c(0.02, 0.01, 0.012, 0.015, 0.02) fx <- c(0.05, 0.08) leslie(mx = mx, fx = fx, age.mx = 0:4, age.fx = 1:2)
Life table
LT(age, sex = "m", mx, ax = NULL, w = NULL, l0 = 1)LT(age, sex = "m", mx, ax = NULL, w = NULL, l0 = 1)
age |
Numeric array of age intervals; for full life table = |
sex |
Character. Sex. |
mx |
Numeric array with age specific mortality rates. |
ax |
Optional. Numeric array with ax. By default, it is the middle of the interval, while ax for age 0 is modeled as in Andreev & Kingkade (2015). |
w |
Optional. Numeric array with weights for each age interval for calculating weighted life expectancy ( |
l0 |
Numeric. Life table radix. By default, = |
By default, for age 0 (first entity in ax) is modeled as in Andreev & Kingkade (2015, p. 390, see table 3-2).
The weighted life expectancy is calculated as follows:
where is the last age, is weight s.t. , and other variables are life table functions.
A numeric matrix with one row per age group. Standard columns are
age, mx, ax, qx, lx, dx, Lx, Tx, and ex. If w is
supplied, additional columns w, wLx, and wex are appended, where
wex is weighted life expectancy.
Andreev, E. M., & Kingkade, W. W. (2015). Average age at death in infancy and infant mortality level: Reconsidering the Coale-Demeny formulas at current levels of low mortality. Demographic Research, 33, 363-390.
MLT() for Multiple Decrement Life Table.
# Minimal toy example age <- 0:5 mx <- c(0.02, 0.01, 0.012, 0.015, 0.02, 0.03) LT(age = age, sex = "m", mx = mx) if (interactive()) { # Real RosBris data via get_rosbris(): Russian males, 2010 rus2010 <- subset(get_rosbris("mortality_5"), year == 2010 & code == 1100 & sex == "m" & territory == "t" ) LT(age = rus2010$age, sex = "m", mx = rus2010$mx) }# Minimal toy example age <- 0:5 mx <- c(0.02, 0.01, 0.012, 0.015, 0.02, 0.03) LT(age = age, sex = "m", mx = mx) if (interactive()) { # Real RosBris data via get_rosbris(): Russian males, 2010 rus2010 <- subset(get_rosbris("mortality_5"), year == 2010 & code == 1100 & sex == "m" & territory == "t" ) LT(age = rus2010$age, sex = "m", mx = rus2010$mx) }
Mean Age at Childbearing (MAC)
mac(fx, age)mac(fx, age)
fx |
Numeric array of age specific fertility rates. |
age |
Numeric array of ages. For example, |
A length-1 numeric value giving the mean age at childbearing implied
by fx.
age <- seq(15, 45, 5) fx <- c(0.03, 0.10, 0.14, 0.12, 0.07, 0.03, 0.01) mac(fx, age)age <- seq(15, 45, 5) fx <- c(0.03, 0.10, 0.14, 0.12, 0.07, 0.03, 0.01) mac(fx, age)
Age and cause decomposition of differences in life expectancies
mdecomp(mx1, mx2, age, method = "andreev", ...)mdecomp(mx1, mx2, age, method = "andreev", ...)
mx1 |
List of numeric arrays. 1st array should be all-cause nmx in the 1st population, other arrays are cause-specific nmx in the 1st population |
mx2 |
List of numeric arrays. 1st array should be all-cause nmx in the 2nd population, other arrays are cause-specific nmx in the 2nd population |
age |
Numeric array of age intervals; for full life table = |
method |
Character. Decomposition method. "andreev" (1982) or "arriaga" (1984) - slightly different in their results. By default, |
... |
Optional. Additional arguments for |
The contribution of each cause to the absolute difference in life expectancies between the first and second population is caculated as
where is contribution of age to difference from function decomp(), is age-specific mortality rate for population from cause , and is total age-specific mortality rate.
A data frame of class c("mdecomp", "data.frame") with one row per
age group. Column age contains ages, ex12 contains the overall age
contribution to the life-expectancy difference, and the remaining columns
contain cause-specific contributions named after the cause-specific
elements of mx1 and mx2.
decomp() for just age decomposition and plot.mdecomp() for graph of mdecomp results
data(mdecompex) usa <- subset(mdecompex, cnt == "usa") eng <- subset(mdecompex, cnt == "eng") dec <- mdecomp( mx1 = list( all = usa$all, neoplasms = usa$neoplasms, circulatory = usa$circulatory ), mx2 = list( all = eng$all, neoplasms = eng$neoplasms, circulatory = eng$circulatory ), age = usa$age ) dec[1:3, ]data(mdecompex) usa <- subset(mdecompex, cnt == "usa") eng <- subset(mdecompex, cnt == "eng") dec <- mdecomp( mx1 = list( all = usa$all, neoplasms = usa$neoplasms, circulatory = usa$circulatory ), mx2 = list( all = eng$all, neoplasms = eng$neoplasms, circulatory = eng$circulatory ), age = usa$age ) dec[1:3, ]
Data on mortality of US and England and Wales men in 2002 by some causes
mdecompexmdecompex
age
age specific mortality rate (asmr) from Neoplasms
asmr from Diseases of the circulatory system
asmr from Diseases of the respiratory system
asmr from Diseases of the digestive system
asmr from other causes
overall asmr
country: usa - US, eng - England and Wales
Andreev & Shkolnikov spreadsheet, can be seen on this webpage
Median age calculation
med.age(N, age)med.age(N, age)
N |
Numeric array. Population counts by age groups (from young to old) |
age |
Numeric array. Lower bounds of age groups, same length as |
A length-1 numeric value giving the estimated median age of the
population represented by N.
N <- c(100, 90, 80, 70, 60) age <- seq(0, 20, 5) med.age(N, age)N <- c(100, 90, 80, 70, 60) age <- seq(0, 20, 5) med.age(N, age)
Multiple Decrement Life Table
MLT(age, mx, ...)MLT(age, mx, ...)
age |
Numeric array of age intervals; for full life table = |
mx |
List of numeric arrays. 1st array should be all-cause mx in the population, other arrays are cause-specific mx in the population. |
... |
Other parameters for the function |
A numeric matrix extending the output of LT(). In addition to the
standard life-table columns, for each cause i in mx[-1] it adds
qx_i, dx_i, lx_i, and ex_no_i, corresponding to cause-specific
death probabilities, deaths, survivors, and cause-deleted life expectancy.
LT() for usual life table calculation
data(asdtex) mx_causes <- list( all = asdtex$all, neoplasms = asdtex$neoplasms, circulatory = asdtex$circulatory ) MLT(age = asdtex$age, mx = mx_causes)[1:3, c("age", "mx", "qx_neoplasms", "ex_no_neoplasms")]data(asdtex) mx_causes <- list( all = asdtex$all, neoplasms = asdtex$neoplasms, circulatory = asdtex$circulatory ) MLT(age = asdtex$age, mx = mx_causes)[1:3, c("age", "mx", "qx_neoplasms", "ex_no_neoplasms")]
Mortality models for mx approximation
mort.approx(mx, age, model = c("Brass", "Gompertz"), standard.mx = NULL, ...)mort.approx(mx, age, model = c("Brass", "Gompertz"), standard.mx = NULL, ...)
mx |
Numeric vector of age specific mortality rates. |
age |
Numeric vector of ages. |
model |
Character. Model name to be estimated. Now "Gompertz" and "Brass" are supported. |
standard.mx |
Numeric vector of age specific mortality rates for standard population. Default is |
... |
Used only for |
This function runs least squares optimization of the selected mortality function using Gauss-Newton algorithm algorithm with 2000 maximum iterations and 1e-07 as tolerance parameter. For "Gompertz" usual OLS estimator is used.
The model is as follows:
The model is as follows:
where
and subscript S defines that function is for standard population. To get mx from qx usual formula is used:
where n is the size of age interval and a(x) is a parameter from life table.
A list with two components: model, the fitted lm or nls
object; and predicted, a data frame with columns age and mx.pred
containing the fitted mortality schedule.
Preston, S. H., Heuveline, P., & Guillot, M. (2001). Demography: Measuring and Modeling Population Processes. Blackwell Publishers.
age <- seq(40, 80, 10) mx <- c(0.003, 0.005, 0.009, 0.018, 0.036) standard.mx <- c(0.0025, 0.004, 0.007, 0.014, 0.03) mort.approx(mx = mx, age = age, model = "Gompertz") mort.approx(mx = mx, age = age, model = "Brass", standard.mx = standard.mx)age <- seq(40, 80, 10) mx <- c(0.003, 0.005, 0.009, 0.018, 0.036) standard.mx <- c(0.0025, 0.004, 0.007, 0.014, 0.03) mort.approx(mx = mx, age = age, model = "Gompertz") mort.approx(mx = mx, age = age, model = "Brass", standard.mx = standard.mx)
Plot population pyramid
plot_pyr( popm, popf, popm2 = NULL, popf2 = NULL, age, prc = FALSE, sexn = c("Males", "Females"), sexc = c("#ED0000B2", "#00468BB2"), age.cont = NULL, un.intervals = TRUE )plot_pyr( popm, popf, popm2 = NULL, popf2 = NULL, age, prc = FALSE, sexn = c("Males", "Females"), sexc = c("#ED0000B2", "#00468BB2"), age.cont = NULL, un.intervals = TRUE )
popm |
Numeric vector of male population |
popf |
Numeric vector of female population |
popm2 |
Optional. Numeric vector of second male population to be plotted as line. |
popf2 |
Optional. Numeric vector of second female population to be plotted as line. |
age |
Numeric vector of ages |
prc |
Should the population be shown as a percentage rather than in absolute terms? By default, it is |
sexn |
Character array of labels for the sexes. By default = |
sexc |
Character array of colors for the sexes. By default = |
age.cont |
Optional. Logical. Should the age axis be considered as continuous scale? Recommend to switch to |
un.intervals |
Logical. Should the age groups be unified? For example, if the first and second groups are 0-1, 1-4, and all other groups are five-year, the function automatically makes the group 1-4 to make all the intervals the same. By default, |
A ggplot2 object representing a population pyramid. If popm2 and
popf2 are supplied, the plot also includes dashed comparison lines for
the second population.
plot_pyr( popm = c(100, 90, 80, 70, 60), popf = c(95, 92, 85, 75, 65), age = seq(0, 20, 5) )plot_pyr( popm = c(100, 90, 80, 70, 60), popf = c(95, 92, 85, 75, 65), age = seq(0, 20, 5) )
Plot for mdecomp function
## S3 method for class 'mdecomp' plot(x, return.data = FALSE, ...)## S3 method for class 'mdecomp' plot(x, return.data = FALSE, ...)
x |
A result of age and cause decomposition from |
return.data |
Should the data be returned ( |
... |
Ignored. |
If return.data = FALSE, a ggplot2 object with stacked bars of
age- and cause-specific contributions. If return.data = TRUE, a data
frame with columns age, ex12, and group used to build the plot.
data(mdecompex) usa <- subset(mdecompex, cnt == "usa") eng <- subset(mdecompex, cnt == "eng") dec <- mdecomp( mx1 = list( all = usa$all, neoplasms = usa$neoplasms, circulatory = usa$circulatory ), mx2 = list( all = eng$all, neoplasms = eng$neoplasms, circulatory = eng$circulatory ), age = usa$age ) plot(dec)data(mdecompex) usa <- subset(mdecompex, cnt == "usa") eng <- subset(mdecompex, cnt == "eng") dec <- mdecomp( mx1 = list( all = usa$all, neoplasms = usa$neoplasms, circulatory = usa$circulatory ), mx2 = list( all = eng$all, neoplasms = eng$neoplasms, circulatory = eng$circulatory ), age = usa$age ) plot(dec)
Rosbris' Region codes
rosbris.codesrosbris.codes
number of Region (sequence number)
Region name
Region unique code
Russian Fertility and Mortality Database. Center for Demographic Research, Moscow (Russia). Available at https://www.nes.ru/demogr-fermort-data
Data on Standard Life expectancies that is used for YLL calculations
sle_standsle_stand
Standard: 1 - World Health Organization Standard Life Expectancy by single-age; 2 - Global Burden of Disease studies (GBD) and WHO Global Health Estimates (WHO GHE) Standard Life Expectancy by 5-year age groups.
age
Standard Life Expectancy
Martinez, R., Soliz, P., Caixeta, R., Ordunez, P. (2019). Reflection on modern methods: years of life lost due to premature mortality-a versatile and comprehensive measure for monitoring non-communicable disease mortality. International Journal of Epidemiology, 48, 1367-1376. doi:10.1093/ije/dyy254
Leslie matrix summary
## S3 method for class 'leslie' summary(object, d = 1, ...)## S3 method for class 'leslie' summary(object, d = 1, ...)
object |
A leslie matrix from |
d |
Time step. By default it is 1. Only affects |
... |
Ignored. |
The function calculates , , and .
– asymptotic growth factor that is dominant eigenvalue.
– asymptotic growth rate that is .
– stable age distribution normalized to 1 s.t. where is age.
– reproductive values normalized s.t. .
A list of class summary.leslie with four components:
lambda (dominant eigenvalue / asymptotic growth factor), r
(intrinsic growth rate), w (stable age distribution summing to 1),
and v (reproductive values normalized so that sum(v * w) = 1).
mx <- c(0.02, 0.01, 0.012, 0.015, 0.02) fx <- c(0.05, 0.08) les <- leslie(mx = mx, fx = fx, age.mx = 0:4, age.fx = 1:2) summary(les)mx <- c(0.02, 0.01, 0.012, 0.015, 0.02) fx <- c(0.05, 0.08) les <- leslie(mx = mx, fx = fx, age.mx = 0:4, age.fx = 1:2) summary(les)
Tempo-adjusted total fertility rate (TFR')
tatfr(past_fx, present_fx, post_fx, age)tatfr(past_fx, present_fx, post_fx, age)
past_fx |
List with numeric arrays of age specific fertility rates for period t-1 by parity |
present_fx |
List with numeric arrays of age specific fertility rates for period t by parity (it is period of interest) |
post_fx |
List with numeric arrays of age specific fertility rates for period t+1 by parity |
age |
Array with numeric values age |
This indicator is calculated as follows
where are tempo-adjusted and usual total fertility rate for parity and time respectively, is mean age at childbearing for parity and time . The tempo-adjusted total fertility rate is a sum of parity-specific .
Note, the calculation are done as in footnote 1 in (Bongaarts & Feeney, 2000, p. 563). Unfortunately, the original 1998 article does not provide the exact formula, which has caused some confusion in academic circles.
A list with four components: tatfr (overall tempo-adjusted total
fertility rate), tatfr_i (parity-specific tempo-adjusted rates), tfr
(overall conventional TFR), and tfr_i (parity-specific conventional
rates).
Bongaarts, J., & Feeney, G. (1998). On the Quantum and Tempo of Fertility. Population and Development Review, 24(2), 271–291. doi:10.2307/2807974
Bongaarts, J., & Feeney, G. (2000). On the Quantum and Tempo of Fertility: Reply. Population and Development Review, 26(3), 560–564. doi:10.1111/j.1728-4457.2000.00560.x
tfr() for TFR and mac() for mean age at childbearing calculation.
age <- seq(15, 45, 5) past_fx <- list( c(0.02, 0.05, 0.07, 0.05, 0.03, 0.01, 0.00), c(0.01, 0.03, 0.04, 0.03, 0.02, 0.01, 0.00) ) present_fx <- list( c(0.03, 0.06, 0.08, 0.06, 0.03, 0.01, 0.00), c(0.01, 0.03, 0.05, 0.04, 0.02, 0.01, 0.00) ) post_fx <- list( c(0.03, 0.05, 0.08, 0.07, 0.04, 0.02, 0.00), c(0.01, 0.03, 0.04, 0.04, 0.03, 0.01, 0.00) ) tatfr(past_fx, present_fx, post_fx, age)age <- seq(15, 45, 5) past_fx <- list( c(0.02, 0.05, 0.07, 0.05, 0.03, 0.01, 0.00), c(0.01, 0.03, 0.04, 0.03, 0.02, 0.01, 0.00) ) present_fx <- list( c(0.03, 0.06, 0.08, 0.06, 0.03, 0.01, 0.00), c(0.01, 0.03, 0.05, 0.04, 0.02, 0.01, 0.00) ) post_fx <- list( c(0.03, 0.05, 0.08, 0.07, 0.04, 0.02, 0.00), c(0.01, 0.03, 0.04, 0.04, 0.03, 0.01, 0.00) ) tatfr(past_fx, present_fx, post_fx, age)
Total Fertility Rate (TFR)
tfr(fx, age.int = 1)tfr(fx, age.int = 1)
fx |
Numeric array of age specific fertility rates. |
age.int |
Numeric. Age group: |
A length-1 numeric value equal to the sum of age-specific fertility
rates multiplied by age.int.
fx <- c(0.02, 0.08, 0.12, 0.09, 0.04, 0.01, 0.001) tfr(fx, age.int = 5)fx <- c(0.02, 0.08, 0.12, 0.09, 0.04, 0.01, 0.001) tfr(fx, age.int = 5)
Years of Life Lost (YLL) calculation
yll( Dx, type = c("yll", "yll.p", "yll.r", "asyr"), age.int = 5, Dx_all = NULL, pop = NULL, w = NULL, standard = NULL )yll( Dx, type = c("yll", "yll.p", "yll.r", "asyr"), age.int = 5, Dx_all = NULL, pop = NULL, w = NULL, standard = NULL )
Dx |
Array with the number of deaths. |
type |
Character. Type of YLL to calculate. See details section. |
age.int |
Numeric. Age interval of Dx. Can be |
Dx_all |
Array with the number of all deaths. Used only with |
pop |
Array with population. Used only with |
w |
Array with population weights for direct standardization. Used only with |
standard |
Data frame. User-specific standard life expectancy to calculate YLL with the following columns: age, ex. Note: the |
Computes four types of Years of Life Lost (YLL) indicators:
Absolute YLL (type = "yll"):
where are age, time, and cause respectively, is deaths in age at time from cause and is standard life expectancy at age
YLL proportion (type = "yll.p"):
where (total YLL across causes)
YLL rate (type = "yll.r"):
where is population in age group at time
Age-standardized YLL rate (type = "asyr"):
where to corresponds to first to last age group, is standard population weight for age .
A list whose components depend on type. For type = "yll", the
list contains yll_all (overall YLL) and yll (age-specific YLL). For
type = "yll.p", it contains yll.p_all and yll.p (overall and
age-specific YLL proportions). For type = "yll.r", it contains
yll.r_all and yll.r (overall and age-specific YLL rates). For
type = "asyr", it contains asyr_all and asyr (overall and
age-specific age-standardized YLL rates).
Martinez, R., Soliz, P., Caixeta, R., & Ordunez, P. (2019). Reflection on modern methods: years of life lost due to premature mortality—a versatile and comprehensive measure for monitoring non-communicable disease mortality. International Journal of Epidemiology, 48, 1367–1376.
yll(Dx = rep(1, 19), type = "yll", age.int = 5)$yll_allyll(Dx = rep(1, 19), type = "yll", age.int = 5)$yll_all