tests/testthat/helper.R

library(checkmate)

gen_random_mat = function(nrows, ncols, type = "surv") {
  x = matrix(runif(nrows * ncols), nrow = nrows, ncol = ncols)

  if (type == "surv") {
    # sort each row in decreasing order => S(t)
    t(apply(x, 1, function(row) sort(row, decreasing = TRUE)))
  } else if (type == "cdf" || type == "cif") {
    # CDF/CIF => increasing values
    t(apply(x, 1, function(row) sort(row, decreasing = FALSE)))
  } else if (type == "prob" || type == "haz" || type == "dens") {
    # no monotonicity requirement, just probabilities
    x
  } else {
    stop("Invalid type")
  }
}

Try the survdistr package in your browser

Any scripts or data that you put into this service are public.

survdistr documentation built on April 9, 2026, 5:09 p.m.