Learn R Programming

eha (version 2.11.2)

SurvSplit: Split a survival object at specified durations.

Description

Given a survival object, (a matrix with two or three columns) and a set of specified cut times, split each record into multiple subrecords at each cut time. The new survival object will be in `counting process' format, with an enter time, exit time, and event status for each record.

Usage

SurvSplit(Y, cuts)

Value

A list with components

Y

The new survival object with three columns, i.e., in 'counting process' form.

ivl

Interval No., starting from leftmost, (0, cuts[1]) or similar.

idx

Row number for original Y row.

Arguments

Y

A survival object, a matrix with two or three columns.

cuts

The cut points, must be strictly positive and distinct.

Author

Göran Broström

See Also

survSplit, age.window.

Examples

Run this code

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(Y, cuts){
    if (NCOL(Y) == 2) Y <- cbind(rep(0, NROW(Y)), Y)
    indat <- cbind(Y, 1:NROW(Y), rep(-1, NROW(Y)))
    colnames(indat) <- c("enter", "exit", "event", "idx", "ivl")
    n <- length(cuts)
    cuts <- sort(cuts)
    if ((cuts[1] <= 0) || (cuts[n] == Inf))
        stop("'cuts' must be positive and finite.")
    cuts <- c(0, cuts, Inf)
    n <- n + 1
    out <- list()
    indat <- as.data.frame(indat)
    for (i in 1:n){
        out[[i]] <- age.window(indat, cuts[i:(i+1)])
        out[[i]]$ivl <- i
        out[[i]] <- t(out[[i]])
    }
    Y <- matrix(unlist(out), ncol = 5, byrow = TRUE)
    colnames(Y) <- colnames(indat)
    list(Y = Y[, 1:3],
         ivl = Y[, 5],
         idx = Y[, 4]
         )
  }

Run the code above in your browser using DataLab