calc_ac_lifespan_pop: Use the individual calc_ac_lifespan function to estimate...

Description Usage Arguments Value Examples

Description

Given a population with birth years and ages, returns random draws of their ages at other-cause death

Usage

1
2
calc_ac_lifespan_pop(popdata, bootrows, life_table,
  results_as_matrix = FALSE, survHR = 1, max100_topass = TRUE)

Arguments

popdata

Data frame where individuals are rows, with columns birth_year, age, and male, OR a list of data frames that allow build_simpop() to construct this

bootrows

Matrix or data frame of row indicators that can be applied to the data to recover different bootstraps of the data. Each column is a different bootstrap of thedata. OR, list of data frames with these row indicators for use with build_simpop()

life_table

Data frame with columns Survival, BirthCohort, Age, and Male

results_as_matrix

Set to TRUE to convert results from matrix to data frame

survHR

Hazard to apply to the life table survival

max100_topass

If TRUE, interpolate out to 100 as the max survival age

Value

A data frame or matrix with nsim columns of randomly drawn ages at other-cause death for individuals (rows)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
library(bcimodel)
data(allmortratesf)
surv <- interpolate_cumsurv(allmortratesf, 
                          ratevar='Rate.Per.100K',
                          country='Uganda')
# Code compatibility tweaks for life table
surv <- transform(surv, Age=age, Survival=cumsurv, Male=0)

# Example 1: use the list approach
# Simple age distribution
ages <- data.frame(age=c(20,30,40), prop=c(0.2, 0.5, 0.3))
# Simulate a population of size 10 twice, using these proportions and the row IDs
sim.age.rows <- sim_multinom(nsims=10, 2, ages$prop, names=1:nrow(ages))
# Now specify they're all female
sex <- data.frame(male=0, prop=1)
sim.sex.rows <- matrix(1, nrow=10, ncol=2)
# Create the lists
poplist <- list(sex, ages)
rowlist <- list(sim.sex.rows, sim.age.rows)
# Get ages at OC death
oc <- calc_ac_lifespan_pop(poplist, rowlist, surv)

# Example 2
# Alternatively, pass a population in data frame form and just use its normal rows
# Use build_simpop and the 2nd simulation's row IDs
pop <- build_simpop(poplist, rowlist, sim=2)[,c('male', 'age')]
poprows <- replicate(2, 1:nrow(pop))
oc <- calc_ac_lifespan_pop(pop, poprows, surv)

cancerpolicy/bcimodel documentation built on June 30, 2019, 12:39 a.m.