Create a survival curves object, which stores survival probabilities at various time points for multiple individuals.

survival_curves(time, id, survival, sort = TRUE)

Arguments

time

The times at which the survival probabilities were computed at.

id

An identifier for each individual. May either be a numeric vector, integer vector, character vector, or factor.

survival

A vector of estimates of the survival probabilities.

sort

Whether to sort the returned data frame to ensure that rows are sorted by id andtime as required by rsurv.survival_curves().

See also

survival_curves objects can can also be constructed from a data.frame using as_survival_curves(). The purpose of the survival_curves class is for storing survival curves in a standardized format so that survival times can be randomly drawn from them using rsurv.survival_curves().

Examples

# Compute survival probabilities by individual and time id <- 1:3 # 3 individuals n_id <- length(id) times1 <- seq(0, 30, 1/12) # Times for 1 individual n_times <- length(times1) times <- rep(times1, length(id)) # Times for all individuals rates <- rep(runif(n_id, .2, .5), each = n_times) surv <- 1 - pexp(times, rates) # Survival probabilities # Construct a survival curves object sc <- survival_curves(time = times, id = rep(id, each = n_times), survival = surv) class(sc)
#> [1] "survival_curves" "data.frame"
head(sc)
#> time id survival #> 1 0.00000000 1 1.0000000 #> 2 0.08333333 1 0.9757485 #> 3 0.16666667 1 0.9520852 #> 4 0.25000000 1 0.9289957 #> 5 0.33333333 1 0.9064662 #> 6 0.41666667 1 0.8844831
tail(sc)
#> time id survival #> 1078 29.58333 3 0.0004794866 #> 1079 29.66667 3 0.0004692741 #> 1080 29.75000 3 0.0004592791 #> 1081 29.83333 3 0.0004494969 #> 1082 29.91667 3 0.0004399231 #> 1083 30.00000 3 0.0004305532