library("survival")
### randomly right-censored continuous observations
time <- as.double(1:9)
event <- rep(c(FALSE, TRUE), length = length(time))
Surv(time, event)
R(Surv(time, event))
### right-censoring, left-truncation
ltm <- 1:9 / 10
Surv(ltm, time, event)
R(Surv(ltm, time, event))
### interval-censoring
Surv(ltm, time, type = "interval2")
R(Surv(ltm, time, type = "interval2"))
### interval-censoring, left/right-truncation
lc <- as.double(1:4)
lt <- c(NA, NA, 7, 8)
rt <- c(NA, 9, NA, 10)
x <- c(3, NA, NA, NA)
rc <- as.double(11:14)
R(x, cleft = lt, cright = rt)
as.Surv(R(x, cleft = lt, cright = rt))
R(x, tleft = 1, cleft = lt, cright = rt)
R(x, tleft = 1, cleft = lt, cright = rt, tright = 15)
R(x, tleft = lc, cleft = lt, cright = rt, tright = rc)
### discrete observations: counts
x <- 0:9
R(x)
### partially interval-censored counts
rx <- c(rep(NA, 6), rep(15L, 4))
R(x, cright = rx)
### ordered factor
x <- gl(5, 2, labels = LETTERS[1:5], ordered = TRUE)
R(x)
### interval-censoring (ie, observations can have multiple levels)
lx <- ordered(c("A", "A", "B", "C", "D", "E"),
levels = LETTERS[1:5], labels = LETTERS[1:5])
rx <- ordered(c("B", "D", "E", "D", "D", "E"),
levels = LETTERS[1:5], labels = LETTERS[1:5])
R(rx, cleft = lx, cright = rx)
### facilitate nonparametric maximum likelihood
(y <- round(runif(10), 1))
R(y, as.R.ordered = TRUE)
R(Surv(time, event), as.R.ordered = TRUE)
R(Surv(ltm, time, event), as.R.ordered = TRUE)
Run the code above in your browser using DataLab