Assert probability matrix or vector
assert_prob.RdValidates that the input is a proper probability matrix or vector representing either a survival function, cumulative distribution function (CDF), cumulative incidence function (CIF), discrete hazard, or discrete density.
Details
The following conditions must hold:
The input
xis a numeric matrix with no missing values.Time points (
times) are numeric, non-negative, unique, and increasing. If not supplied, they are derived from(col)names(x)(coerced tonumeric).All values are valid probabilities, i.e. lie in \([0,1]\).
Each row is monotone:
"surv": non-increasing survival curves, i.e. \(S(t_i) \ge S(t_{i+1})\)."cdf"/"cif": non-decreasing functions, i.e. \(F(t_i) \le F(t_{i+1})\)."haz"/"dens": no monotonicity requirement.
Boundary condition at
t = 0:"surv": \(S(0) = 1\)."cdf"/"cif": \(F(0) = 0\)."haz"/"dens": \(t_1 > 0\) (otherwise, nonzero hazard/density att = 0implies \(S(0) \neq 1\))
Examples
x = matrix(data = c(1, 0.6, 0.4,
0.8, 0.8, 0.7),
nrow = 2, ncol = 3, byrow = TRUE)
# Explicitly provide time points
assert_prob(x, times = c(12, 34, 42), type = "surv")
# Or use column names as time points
colnames(x) = c(12, 34, 42)
assert_prob(x)
# check CDF
assert_prob(1 - x, type = "cdf")
# check discrete hazards
assert_prob(c(0.2, 0.01, 0.3), times = c(1, 2, 3), type = "haz")
# check discrete densities
assert_prob(c(0.2, 0.01, 0.3), times = c(1, 2, 3), type = "dens")