Adds a new column called LifeExpectancy to the dataset that was input. LifeExpectancy is how many more years we expect a person of age x to live beyond their current age.
Arguments
- data
The mortality dataset, includes an age grouping variable,
- age
The age grouping variable, must be categorical
- pop
Population of each age group, must be numeric
- deaths
The midyear number of deaths at each age group, must be numeric
Value
Dataset that was input with the added columns: ConditionalProbDeath, ConditionalProbLife, NumberToSurvive, PersonYears, TotalYears, and LifeExpectancy.
Examples
# This function will add the ConditionalProbDeath, ConditionalProbLife,
# NumberToSurvive, PropToSurvive, PersonYears, TotalYears, and LifeExpectancy
# columns to the dataset.
# This will be a full lifetable
life_expectancy(mortality2, "age_group", "population", "deaths")
#> # A tibble: 85 × 10
#> age_group deaths population ConditionalProbDeath ConditionalProbLife
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 < 1 year 23161 3970145 0.00582 0.994
#> 2 1 year 1568 3995008 0.000392 1.00
#> 3 2 years 1046 3992154 0.000262 1.00
#> 4 3 years 791 3982074 0.000199 1.00
#> 5 4 years 640 3987656 0.000160 1.00
#> 6 5 years 546 4032515 0.000135 1.00
#> 7 6 years 488 4029655 0.000121 1.00
#> 8 7 years 511 4029991 0.000127 1.00
#> 9 8 years 483 4159114 0.000116 1.00
#> 10 9 years 462 4178524 0.000111 1.00
#> # ℹ 75 more rows
#> # ℹ 5 more variables: NumberToSurvive <dbl>, PropToSurvive <dbl>,
#> # PersonYears <dbl>, TotalYears <dbl>, LifeExpectancy <dbl>