samp_elife {longevity} | R Documentation |
Simulate excess lifetime with truncation or right-censoring
Description
This function dispatches simulations accounting for potential left-truncation (remove by setting lower to zero).
If type2=ltrt
, simulated observations will be lower than the upper bounds upper
.
If type2=ltrc
, simulated observations are capped at upper
and the observation is right-censored (rcens=TRUE
).
Usage
samp_elife(
n,
scale,
rate,
shape = NULL,
lower = 0,
upper = Inf,
family = c("exp", "gp", "gomp", "gompmake", "weibull", "extgp", "gppiece",
"extweibull", "perks", "beard", "perksmake", "beardmake"),
type2 = c("none", "ltrt", "ltrc", "ditrunc")
)
Arguments
n |
sample size |
scale |
scale parameter(s) |
rate |
rate parameter(s) |
shape |
shape parameter(s) |
lower |
vector of lower bounds |
upper |
vector of upper bounds |
family |
string; choice of parametric family |
type2 |
string, either |
Value
either a vector of observations or, if type2=ltrc
, a list with n
observations dat
and a logical vector of the same length with TRUE
for right-censored observations and FALSE
otherwise.
Note
As the tails of the Gompertz and Gompertz–Makeham models decrease exponentially fast, the method fails in the rare event case if the lower bound is too large (say larger than the 99.99
Examples
set.seed(1234)
n <- 500L
# Simulate interval truncated data
x <- samp_elife(n = n,
scale = 2,
shape = 1.5,
lower = low <- runif(n),
upper = upp <- runif(n, min = 3, max = 15),
type2 = "ltrt",
family = "weibull")
coef(fit_elife(
time = x,
ltrunc = low,
rtrunc = upp,
family = "weibull"))
# Simulate left-truncated right-censored data
x <- samp_elife(n = n,
scale = 2,
shape = 1.5,
lower = low <- runif(n),
upper = upp <- runif(n, min = 3, max = 15),
type2 = "ltrc",
family = "gomp")
#note that the return value is a list...
coef(fit_elife(
time = x$dat,
ltrunc = low,
event = !x$rcens,
family = "gomp"))