Package 'actLifer'

Title: Creating Actuarial Life Tables
Description: Contains data and functions that can be used to make actuarial life tables. Each function adds a column to the inputted dataset for each intermediate calculation between mortality rate and life expectancy. Users can run any of our functions to complete the life table until that step, or run lifetable() to output a full life table that can be customized to remove optional columns. Methods for creating lifetables are as described in Zedstatistics (2021) <https://www.youtube.com/watch?v=Dfe59glNXAQ>.
Authors: Grace Rade [aut, cre, cph] , Maeve Tyler-Penny [aut] , Julia Ting [aut]
Maintainer: Grace Rade <[email protected]>
License: MIT + file LICENSE
Version: 1.0.0.9000
Built: 2025-02-12 05:26:24 UTC
Source: https://github.com/g-rade/actlifer

Help Index


Central Death Rate

Description

Adds a new column called CentralDeathRate to the dataset that was input. This column represents the central death rate of each age group - deaths/population.

Usage

central_death_rate(data, age, pop, deaths)

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

Data frame that was input with an added CentralDeathRate column.

Examples

# This function adds a CentralDeathRate column to the dataset
central_death_rate(mortality2, "age_group", "population", "deaths")

Conditional Probability of Death at Age x

Description

Adds a new column called ConditionalProbDeath to the dataset that was input. This column represents the probability of death given the age group for each age group. In other words, the probability a person in a given age group will die before their next birthday.

Usage

conditional_death_prob(data, age, pop, deaths)

Arguments

data

The mortality dataset, includes an age grouping variable

age

The age grouping variable, must be cateogrical

pop

Population of each age group, must be numeric

deaths

The number of deaths at each age group, must be numeric

Value

Data frame that was input with an added column, ConditionalProbDeath.

Examples

# This function will add a ConditionalProbDeath column to the dataset
conditional_death_prob(mortality2, "age_group", "population", "deaths")

Conditional Probability of Survival at Age x

Description

Adds a new column called ConditionalProbLife to the dataset that was input. ConditionalProbLife column contains the probabilities of surviving for each given age group. In other words, this is the probability of someone surviving to their next birthday.

Usage

conditional_life_prob(data, age, pop, deaths)

Arguments

data

The mortality dataset, includes an age grouping variable

age

The age grouping variable, must be cateogrical

pop

Population of each age group, must be numeric

deaths

The number of deaths at each age group, must be numeric

Value

Dataset that was input with added columns ConditionalProbDeath and ConditionalProbLife. In other words, we are doing the "steps" up to the conditional probability of survival.

Examples

# This function will add the ConditionalProbDeath and ConditionalProbLife columns
# to the dataset
conditional_life_prob(mortality2, "age_group", "population", "deaths")

Error Handling Function

Description

Checks inputs data, age, pop, and deaths to make sure they are valid.

Usage

input_check(data, age, pop, deaths)

Arguments

data

data frame input in the upper function

age

age string or character input in the upper function

pop

pop string or character input in the upper function

deaths

deaths string or character input in the upper function

Value

data frame with numeric pop and deaths columns


Life Expectancy of Age x

Description

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.

Usage

life_expectancy(data, age, pop, deaths)

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")

Lifetable Function

Description

Gives user more control over their lifetable compared to the life_expectancy() function. Allows the user to add in the central death rate and proportion surviving to age x. Allows the user to omit accessory columns which are used to calculate life expectancy.

Usage

lifetable(
  data,
  age,
  pop,
  deaths,
  includeAllSteps = TRUE,
  includeCDR = TRUE,
  includePS = TRUE,
  ...
)

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

includeAllSteps

If false, will only include the proportion surviving to age x and life expectancy for age x

includeCDR

If true, will include the central death rate for each age group

includePS

If true, will include the proportion surviving for each age group

...

Other optional grouping variables (can be race, gender, etc.)

Value

Lifetable

Examples

# Running lifetable() and choosing not to include CentralDeathRate and
# ProportionToSurvive (optional columns) in the output dataset

lifetable(mortality2, "age_group", "population", "deaths", FALSE, TRUE, TRUE)

A sample mortality data

Description

A data extract takes from the CDC Wonder database.

Usage

mortality

Format

A data frame with 85 rows of 3 columns representing the US population at mulit-year different age groups with which we use to make a life table. This data is from the year 2018

age_group

Categorical variable identifying each age group

deaths

the mid-year number of deaths in each age group

population

the US population of each age group

Source

https://wonder.cdc.gov


A sample mortality data

Description

A data extract taken from the CDC Wonder database.

Usage

mortality2

Format

A data frame with 85 rows of 3 columns representing the deaths and US population at each single-year age group with which we can use to make a life table. This data is from the year 2016.

age_group

Categorical variable identifying each age group

deaths

the mid-year number of deaths in each age group

population

the US population of each age group

Source

https://wonder.cdc.gov/ucd-icd10.html


A sample mortality data

Description

A data extract taken from the CDC Wonder database.

Usage

mortality3

Format

A data frame with 170 rows of 4 columns representing the deaths and US population at each single-year age group for each sex with which we can use to make a life table. This data is from the year 2016.

age_group

Categorical variable identifying each age group

deaths

the mid-year number of deaths in each age group

population

the US population of each age group

gender

a categroical variable grouping the data into male and female

Source

<https://wonder.cdc.gov


The Number of People to Survive to Age x

Description

Adds a new column called NumberToSurvive to the dataset that was input. NumberToSurvive represents the number of people living at the beginning of the given age interval, using an arbitrary 100,000 people for the first age group in the table.

Usage

number_to_survive(data, age, pop, deaths)

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 added columns: ConditionalProbDeath, ConditionalProbLife, and NumberToSurvive.

Examples

# This function will add the ConditionalProbDeath, ConditionalProbLife, and
# NumberToSurvive columns to the dataset
number_to_survive(mortality2, "age_group", "population", "deaths")

Person Years Lived at Age x

Description

Adds a new column called PersonYears to the dataset that was input. PersonYears represents the number of years lived at age x based on the number surviving to age x.

Usage

person_years(data, age, pop, deaths)

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, PropToSurvive, PersonYears.

Examples

# This function will add the ConditionalProbDeath, ConditionalProbLife,
# NumberToSurvive, PropToSurvive, and PersonYears columns to the dataset
person_years(mortality2, "age_group", "population", "deaths")

Proportion to Survive to Age x

Description

Adds a new column called PropToSurvive to the dataset that was input. PropToSurvive is the proportion surviving to age x

Usage

prop_to_survive(data, age, pop, deaths)

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

Data frame that was input with columns for steps up to proportion surviving to age x included. That is, the original data with the following added columns: ConditionalProbDeath, ConditionalProbLife, NumberToSurvive, PropToSurvive

Examples

# This function will add the ConditionalProbDeath, ConditionalProbLife,
# NumberToSbrvivem and PropToSurvive columns to the dataset
prop_to_survive(mortality2, "age_group", "population", "deaths")

Total Years Lived From Age x

Description

Adds a new column called TotalYears to the dataset that was input. TotalYears is the number of years lived from age zero to age x.

Usage

total_years_lived(data, age, pop, deaths)

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, and TotalYears.

Examples

# This function will add the ConditionalProbDeath, ConditionalProbLife,
# NumberToSurvive, PropToSurvive, PersonYearsm and TotalYears columns to the
# dataset
total_years_lived(mortality2, "age_group", "population", "deaths")