tests/testthat/helper-data.R

# Shared fixtures for the test suite.  Deterministic given the seed; the
# core DSA search uses no RNG for vfold = 1, so fits on this data are
# reproducible and suitable for golden-value tests.

make_matrix_data <- function(n = 200, seed = 42) {
  set.seed(seed)
  X <- data.frame(
    a = rnorm(n),
    b = runif(n, 0, 10),
    c = sample(1:50, n, TRUE),
    f = factor(sample(c("x", "y", "z"), n, TRUE))
  )
  yN <- with(X, 2 * a - 0.3 * b + rnorm(n))
  yF <- factor(ifelse(yN > median(yN), "hi", "lo"))
  yF3 <- factor(sample(c("A", "B", "C"), n, TRUE))
  Ti <- rexp(n, rate = exp(-0.4 * X$a))
  ev <- rbinom(n, 1, 0.7)
  yS <- survival::Surv(Ti, ev)
  list(X = X, Xn = X[, c("a", "b", "c")], yN = yN, yF = yF, yF3 = yF3, yS = yS)
}

ctl0 <- function(...) {
  DSA.control(vfold = 1, minsplit = 30, minbuck = 10, cut.off.growth = 4,
              missing = "no", ...)
}

Try the partDSA package in your browser

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

partDSA documentation built on July 8, 2026, 9:06 a.m.