View source: R/generate_units.R
generate_units | R Documentation |
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.
generate_units(time, psi, n_sim = 20, cbaseh, inv_cbaseh, coxphmod = NULL,
baseline_data, interval = c(0, 9e+12), mu = 0)
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 |
A function returning the inverse cumulative baseline hazard at each relevant time point. |
coxphmod |
(optional): A cox proportional hazards model generated using
If both |
baseline_data |
(optional): A |
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. |
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()
.
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
.
Daniel Gomon
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.