Life Table Generation
An individual's characteristics can also be used to generate a life table with a cohort of identical traits. This can be used to calculate the probability of survival to different states.
Life tables generated from the static and trend models are always deterministic, so the output will be one lifetable.
Meanwhile, the frailty model will produce stochastic outputs. The lifetables outputted will be a full list of the simulated lifetables.
The lifetable shows the number of people in each state at each age, and one can also choose the initial state and the initial age that the starting cohort is in.
Generating a Life Table for Static and Trend Models
create_life_table(trans_probs, init_age, init_state = 0, cohort = 100000)
Parameters:
trans_probs : list
list of transition probability matrices; typically generated by 'get_trans_probs'
init_age : numeric
numeric denoting initial age of individual
init_state : numeric
for 3-state model: integer value of 0 or 1, where 0 for healthy state, 1 for disabled state
for 5-state model: 0 for H state, 1 for M state, 2 for D state, 3 for MD state
cohort : numeric
number of people at the beginning of the life table
Returns:
A life table matrix
Usage:
# for male aged 65 at wave index i, initially in the health state, using the static model with parameters 'params'
trans_probs <- get_trans_probs(n_states=5, model_type='S', param_file=US_HRS_5, init_age=65, female=0, year = 2012, wave_index = 8, latent = 0)
lifetable <- create_life_table(trans_probs, init_age=65, init_state = 0, cohort = 100000)
Simulating a Number of Life Tables for Frailty Model
simulate_life_table(n_states, model_type, param_file, init_age, female, year = 2012, init_state = 0, wave_index = 8,latent=0,n_sim=100,cohort=100000,mean=FALSE)
Parameters:
n_states : numeric
take values 3 or 5, use 3 for 3-state model, and 5 for 5-state model
model_type : character
select F for Frailty model
param_file : dataframe
File path, or dataframe/tibble of parameters (generally, use US_HRS or china_CLHLS for the 3-state model, and use US_HRS_5 for the 5-state-model)
init_age : numeric
integer denoting the initial age
female : numeric
0 for male, 1 for female
year : numeric
integer denoting current year, required in 3-state model and ignored in 5-state model
init_state : numeric
for 3-state model: integer value of 0 or 1, where 0 for healthy state, 1 for disabled state
wave_index : numeric
integer for the wave index = (interview year - 1998)/2 + 1, required in 5-state model and ignored in 3-state model
latent : numeric
initial value of latent factor, normally take the value 0
n_sim : numeric
integer denoting number of life table simulations
cohort : numeric
number of people at the beginning of the life table
mean : logic
TRUE to return expected life table, FALSE to return all simulated life tables
Returns:
A list of life table matrices if mean = FALSE, or a life table matrix if mean = TRUE
Usage:
# for male aged 65 at wave index i, initially in the health state, using the frailty model with parameters 'params'
lifetable_simulated <- simulate_life_table(n_states=5, model_type='F', param_file=US_HRS_5, init_age=65, female=0, year = 2012, init_state = 0, wave_index = 8,latent=0,n_sim=100,cohort=100000,mean=FALSE)