View source: R/fun-modify_LT.R
modify_life_table | R Documentation |
Modify life table by changing the cause of death associated risks
modify_life_table(lt, cod, cod_change)
lt |
Life table; |
cod |
Causes of death matrix containing death counts corresponding to the population and time period of the life table; |
cod_change |
Numerical scalar, vector or matrix. The changes to be applied to the causes of death rate, m[c,x], in order to reduce or increase the mortality estimates given by the life table. Accepted input: any value greater than -100. See examples. |
A life table in the same format as the input life table.
L <- data_gbd2021_lt # life tables
D <- data_gbd2021_cod # cod data
# Select Life Table
lt <- L[L$region == "Romania" & L$sex == "both" & L$period == 2021, ]
# Select COD data
cod <- D[D$region == "Romania" & D$sex == "both" & D$period == 2021, ]
cod_change = -50
# Example 1:
# How does the life table modify if the cause-specific mortality is
# reduced by 50% (all ages, all causes of death)?
lt_reduced <- modify_life_table(lt, cod, cod_change = -50)
lt_reduced
# Example 2:
# Let's change the first cod by 1%, second one with 2% and so on until 17%
# Note, we are increasing death rates. This should result in a lower life
# expectancy.
unique(cod$cause_name) # we have 17 causes
lt_reduced2 <- modify_life_table(lt, cod, cod_change = 1:17)
lt_reduced2
# Example 3:
# Apply a specific change by cause and age
# Say, we want to decrease the cod's risk only between age 45 and 75
# with values between 24% and 40%.
# we have to build a matrix with 25 rows and 18 columns (AGEs x CODs)
# to indicate the change for each combination
M <- matrix(24:40, nrow = 25, ncol = 18, byrow = TRUE)
dimnames(M) <- list(unique(cod$x), unique(cod$cause_name))
M[!(rownames(M) %in% 45:75), ] <- 0
lt_reduced3 <- modify_life_table(lt, cod, cod_change = -M)
lt_reduced3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.