generate_units: Generate units with specified failure rate

View source: R/generate_units.R

generate_unitsR Documentation

Generate units with specified failure rate

Description

Generate n_sim units with subjects arriving according to a Poisson process with rate psi until time. Failure rate is determined either from cbaseh or inv_cbaseh, or from specified coxphmod. Covariates will be resampled from baseline_data if specified.

Usage

generate_units(time, psi, n_sim = 20, cbaseh, inv_cbaseh, coxphmod = NULL,
  baseline_data, interval = c(0, 9e+12), mu = 0)

Arguments

time

A numeric value indicating until what time from the start of the study subjects can arrive.

psi

Poisson arrival rate for subjects.

n_sim

An integer indicating how many units should be generated. Default is 20.

cbaseh

A function returning the cumulative baseline hazard at each relevant time point. Will be numerically inverted to generate failure times. If the inverse cumulative baseline hazard function is available, please specify inv_cbaseh instead.

inv_cbaseh

A function returning the inverse cumulative baseline hazard at each relevant time point.

coxphmod

(optional): A cox proportional hazards model generated using coxph() or a list containing:

formula:

a formula() in the form ~ covariates;

coefficients:

a named vector specifying risk adjustment coefficients for covariates. Names must be the same as in formula and colnames of data.

If both cbaseh and inv_cbaseh are missing, the hazard rate will be determined from coxphmod.

baseline_data

(optional): A data.frame used for covariate resampling with rows representing subjects and columns containing covariates to use for risk-adjustment. Should only be specified in combination with coxphmod.

interval

(optional) A numeric vector of length 2 indicating in which range of values the failure times of subjects should be determined. By default, failure times will be restricted between 0 and 9e12.

mu

(optional) The increased log hazard ratio at the generated units with respect to the specified baseline hazard rate. Default is log(1) = 0.

Details

In a Poisson arrival process, inter-arrival times are exponentially distributed with parameter psi. If cbaseh is specified, the inverse baseline hazard will be determined using uniroot(). The times of failure are then determined using gen_surv_times().

Value

A data.frame with rows representing subjects and the following named columns:

entrytime:

time of subject entry into the study;

survtime:

survival time of subject;

censorid:

censoring indicator, 0 = censored, 1 = observed;

unit:

unit number;

expmu:

exponent of the log hazard ratio used to generate survival times;

psival:

arrival rate at unit;

covariates:

covariates resampled from baseline_data.

Author(s)

Daniel Gomon

Examples

require(survival)
#Fit a Cox model
exprfit <- as.formula("Surv(survtime, censorid) ~ age + sex + BMI")
tcoxmod <- coxph(exprfit, data= surgerydat)

#Generate 30 hospitals with on average 2 patients per day arriving
#according to the Cox model determined above, with resampling from the
#original data set. The hazard rate at the hospitals is twice the baseline
#hazard.
generate_units(time = 50, psi = 2, n_sim = 30, coxphmod = tcoxmod,
baseline_data = surgerydat, mu = log(2))




success documentation built on June 22, 2024, 10:19 a.m.