sim_clinical_incidence: Use sim_KM to efficiently simulate ages at clinical incidence...

Description Usage Arguments Value Examples

Description

Given a population with a clinical incidence survival curve and ages, returns random draws of their ages at incidence

Usage

1
2
sim_clinical_incidence(popdata, bootrows, incidence,
  results_as_matrix = FALSE)

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

incidence

Matrix/df with columns 'age' and 'cumsurv'

results_as_matrix

Convert the results from a data frame to a matrix?

Value

Data frame or matrix of ages at clinical incidence, capped at age 121. Age at incidence will always be after age at entry.

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
# Prepare incidence data
library(bcimodel)
data(incratesf)
inc <- interpolate_cumsurv(incratesf, 
                          ratevar='Female.Rate.Per.100K',
                          country='Uganda',
                          maxage=100)
# 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 clinical incidence
incage <- sim_clinical_incidence(poplist, rowlist, inc)

# 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))
incage <- sim_clinical_incidence(pop, poprows, inc)

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