View source: R/fun-decompose.R
decompose_by_cod | R Documentation |
Perform decomposition of age- and cause-specific mortality contributions in life expectancy between any two regions/time periods
decompose_by_cod(L1, L2, C1, C2, symmetrical = TRUE, direction = "up")
L1 |
Life table corresponding to the region/time period 1; |
L2 |
Life table corresponding to the region/time period 2; |
C1 |
Causes of death data containing death counts corresponding to the region/time period 1. Format: long table; |
C2 |
Causes of death data containing death counts corresponding to the region/time period 2. Format: long table; |
symmetrical |
logical. default TRUE as recommended by authors. Shall we average the results of replacing 1 with 2 and 2 with 1? The symmetrical argument toggles whether or not we replace cod1 with cod2 (FALSE), or take the arithmetic average or replacement in both directions. Defaults are set to symmetrically replace from the bottom up, per the authors' suggestion. |
direction |
character. One of "up", "down", or "both". Default "up", as recommended by authors. It refers to whether we go from the bottom up or top down, or take the arithmetic average of these when replacing vector elements. Although the total difference will always sum correctly, the calculated contribution from individual components can vary greatly depending on the order in general. |
This implements the algorithm described in Andreev et al (2002), with defaults set to approximate their recommendations for replacement ordering and result averaging.
A long tibble in the same format as the cod input data. The output
containS the column decomposition
that indicates the change in life
expectancy by age and/or cause of death between the two life tables provided
as input. Measure unit: years.
The code of this function is based on the implementation of the
DemoDecomp::stepwise_replacement
function maintained by Tim RIFFE.
...
L <- data_gbd2021_lt # life tables
D <- data_gbd2021_cod # cod data
# Select two Life Tables
region1 = "Romania"
region2 = "Mexico"
sex = "male"
year = 2021
lt1 <- L[L$region == region1 & L$sex == sex & L$period == year, ]
lt2 <- L[L$region == region2 & L$sex == sex & L$period == year, ]
# Select COD corresponding data
cod1 <- D[D$region == region1 & D$sex == sex & D$period == year, ]
cod2 <- D[D$region == region2 & D$sex == sex & D$period == year, ]
## Example of decomposition by age and cause of death
dec <- decompose_by_cod(L1 = lt1,
L2 = lt2,
C1 = cod1,
C2 = cod2)
dec
plot_decompose(dec)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.