SurvSplit | R Documentation |
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.
SurvSplit(Y, cuts)
Y |
A survival object, a matrix with two or three columns. |
cuts |
The cut points, must be strictly positive and distinct. |
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. |
This function is used in phreg
for the piecewise
constant hazards model. It uses age.window
for each interval.
Göran Broström
survSplit
, age.window
.
##---- 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]
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.