| Title: | Survival Analysis for Recurrent Event Data |
|---|---|
| Description: | Estimation of the survival function of inter-occurrence times for recurrent event data, using the estimators of Peña, Strawderman and Hollander (2001) <doi:10.1198/016214501753381922> and Wang and Chang (1999) <doi:10.1080/01621459.1999.10473831>, and maximum likelihood estimation under a gamma frailty model. Includes bootstrap comparison of survival quantiles between groups. |
| Authors: | Dolors Pelegri-Siso [aut, cre] (ORCID: <https://orcid.org/0000-0002-5993-3003>), Juan R. González [aut], Edsel A. Peña [aut], Robert L. Strawderman [aut] |
| Maintainer: | Dolors Pelegri-Siso <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 2.0.0 |
| Built: | 2026-09-22 10:28:26 UTC |
| Source: | https://github.com/isglobal-brge/survrec |
Estimation of the survival function of inter-occurrence times for recurrent event data. Three estimators are available: the generalized product-limit estimator of Peña, Strawderman and Hollander (2001), the estimator of Wang and Chang (1999) for correlated inter-occurrence times, and maximum likelihood estimation under a gamma frailty model. Survival quantiles can be compared between groups through several bootstrap schemes.
The main entry points are Survr() to build the response object,
survfitr() to estimate survival curves (optionally by group) and
survdiffr() to bootstrap survival quantiles.
Maintainer: Dolors Pelegri-Siso [email protected] (ORCID)
Authors:
Juan R. González [email protected]
Edsel A. Peña
Robert L. Strawderman
Peña, E.A., Strawderman, R. and Hollander, M. (2001). Nonparametric Estimation with Recurrent Event Data. Journal of the American Statistical Association 96, 1299–1315.
Wang, M.-C. and Chang, S.-H. (1999). Nonparametric Estimation of a Recurrent Survival Function. Journal of the American Statistical Association 94, 146–153.
Useful links:
Report bugs at https://github.com/isglobal-brge/survrec/issues
Returns the estimated curves in long ("tidy") format, one row per distinct event time (and group), ready for further processing or plotting.
## S3 method for class 'survfitr' as.data.frame(x, row.names = NULL, optional = FALSE, ...)## S3 method for class 'survfitr' as.data.frame(x, row.names = NULL, optional = FALSE, ...)
x |
a |
row.names, optional
|
see |
... |
ignored. |
A data frame with columns group (only when the fit has
strata), time, n.event, n.risk, surv and std.error (NA
for estimators without standard errors).
data(MMC) fit <- survfitr(Survr(id, time, event) ~ group, data = MMC, type = "wang-chang" ) head(as.data.frame(fit))data(MMC) fit <- survfitr(Survr(id, time, event) ~ group, data = MMC, type = "wang-chang" ) head(as.data.frame(fit))
Draws the mean cumulative function estimated by mcf() as a step
function, one colour per group.
## S3 method for class 'mcf' autoplot(object, ...)## S3 method for class 'mcf' autoplot(object, ...)
object |
an object of class |
... |
ignored; kept for compatibility with the generic. |
A ggplot object.
data(colon) autoplot(mcf(Survr(hc, time, event) ~ as.factor(dukes), data = colon))data(colon) autoplot(mcf(Survr(hc, time, event) ~ as.factor(dukes), data = colon))
Draws the density of the bootstrap replicates of each group, with a vertical line at the observed quantile. Infinite replicates (survival estimate never below the requested level) are excluded from the densities and reported in the caption.
## S3 method for class 'survdiffr' autoplot(object, ...)## S3 method for class 'survdiffr' autoplot(object, ...)
object |
a grouped result of |
... |
ignored; kept for compatibility with the generic. |
A ggplot object.
survdiffr(), summary.survdiffr(), theme_survrec()
data(colon) fit <- survdiffr(Survr(hc, time, event) ~ as.factor(dukes), data = colon, q = 0.5, seed = 1 ) autoplot(fit)data(colon) fit <- survdiffr(Survr(hc, time, event) ~ as.factor(dukes), data = colon, q = 0.5, seed = 1 ) autoplot(fit)
Draws the estimated survival function of a survfitr object as a step
function, one colour per group, with an optional pointwise confidence
band. The cumulative distribution (fun = "event") and the cumulative
hazard (fun = "cumhaz") transformations are also available.
## S3 method for class 'survfitr' autoplot( object, fun = c("surv", "event", "cumhaz"), conf.int = TRUE, level = 0.95, conf.type = c("log-log", "plain"), ... )## S3 method for class 'survfitr' autoplot( object, fun = c("surv", "event", "cumhaz"), conf.int = TRUE, level = 0.95, conf.type = c("log-log", "plain"), ... )
object |
an object of class |
fun |
transformation of the survival curve: |
conf.int |
draw the pointwise confidence band? Default |
level |
confidence level of the band. |
conf.type |
transformation used for the band: |
... |
ignored; kept for compatibility with the generic. |
The confidence band is computed from the standard errors of the fit
when the estimator provides them (Peña-Strawderman-Hollander and
Wang-Chang). With conf.type = "log-log" (default) the limits are
obtained on the scale, so they always stay inside
; "plain" gives the symmetric limits of the base
plot.survfitr() method.
A ggplot object, which can be further styled with the usual
ggplot2 syntax.
plot.survfitr() for the base-graphics version,
plotEstimators() to compare the three estimators,
theme_survrec()
data(MMC) fit <- survfitr(Survr(id, time, event) ~ group, data = MMC, type = "wang-chang" ) autoplot(fit) autoplot(fit, fun = "cumhaz", conf.int = FALSE) # it is a ggplot, so it can be restyled autoplot(fit) + ggplot2::labs(title = "Migratory Motor Complex")data(MMC) fit <- survfitr(Survr(id, time, event) ~ group, data = MMC, type = "wang-chang" ) autoplot(fit) autoplot(fit, fun = "cumhaz", conf.int = FALSE) # it is a ggplot, so it can be restyled autoplot(fit) + ggplot2::labs(title = "Migratory Motor Complex")
Rehospitalization times after surgery in patients diagnosed with colorectal cancer.
coloncolon
A data frame with 861 rows and 6 columns:
subject identifier, repeated for each recurrence
rehospitalization or censoring gap time
censoring status: 1 for every rehospitalization, 0 for the last (censored) time of each subject
did the patient receive chemotherapy? 1: no, 2: yes
Dukes' tumoral stage: 1: A-B, 2: C, 3: D
distance from residence to hospital: 1: <= 30 km, 2: > 30 km
González, J.R., Fernandez, E., Moreno, V. et al. (2005). Sex differences in hospital readmission among colorectal cancer patients. Journal of Epidemiology and Community Health 59, 506–511.
Nonparametric (Nelson-Aalen type) estimate of the mean cumulative function, i.e. the expected number of events experienced by a subject up to each calendar time, optionally by group.
mcf(formula, data) ## S3 method for class 'mcf' print(x, ...)mcf(formula, data) ## S3 method for class 'mcf' print(x, ...)
formula |
a formula object with a |
data |
a data frame in which to interpret the variables named in the formula. |
x |
an |
... |
further arguments passed to |
Calendar times are reconstructed as the within-subject cumulative sums
of the gap times of the Survr() response. At each distinct event
calendar time the estimate increases by , where
is the number of events observed at and
the number of subjects still under observation (total observation time
).
An object of class mcf: a data frame with columns group,
time, n.event, n.risk and mcf, with print and autoplot
methods.
Lawless, J.F. and Nadeau, C. (1995). Some Simple Robust Methods for the Analysis of Recurrent Events. Technometrics 37, 158–168.
data(MMC) m <- mcf(Survr(id, time, event) ~ group, data = MMC) m autoplot(m)data(MMC) m <- mcf(Survr(id, time, event) ~ group, data = MMC) m autoplot(m)
Maximum likelihood estimation of the survival function of correlated inter-occurrence times of recurrent event data under a gamma frailty model.
mlefrailty_fit( x, tvals, lambda = NULL, alpha = NULL, alpha.min, alpha.max, tol = 1e-07, maxiter = 500, alpha.console = TRUE )mlefrailty_fit( x, tvals, lambda = NULL, alpha = NULL, alpha.min, alpha.max, tol = 1e-07, maxiter = 500, alpha.console = TRUE )
x |
a survival recurrent event object, see |
tvals |
optional vector of times at which the survival function is also evaluated. |
lambda |
optional vector of baseline hazard probabilities at the
distinct event times. Defaults to the occurrence/exposure rates
|
alpha |
optional shape and scale parameter of the frailty distribution. If unknown it is estimated via the EM algorithm, starting from a seed obtained by maximising the profile likelihood (see details). |
alpha.min |
optional left bound of the interval used to find the
seed of |
alpha.max |
optional right bound of the interval used to find the
seed of |
tol |
convergence tolerance of the EM algorithm. Default is 1e-7. |
maxiter |
maximum number of EM iterations. Default is 500. |
alpha.console |
if |
The product-limit estimator of Peña, Strawderman and Hollander (2001) is valid when the inter-occurrence times are an IID sample from some underlying distribution F. This assumption is clearly restrictive in biomedical applications, and one obvious generalization that allows association between inter-occurrence times is a frailty model.
A common and convenient choice of frailty distribution is a gamma with
shape and scale parameters set equal to an unknown parameter
. The common marginal survival function can be written as
The parameter controls the degree of association between
inter-occurrence times within a unit. Peña, Strawderman and Hollander
(2001) showed that and can be estimated by
maximising the marginal likelihood function with an
expectation-maximisation (EM) algorithm.
To achieve good convergence, a seed value for is estimated
first by maximising the profile likelihood for over the
interval (alpha.min, alpha.max) with Brent's method. If the EM
algorithm does not converge from that seed, it is restarted from up to
six additional seeds around it. If convergence still fails, the initial
value of alpha can be used as the alpha.min argument and the fit
recomputed.
A list with class survfitr containing:
number of units or subjects observed.
number of events of each subject.
uncensored gap times, ordered by subject.
censored gap time of each subject.
ordered distinct event times.
number of events at each distinct time.
matrix of units at risk at each distinct time (rows are subjects).
1 if the EM algorithm converged, -1 if it reached
maxiter without converging (in that case no estimates are
provided).
estimate of the gamma frailty parameter.
estimated hazard probabilities at the distinct event times.
posterior frailty estimate of each subject; values spread away from 1 indicate heterogeneity between subjects.
survival estimate at each distinct time.
copy of the tvals argument.
survival estimate at the tvals times.
Peña, E.A., Strawderman, R. and Hollander, M. (2001). Nonparametric Estimation with Recurrent Event Data. Journal of the American Statistical Association 96, 1299–1315.
data(MMC) fit <- mlefrailty_fit(Survr(MMC$id, MMC$time, MMC$event)) fit plot(fit) # compare with Peña-Strawderman-Hollander fit <- psh_fit(Survr(MMC$id, MMC$time, MMC$event)) lines(fit, lty = 2) # and with Wang-Chang fit <- wc_fit(Survr(MMC$id, MMC$time, MMC$event)) lines(fit, lty = 3)data(MMC) fit <- mlefrailty_fit(Survr(MMC$id, MMC$time, MMC$event)) fit plot(fit) # compare with Peña-Strawderman-Hollander fit <- psh_fit(Survr(MMC$id, MMC$time, MMC$event)) lines(fit, lty = 2) # and with Wang-Chang fit <- wc_fit(Survr(MMC$id, MMC$time, MMC$event)) lines(fit, lty = 3)
Times of the Migratory Motor Complex (MMC) of 19 healthy individuals, measured through small bowel manometry.
MMCMMC
A data frame with 99 rows and 4 columns:
subject identifier, repeated for each recurrence
recurrence or censoring gap time
censoring status: 1 for every recurrence, 0 for the last (censored) time of each subject
a factor with levels Males and Females. Note: the
groups were created at random to illustrate a group comparison
Husebye, E., Skar, V., Aalen, O.O. and Osnes, M. (1990). Digital ambulatory manometry of the small intestine in healthy adults. Digestive Diseases and Sciences 35, 1057–1065.
Plots the estimated survival (or probability) function from a
survfitr object, one curve per group when the fit has strata.
Additional fits can be added to the same axes with the lines method.
## S3 method for class 'survfitr' plot(x, conf.int = TRUE, prob = FALSE, ...) ## S3 method for class 'survfitr' lines(x, prob = FALSE, ...)## S3 method for class 'survfitr' plot(x, conf.int = TRUE, prob = FALSE, ...) ## S3 method for class 'survfitr' lines(x, prob = FALSE, ...)
x |
an object of class |
conf.int |
if |
prob |
if |
... |
additional arguments passed to |
No return value; called for its side effect.
psh_fit(), wc_fit(), mlefrailty_fit()
data(MMC) fit <- survfitr(Survr(id, time, event) ~ group, data = MMC, type = "wang-chang" ) plot(fit)data(MMC) fit <- survfitr(Survr(id, time, event) ~ group, data = MMC, type = "wang-chang" ) plot(fit)
Fits the Peña-Strawderman-Hollander, the Wang-Chang and the gamma frailty MLE estimators to the same sample and draws the three curves on the same axes. Agreement between the PSH and the frailty estimates suggests independent inter-occurrence times, while a Wang-Chang curve separated from the PSH one points to within-subject correlation.
plotEstimators(x, conf.int = FALSE, level = 0.95, alpha.console = FALSE, ...)plotEstimators(x, conf.int = FALSE, level = 0.95, alpha.console = FALSE, ...)
x |
a survival recurrent event object, see |
conf.int |
draw the pointwise confidence bands of the estimators
that provide them? Default |
level |
confidence level of the bands. |
alpha.console |
passed to |
... |
additional arguments passed to the three fitting functions. |
A ggplot object.
autoplot.survfitr(), psh_fit(), wc_fit(),
mlefrailty_fit()
data(MMC) plotEstimators(Survr(MMC$id, MMC$time, MMC$event))data(MMC) plotEstimators(Survr(MMC$id, MMC$time, MMC$event))
Prints, for each curve, the number of subjects, the number of events, the restricted mean survival and its standard error, the median survival and the minimum, maximum and median number of recurrences per subject.
## S3 method for class 'survfitr' print(x, scale = 1, digits = max(options()$digits - 4, 3), ...)## S3 method for class 'survfitr' print(x, scale = 1, digits = max(options()$digits - 4, 3), ...)
x |
the result of a call to |
scale |
a numeric value to rescale the survival time, e.g. if the
input data are in days, |
digits |
number of digits to print. |
... |
other unused arguments. |
The restricted mean and its standard error are based on a truncated estimator: if the survival curve does not reach zero, the reported quantity is the mean survival restricted to the time before the last censoring. The median is the time at which the survival curve crosses 0.5.
x, invisibly.
summary.survfitr(), survfitr()
data(MMC) fit <- survfitr(Survr(id, time, event) ~ group, data = MMC) print(fit)data(MMC) fit <- survfitr(Survr(id, time, event) ~ group, data = MMC) print(fit)
Estimates the survival function of the inter-occurrence times of recurrent event data with the generalized product-limit estimator (PLE) of Peña, Strawderman and Hollander (2001).
psh_fit(x, tvals)psh_fit(x, tvals)
x |
a survival recurrent event object, see |
tvals |
optional vector of times at which the survival function is also evaluated. |
The estimator computed by this function is the nonparametric estimator of the inter-event time survivor function under the assumption of a renewal or IID model. It generalizes the product-limit estimator to the situation where the event is recurrent. For details and the theory behind the estimator, please refer to Peña, Strawderman and Hollander (2001).
A list with class survfitr containing:
number of units or subjects observed.
number of events of each subject.
uncensored gap times, ordered by subject.
censored gap time of each subject.
ordered distinct event times.
number of events at each distinct time.
matrix of units at risk at each distinct time (rows are subjects).
survival estimate at each distinct time.
standard error of the survival estimate.
copy of the tvals argument.
survival estimate at the tvals times.
Peña, E.A., Strawderman, R. and Hollander, M. (2001). Nonparametric Estimation with Recurrent Event Data. Journal of the American Statistical Association 96, 1299–1315.
data(MMC) fit <- psh_fit(Survr(MMC$id, MMC$time, MMC$event)) fit plot(fit, conf.int = FALSE) # compare with the gamma frailty MLE fit <- mlefrailty_fit(Survr(MMC$id, MMC$time, MMC$event)) lines(fit, lty = 2) # and with Wang-Chang fit <- wc_fit(Survr(MMC$id, MMC$time, MMC$event)) lines(fit, lty = 3)data(MMC) fit <- psh_fit(Survr(MMC$id, MMC$time, MMC$event)) fit plot(fit, conf.int = FALSE) # compare with the gamma frailty MLE fit <- mlefrailty_fit(Survr(MMC$id, MMC$time, MMC$event)) lines(fit, lty = 2) # and with Wang-Chang fit <- wc_fit(Survr(MMC$id, MMC$time, MMC$event)) lines(fit, lty = 3)
Given a survfitr object, returns the first time at which the
estimated survival function falls to the quantile q or below.
q_search(f, q = 0.5)q_search(f, q = 0.5)
f |
a |
q |
quantile. Default is 0.5 (the median survival time). |
The survival time of the selected quantile, or NA (with a
warning) when the survival estimates are not available.
data(MMC) fit <- survfitr(Survr(id, time, event) ~ 1, data = MMC) # 75th percentile of the survival function q_search(fit, q = 0.75)data(MMC) fit <- survfitr(Survr(id, time, event) ~ 1, data = MMC) # 75th percentile of the survival function q_search(fit, q = 0.75)
Returns, for each requested probability p, the first time at which
the estimated survival function falls to 1 - p or below (so
probs = 0.5 is the median survival time). NA is returned when the
curve does not reach the requested level.
## S3 method for class 'survfitr' quantile(x, probs = c(0.25, 0.5, 0.75), ...)## S3 method for class 'survfitr' quantile(x, probs = c(0.25, 0.5, 0.75), ...)
x |
a |
probs |
vector of probabilities. |
... |
ignored; kept for compatibility with the generic. |
A named vector of survival times, or a matrix with one row per group when the fit has strata.
data(MMC) fit <- survfitr(Survr(id, time, event) ~ group, data = MMC, type = "wang-chang" ) quantile(fit, probs = c(0.25, 0.5, 0.75))data(MMC) fit <- survfitr(Survr(id, time, event) ~ group, data = MMC, type = "wang-chang" ) quantile(fit, probs = c(0.25, 0.5, 0.75))
Computes, for each group, the observed quantile and a percentile bootstrap confidence interval, and for each pair of groups the difference of quantiles with its percentile interval and a two-sided bootstrap p-value for the null hypothesis of no difference.
## S3 method for class 'survdiffr' summary(object, level = 0.95, ...) ## S3 method for class 'summary.survdiffr' print(x, digits = max(options()$digits - 4, 3), ...)## S3 method for class 'survdiffr' summary(object, level = 0.95, ...) ## S3 method for class 'summary.survdiffr' print(x, digits = max(options()$digits - 4, 3), ...)
object |
a grouped result of |
level |
confidence level of the percentile intervals. |
... |
ignored; kept for compatibility with the generic. |
x |
a |
digits |
number of digits to print. |
Replicates in which the survival estimate never fell below the
requested level are treated as +Inf (the quantile exceeds the
observed follow-up); pairs where both replicates are infinite are
dropped from the difference. The p-value is
over the replicated differences
.
A list of class summary.survdiffr with components groups
(data frame with the observed quantile and its interval per group)
and contrasts (data frame with the pairwise differences, intervals
and p-values).
data(colon) fit <- survdiffr(Survr(hc, time, event) ~ as.factor(dukes), data = colon, q = 0.5, seed = 1 ) summary(fit)data(colon) fit <- survdiffr(Survr(hc, time, event) ~ as.factor(dukes), data = colon, q = 0.5, seed = 1 ) summary(fit)
Returns a matrix with the distinct event times and, at each of them, the number of events, the number of subjects at risk, the survival estimate and (when available) its standard error. If the fit has multiple curves, a list with one matrix per curve is returned.
## S3 method for class 'survfitr' summary(object, ...) ## S3 method for class 'summary.survfitr' print(x, scale = 1, digits = max(options()$digits - 4, 3), ...)## S3 method for class 'survfitr' summary(object, ...) ## S3 method for class 'summary.survfitr' print(x, scale = 1, digits = max(options()$digits - 4, 3), ...)
object |
output of a call to |
... |
other unused arguments. |
x |
a |
scale |
a numeric value to rescale the survival time. |
digits |
number of digits to print. |
For a single curve, a matrix; for multiple curves, a list of
class summary.survfitr with one matrix per curve.
data(MMC) summary(survfitr(Survr(id, time, event) ~ group, data = MMC))data(MMC) summary(survfitr(Survr(id, time, event) ~ group, data = MMC))
Evaluates a step survival function at arbitrary times. The estimate is a decreasing piecewise-constant function with jumps at the event times, so the value at any time is the one of the previous event time.
surv_search(tvals, time, surv)surv_search(tvals, time, surv)
tvals |
vector of times at which the survival function is evaluated. |
time |
vector of ordered distinct event times. |
surv |
vector of survival estimates at each event time. |
The survival estimate at each of the tvals times.
time <- c(4, 7, 9, 15, 21, 67) surv <- c(0.8, 0.7, 0.65, 0.55, 0.43, 0.22) # survival at times 1, 10, 32 and 74 surv_search(c(1, 10, 32, 74), time, surv)time <- c(4, 7, 9, 15, 21, 67) surv <- c(0.8, 0.7, 0.65, 0.55, 0.43, 0.22) # survival at times 1, 10, 32 and 74 surv_search(c(1, 10, 32, 74), time, surv)
Obtains bootstrap replicates of a quantile (e.g. the median) of the
survival time for each group of subjects. Confidence intervals of the
replicates can be computed with boot::boot.ci().
survdiffr( formula, data, q, B = 500, boot.F = "WC", boot.G = "none", seed = NULL, ... )survdiffr( formula, data, q, B = 500, boot.F = "WC", boot.G = "none", seed = NULL, ... )
formula |
a formula object with a |
data |
a data frame in which to interpret the variables named in the formula. |
q |
quantile of the survival function whose time is bootstrapped. |
B |
number of bootstrap samples. |
boot.F |
a character string specifying the bootstrap procedure:
|
boot.G |
a character string specifying whether the censoring times
are also resampled from their empirical distribution: |
seed |
optional random seed for the bootstrap resampling (passed
to |
... |
additional arguments passed to the estimator used for the observed (non-bootstrap) quantile. |
Three resampling schemes are available through boot.F: nonparametric
resampling of gap times from the Peña-Strawderman-Hollander ("PSH")
or the Wang-Chang ("WC") estimates of the inter-occurrence time
distribution, and semiparametric resampling under the fitted gamma
frailty model ("semiparametric"). With boot.G = "empirical" the
per-subject censoring times are additionally resampled from their
empirical distribution.
All resampling uses R's random number generator, so results are
reproducible with set.seed() or the seed argument. The re-estimation
of the survival curve on each replicate can run in parallel, see
survrecThreads(). Some procedures (notably the semiparametric one,
which refits the frailty model on every replicate) can be slow.
An object of class boot (or a named list with one per group)
whose t0 is the observed quantile and t the bootstrap replicates.
A replicate is -1 when the survival estimate does not fall below
q, and NA when the resampled data had no events. For the
semiparametric procedure the component alpha contains the frailty
parameter estimated on each replicate.
González, J.R. and Peña, E.A. (2003). Bootstrapping median survival with recurrent event data. IX Conferencia Española de Biometría.
survfitr(), boot::boot.ci(), survrecThreads()
data(colon) # compare the median survival time between the three Dukes stages fit <- survdiffr(Survr(hc, time, event) ~ as.factor(dukes), data = colon, q = 0.5, seed = 1 ) boot::boot.ci(fit$"1", type = c("norm", "basic", "perc")) boot::boot.ci(fit$"2", type = c("norm", "basic", "perc")) boot::boot.ci(fit$"3", type = c("norm", "basic", "perc")) # 75th quantile with percentile confidence intervals fit <- survdiffr(Survr(hc, time, event) ~ as.factor(dukes), data = colon, q = 0.75, seed = 1 ) quantile(fit$"1"$t, c(0.025, 0.975)) # resampling from the PSH estimate instead fit <- survdiffr(Survr(hc, time, event) ~ as.factor(dukes), data = colon, q = 0.5, boot.F = "PSH", seed = 1 )data(colon) # compare the median survival time between the three Dukes stages fit <- survdiffr(Survr(hc, time, event) ~ as.factor(dukes), data = colon, q = 0.5, seed = 1 ) boot::boot.ci(fit$"1", type = c("norm", "basic", "perc")) boot::boot.ci(fit$"2", type = c("norm", "basic", "perc")) boot::boot.ci(fit$"3", type = c("norm", "basic", "perc")) # 75th quantile with percentile confidence intervals fit <- survdiffr(Survr(hc, time, event) ~ as.factor(dukes), data = colon, q = 0.75, seed = 1 ) quantile(fit$"1"$t, c(0.025, 0.975)) # resampling from the PSH estimate instead fit <- survdiffr(Survr(hc, time, event) ~ as.factor(dukes), data = colon, q = 0.5, boot.F = "PSH", seed = 1 )
Computes an estimate of the survival curve of inter-occurrence times for recurrent event data, optionally by group, using the Peña-Strawderman-Hollander, the Wang-Chang or the gamma frailty MLE estimators, together with their standard errors.
survfitr(formula, data, type = "MLEfrailty", ...)survfitr(formula, data, type = "MLEfrailty", ...)
formula |
a formula object with a |
data |
a data frame in which to interpret the variables named in the formula. |
type |
a character string specifying the estimator:
|
... |
additional arguments passed to the fitting function of the chosen estimator. |
See psh_fit(), wc_fit() and mlefrailty_fit() for details on each
estimator; additional arguments in ... are passed to the chosen
fitting function.
A survfitr object: the fit of the chosen estimator, or a
named list with one fit per group when the formula defines groups.
Methods are provided for print, plot, lines and summary.
Peña, E.A., Strawderman, R. and Hollander, M. (2001). Nonparametric Estimation with Recurrent Event Data. Journal of the American Statistical Association 96, 1299–1315.
Wang, M.-C. and Chang, S.-H. (1999). Nonparametric Estimation of a Recurrent Survival Function. Journal of the American Statistical Association 94, 146–153.
print.survfitr(), plot.survfitr(), summary.survfitr(),
Survr(), psh_fit(), wc_fit(), mlefrailty_fit()
data(colon) # fit a Peña-Strawderman-Hollander estimator by Dukes stage fit <- survfitr(Survr(hc, time, event) ~ as.factor(dukes), data = colon, type = "pena" ) plot(fit, ylim = c(0, 1), xlim = c(0, 2000)) fit summary(fit)data(colon) # fit a Peña-Strawderman-Hollander estimator by Dukes stage fit <- survfitr(Survr(hc, time, event) ~ as.factor(dukes), data = colon, type = "pena" ) plot(fit, ylim = c(0, 1), xlim = c(0, 2000)) fit summary(fit)
Creates a survival recurrent object, usually used as the response variable in a model formula.
Survr(id, time, event) is.Survr(x)Survr(id, time, event) is.Survr(x)
id |
identifier of each subject; the same value for all the recurrent times of a subject. |
time |
gap times of recurrence. The last time of each subject is censored. |
event |
status indicator: 1 = recurrence, 0 = censored. Only these values are accepted. |
x |
any R object. |
Each subject must contribute one censored time (its last, incomplete
gap time), so id must have exactly as many distinct values as there
are zeros in event. Rows are assumed to be grouped by subject and in
chronological order within subject.
An object of class Survr, implemented as a matrix with
columns id, time and event.
is.Survr() returns TRUE if x inherits from class Survr and
FALSE otherwise.
survfitr(), psh_fit(), wc_fit(), mlefrailty_fit()
data(MMC) x <- Survr(MMC$id, MMC$time, MMC$event) is.Survr(x)data(MMC) x <- Survr(MMC$id, MMC$time, MMC$event) is.Survr(x)
Gets or sets the maximum number of threads used by the parallel parts of
the package, currently the re-estimation phase of the bootstrap in
survdiffr(), which refits the survival curve once per bootstrap
replicate.
survrecThreads(n)survrecThreads(n)
n |
Maximum number of threads, or |
By default the package lets OpenMP decide, which means it honours the
OMP_NUM_THREADS environment variable. Set this option to cap the
number of threads regardless of that variable, for instance when
running inside a shared machine or a job scheduler.
The bootstrap resampling itself always runs serially because it draws
from R's random number generator (which is not thread-safe); results are
therefore reproducible with set.seed() independently of the number of
threads.
If the package was built without OpenMP support (which is the case with the default compiler on macOS), the computation runs sequentially and this setting has no effect.
The current setting, invisibly when it is being changed.
NULL means "let OpenMP decide".
survrecThreads() # current setting old <- survrecThreads(2) survrecThreads(old) # restoresurvrecThreads() # current setting old <- survrecThreads(2) survrecThreads(old) # restore
A clean ggplot2 theme shared by all the plotting functions of the
package: light horizontal grid, no panel border, muted axis text and
room for the legend at the bottom. Exported so that the figures of a
report can be restyled consistently. It matches the theme of the
companion package gcmrec.
theme_survrec(base_size = 12)theme_survrec(base_size = 12)
base_size |
Base font size in points. |
A ggplot2 theme object, to be added to any plot.
data(MMC) fit <- survfitr(Survr(id, time, event) ~ group, data = MMC, type = "wang-chang" ) autoplot(fit) + theme_survrec(base_size = 14)data(MMC) fit <- survfitr(Survr(id, time, event) ~ group, data = MMC, type = "wang-chang" ) autoplot(fit) + theme_survrec(base_size = 14)
Estimates the survival function of correlated or i.i.d. inter-occurrence times of recurrent event data with the product-limit estimator of Wang and Chang (1999).
wc_fit(x, tvals)wc_fit(x, tvals)
x |
a survival recurrent event object, see |
tvals |
optional vector of times at which the survival function is also evaluated. |
Wang and Chang (1999) proposed an estimator of the common marginal survivor function for the case where within-unit inter-occurrence times are correlated. The correlation structure they considered is quite general and contains both the i.i.d. and the multiplicative (hence gamma) frailty model as special cases.
This estimator removes the bias noted for the product-limit estimator of Peña, Strawderman and Hollander (2001) when inter-occurrence times are correlated within units. However, when applied to i.i.d. inter-occurrence times it is not expected to perform as well as the PSH estimator, especially with regard to efficiency.
A list with class survfitr containing:
number of units or subjects observed.
number of events of each subject.
uncensored gap times, ordered by subject.
censored gap time of each subject.
ordered distinct event times.
weighted number of events at each distinct time.
weighted number of units at risk at each distinct time.
survival estimate at each distinct time.
standard error of the survival estimate.
copy of the tvals argument.
survival estimate at the tvals times.
The maintainers wish to thank Professors Chiung-Yu Huang and Shu-Hui Chang for providing the original Fortran code computing the standard errors of Wang and Chang's estimator.
Wang, M.-C. and Chang, S.-H. (1999). Nonparametric Estimation of a Recurrent Survival Function. Journal of the American Statistical Association 94, 146–153.
data(MMC) fit <- wc_fit(Survr(MMC$id, MMC$time, MMC$event)) fit plot(fit, conf.int = FALSE) # compare with Peña-Strawderman-Hollander fit <- psh_fit(Survr(MMC$id, MMC$time, MMC$event)) lines(fit, lty = 2) # and with the gamma frailty MLE fit <- mlefrailty_fit(Survr(MMC$id, MMC$time, MMC$event)) lines(fit, lty = 3)data(MMC) fit <- wc_fit(Survr(MMC$id, MMC$time, MMC$event)) fit plot(fit, conf.int = FALSE) # compare with Peña-Strawderman-Hollander fit <- psh_fit(Survr(MMC$id, MMC$time, MMC$event)) lines(fit, lty = 2) # and with the gamma frailty MLE fit <- mlefrailty_fit(Survr(MMC$id, MMC$time, MMC$event)) lines(fit, lty = 3)