Learn R Programming

mlt (version 1.6-0)

R: Response Variables

Description

Represent a possibly censored or truncated response variable

Usage

R(object, ...)
# S3 method for numeric
R(object = NA, cleft = NA, cright = NA,
   tleft = NA, tright = NA, tol = sqrt(.Machine$double.eps), 
   as.R.ordered = FALSE, as.R.interval = FALSE, ...)
# S3 method for ordered
R(object, cleft = NA, cright = NA, ...)
# S3 method for integer
R(object, cleft = NA, cright = NA, bounds = c(min(object), Inf), ...)
# S3 method for factor
R(object, ...)
# S3 method for Surv
R(object, as.R.ordered = FALSE, as.R.interval = FALSE, ...)
as.Surv(object)
# S3 method for response
as.Surv(object)
# S3 method for response
as.double(x, ...)

Arguments

object

A vector of (conceptually) exact measurements or an object of class response (for as.Surv) or a list.

x

same as object.

cleft

A vector of left borders of censored measurements

cright

A vector of right borders of censored measurements

tleft

A vector of left truncations

tright

A vector of right truncations

tol

Tolerance for checking if cleft < cright

bounds

Range of possible values for integers

as.R.ordered

logical, should numeric responses or right-censored (and possible left-truncated survival) times be coded as ordered factor? This leads to a parameterisation allowing to maximise the nonparametric maximum likelihood

as.R.interval

logical, should numeric responses be coded for the nonparametric maximum likelihood

...

other arguments, ignored except for tleft and tright to R.ordered and R.integer

Details

R is basically an extention of Surv for the representation of arbitrarily censored or truncated measurements at any scale. The storage.mode of object determines if models are fitted by the discrete likelihood (integers or factors) or the continuous likelihood (log-density for numeric objects). Interval-censoring is given by intervals (cleft, cright], also for integers and factors (see example below). Left- and right-truncation can be defined by the tleft and tright arguments. Existing Surv objects can be converted using R(Surv(...))$ and, in some cases, an as.Surv() method exists for representing response objects as Surv objects.

R applied to a list calls R for each of the list elements and returns a joint object.

More examples can be found in Hothorn (2018) and in vignette("tram", package = "tram").

References

Torsten Hothorn (2020), Most Likely Transformations: The mlt Package, Journal of Statistical Software, 92(1), 1--68, tools:::Rd_expr_doi("10.18637/jss.v092.i01")

Examples

Run this code

 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