Skip to contents

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

Usage

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

Arguments

x

(numeric())
Survival/CDF/CIF vector at given time points. Optionally named with the corresponding times.

times

(numeric() | NULL)
Original time points corresponding to x. If NULL, extracted from names(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 (default), perform simple validation (range, monotonicity, and bounds). Set to FALSE to skip checks (NOT recommended for external use).

Value

A numeric vector of length length(eval_times) with interpolated values.

Examples

surv_vec = c(1, 0.8, 0.6)
names(surv_vec) = c(0, 10, 20)
eval_times = c(5, 15, 25)
vec_interp(surv_vec, eval_times = eval_times, type = "surv")
#>   5  15  25 
#> 1.0 0.8 0.6