| survDistr | R Documentation |
survDistr is an R6 specialized container designed for storing and managing prediction outputs from survival models in single-event settings. This includes models such as Cox proportional hazards, random survival forests, and other classical or machine learning-based survival estimators.
The main prediction data type is survival matrix, where rows represent observations and columns represent time points.
Key design features:
The survival matrix is stored internally and can be accessed using the $data() method.
The $times active field provides the time points corresponding to the matrix columns.
The interpolation method is controlled via the $method active field.
Survival-related quantities (e.g., distribution, density, hazard functions) are
interpolated using the interp() function.
The assert_prob() function validates the input data matrix during construction if
check is set to TRUE.
Use the $filter() method to subset observations in-place by filtering rows of the
stored matrix.
Use trim_dups = TRUE in the constructor to remove flat survival segments (repeated
values across time points) with a pre-specified tolerance (for a more controlled
pre-processing, see trim_duplicates()).
times(numeric)
Numeric vector of time points corresponding to columns of data. Read-only.
method(character(1))
Interpolation method; one of "const_surv" (default), "const_dens" (alias: "linear_surv")
and "const_haz" (alias: "exp_surv").
new()Creates a new instance of this R6 class.
survDistr$new( x, times = NULL, method = "const_surv", check = TRUE, trim_dups = FALSE )
x(matrix)
A numeric matrix of survival probabilities (values between 0 and 1).
Column names must correspond to time points if times is NULL.
times(numeric())
Numeric vector of time points for matrix x,
must match the number of columns.
method(character(1))
Interpolation method; one of "const_surv" (default), "const_dens" (alias: "linear_surv")
and "const_haz" (alias: "exp_surv").
check(logical(1))
If TRUE, run input matrix validation checks using assert_prob();
set to FALSE to skip checks (NOT recommended for external use).
trim_dups(logical(1))
If TRUE, removes adjacent duplicate values from the input using trim_duplicates().
This eliminates flat segments in survival curves and improves interpolation efficiency.
Default is FALSE.
print()Displays summary information about a survDistr object, including the number of observations and time points.
survDistr$print()
data()Return the stored data matrix.
survDistr$data(rows = NULL, add_times = TRUE)
rows(integer() | logical() | NULL)
Row indices or a logical vector used to filter observations.
Logical vectors must have length equal to the number of observations.
Integer indices must be positive and within range.
If NULL, no filtering is applied.
add_times(logical(1))
If TRUE, attach eval_times to the output.
(matrix)
filter()Filters observations in-place by subsetting rows of the stored matrix.
survDistr$filter(rows = NULL)
rows(integer() | logical() | NULL)
Row indices or a logical vector used to filter observations.
Logical vectors must have length equal to the number of observations.
Integer indices must be positive and within range.
If NULL, no filtering is applied.
Invisibly returns the survDistr object itself.
survival()Computes survival probabilities S(t) at the specified time points.
survDistr$survival(rows = NULL, times = NULL, add_times = TRUE)
rows(integer() | logical() | NULL)
Row indices or a logical vector used to filter observations.
Logical vectors must have length equal to the number of observations.
Integer indices must be positive and within range.
If NULL, no filtering is applied.
times(numeric)
New time points at which to interpolate.
Values need to be unique, increasing non-negative numbers.
If NULL, the object's stored time points are used.
add_times(logical(1))
If TRUE, attach eval_times to the output.
a matrix of survival probabilities (rows = observations, columns = time points).
distribution()Computes the cumulative distribution function F(t) = 1 - S(t) or CDF at the specified time points.
F(t) is the probability that the event has occurred up until time t.
survDistr$distribution(rows = NULL, times = NULL, add_times = TRUE)
rows(integer() | logical() | NULL)
Row indices or a logical vector used to filter observations.
Logical vectors must have length equal to the number of observations.
Integer indices must be positive and within range.
If NULL, no filtering is applied.
times(numeric)
New time points at which to interpolate.
Values need to be unique, increasing non-negative numbers.
If NULL, the object's stored time points are used.
add_times(logical(1))
If TRUE, attach eval_times to the output.
a matrix of CDF values (rows = observations, columns = time points).
density()Computes the probability density function f(t) or PDF at the specified time points.
f(t) = \frac{d}{dt} F(t) is the probability of the event occurring at the specific
time t.
survDistr$density(rows = NULL, times = NULL, add_times = TRUE)
rows(integer() | logical() | NULL)
Row indices or a logical vector used to filter observations.
Logical vectors must have length equal to the number of observations.
Integer indices must be positive and within range.
If NULL, no filtering is applied.
times(numeric)
New time points at which to interpolate.
Values need to be unique, increasing non-negative numbers.
If NULL, the object's stored time points are used.
add_times(logical(1))
If TRUE, attach eval_times to the output.
a matrix of PDF values (rows = observations, columns = time points).
cumhazard()Computes the cumulative hazard (accumulated risk up to time t) at the specified time
points as H(t) = -log(S(t)).
survDistr$cumhazard(rows = NULL, times = NULL, add_times = TRUE, eps = 1e-12)
rows(integer() | logical() | NULL)
Row indices or a logical vector used to filter observations.
Logical vectors must have length equal to the number of observations.
Integer indices must be positive and within range.
If NULL, no filtering is applied.
times(numeric)
New time points at which to interpolate.
Values need to be unique, increasing non-negative numbers.
If NULL, the object's stored time points are used.
add_times(logical(1))
If TRUE, attach eval_times to the output.
eps(numeric(1))
Small positive value used to replace extremely low survival probabilities when computing cumulative hazard,
preventing numerical instability in -\log S(t) calculations.
a matrix of cumulative hazards (rows = observations, columns = time points).
hazard()Computes the hazard h(t) = \frac{f(t)}{S(t)} at the specified time points.
Hazard is the conditional instantaneous event rate at time t given
survival up to time t.
survDistr$hazard(rows = NULL, times = NULL, add_times = TRUE)
rows(integer() | logical() | NULL)
Row indices or a logical vector used to filter observations.
Logical vectors must have length equal to the number of observations.
Integer indices must be positive and within range.
If NULL, no filtering is applied.
times(numeric)
New time points at which to interpolate.
Values need to be unique, increasing non-negative numbers.
If NULL, the object's stored time points are used.
add_times(logical(1))
If TRUE, attach eval_times to the output.
a matrix of hazard values (rows = observations, columns = time points).
clone()The objects of this class are cloneable with this method.
survDistr$clone(deep = FALSE)
deepWhether to make a deep clone.
# generate survival matrix
mat = matrix(data = c(1,0.6,0.4,0.8,0.8,0.7), nrow = 2,
ncol = 3, byrow = TRUE)
times = c(12, 34, 42)
x = survDistr$new(mat, times)
x
# stored survival matrix
x$data()
# interpolation method
x$method
# time points
x$times
eval_times = c(10, 30, 42, 50)
# S(t) at given time points (constant interpolation)
x$survival(times = eval_times)
# same but with linear interpolation
x$method = "linear_surv"
x$survival(times = eval_times)
# Cumulative hazard
x$cumhazard(times = eval_times)
# Density
x$density(times = eval_times)
# Hazard
x$hazard(times = eval_times)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.