Skip to contents

Wrapper around the internal C++ interpolation function c_mat_interp. Performs input validation before calling the underlying C++ code. Can be used for survival, cumulative distribution (CDF), or cumulative incidence (CIF) matrices.

Usage

mat_interp(
  x,
  times = NULL,
  eval_times = NULL,
  constant = TRUE,
  type = "surv",
  add_times = TRUE,
  check = TRUE
)

Arguments

x

(matrix())
Survival/CDF/CIF matrix with rows as observations and columns as time points.

times

(numeric() | NULL)
Original time points corresponding to columns of x.

eval_times

(numeric() | NULL)
New time points at which to interpolate. Values do not need to be sorted or unique, just non-negative. If NULL, x is returned unchanged.

constant

(logical(1))
If TRUE (default), use piecewise-constant (left-continuous) interpolation. If FALSE, use piecewise-linear interpolation.

type

(character(1))
One of "surv" (default), "cdf", or "cif", indicating the input data type.

add_times

(logical(1))
If TRUE (default), column names are set to the relevant time points.

check

(logical(1))
If TRUE, run input matrix validation via assert_prob_matrix(); set to FALSE to skip checks (NOT recommended for external use).

Value

A numeric matrix with the same number of rows as x and number of columns equal to length(eval_times).

Examples

x = matrix(c(1, 0.8, 0.6,
             1, 0.7, 0.4),
           nrow = 2, byrow = TRUE)
times = c(0, 10, 20)
eval_times = c(5, 15, 25, 15) # duplicates & unordered
mat_interp(x, times, eval_times, constant = TRUE, type = "surv")
#>      5  15  25  15
#> [1,] 1 0.8 0.6 0.8
#> [2,] 1 0.7 0.4 0.7