R {mlt} | R Documentation |
Response Variables
Description
Represent a possibly censored or truncated response variable
Usage
R(object, ...)
## S3 method for class '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 class 'ordered'
R(object, cleft = NA, cright = NA, ...)
## S3 method for class 'integer'
R(object, cleft = NA, cright = NA, bounds = c(min(object), Inf), ...)
## S3 method for class 'factor'
R(object, ...)
## S3 method for class 'Surv'
R(object, as.R.ordered = FALSE, as.R.interval = FALSE, ...)
as.Surv(object)
## S3 method for class 'response'
as.Surv(object)
## S3 method for class 'response'
as.double(x, ...)
Arguments
object |
A vector of (conceptually) exact measurements or an object of class
|
x |
same as |
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 |
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 |
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 object
s). 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, doi:10.18637/jss.v092.i01
Examples
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)