Surv2: Construct survival object from event and would-be-censored...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/transform.R

Description

Convenience function to construct survival object from time to event (NA if event did not occur) and would-be-censored time (used if event did not occur).

Usage

1
Surv2(tevent, tcensor)

Arguments

tevent

Vector of times until event, with NA indicating event did not occur

tcensor

Vector of would-be-censored times at which censoring would occur if event did not occur

Details

Right censored survival objects are normally constructed using Surv, specifying the time (until either event or censoring) and an indicator variable (censored or event).

In some applications it may be more natural to construct the same survival object using two times: the time until the event (may be NA if the event never occurs), and the “would-be-censored” time, which is the time at which censoring would occur if the event has not occured first. Surv2 provides a convenience wrapper for this method of construction.

The arguments tevent and tcensor should be numeric vectors of equal length. Elementwise: An event is determined to have occurred if tevent is nonmissing and less than or equal to tcensor. The survival time is tevent if an event has occurred, and tcensor otherwise. A survival object is created with this time and event status with a call to Surv.

Value

An object of class Surv.

Author(s)

Toby Johnson Toby.x.Johnson@gsk.com

See Also

Surv

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
library(survival)
n <- 500 # sample size
tevent <- ifelse(rbinom(n, 1, 0.9) == 1, rexp(n, 0.1), NA)  # time until event
tcensor <- runif(n, 0, 5) # length of followup
mys <- Surv2(tevent, tcensor)
stopifnot(is.Surv(mys))
stopifnot(!any(is.na(mys)))
## check definition
stopifnot(identical(mys[ , "status"],
                    ifelse(!is.na(tevent) & tevent <= tcensor, 1, 0)))
stopifnot(all(mys[is.na(tevent), "status"] == 0))

tobyjohnson/gtx documentation built on Aug. 30, 2019, 8:07 p.m.