WA_cv: K-fold cross-validation for WA configuration selection

WA_cvR Documentation

K-fold cross-validation for WA configuration selection

Description

Runs K-fold CV over a grid of basis types, degrees, interior-knot counts, and link functions. For each configuration, fits the model on K-1 folds and accumulates the prediction error (PE) on the held-out fold using WA_PE() (IPCW computed on the training subjects).

Usage

WA_cv(
  formula,
  data,
  id,
  cluster = NULL,
  basis_set = c("il", "pl", "bz"),
  degree_vec = 1:2,
  n_int_vec = c(0, 2, 4),
  knot_scheme = c("equidist", "quantile"),
  link_set = c("log"),
  time_range = NULL,
  tau_grid = NULL,
  w_recur,
  w_term,
  ipcw = c("cox", "km"),
  ipcw_formula = ~1,
  K = 5,
  seed = 1L,
  verbose = TRUE
)

Arguments

formula

A Surv(time, status) ~ RHS formula; see WA_fit.

data

Long-format data frame; see WA_fit.

id

Character scalar; subject ID column name; see WA_fit.

cluster

Optional character scalar; cluster column name; see WA_fit.

basis_set

Character vector of candidate bases.

degree_vec

Integer vector of candidate degrees.

n_int_vec

Integer vector of interior-knot counts; 0 means boundaries only.

knot_scheme

"equidist" or "quantile" to construct interior knots.

link_set

Character vector of candidate links (subset of c("log","identity")).

time_range

Optional numeric length-2 vector c(tmin, tmax). If NULL, inferred from data.

tau_grid

Optional numeric vector; if NULL, a default dense grid over time_range is created.

w_recur

recurrent-event weights

w_term

Numeric scalar; terminal-event weight; see WA_fit.

ipcw

IPCW method ("cox" or "km") for PE computation.

ipcw_formula

One-sided RHS formula for IPCW Cox model (if ipcw="cox").

K

Number of folds.

seed

RNG seed for fold assignment.

verbose

Logical; show a text progress bar and per-fold messages.

Value

A data frame with columns: basis, degree, n_int, link, and aggregated PE. Lower PE is better.


WAreg documentation built on March 6, 2026, 5:07 p.m.

Related to WA_cv in WAreg...