| WA_fit | R Documentation |
Fits the while-alive regression model targeting the while-alive loss rate
for composite endpoints with recurrent and terminal events. Time-varying
covariate effects are represented via user-chosen time bases (e.g., B-spline,
piecewise polynomial, interval-local). Robust inference supports
cluster-randomized trials (CRTs) via cluster-robust variance; if
cluster = NULL, IID (subject-as-cluster) variance is used.
WA_fit(
formula,
data,
id,
cluster = NULL,
knots,
tau_grid,
basis = c("il", "pl", "bz", "ns", "ms", "st", "tl", "tf"),
degree = 1,
link = c("log", "identity"),
w_recur,
w_term,
ipcw = c("km", "cox"),
ipcw_formula = ~1
)
formula |
A |
data |
Long-format data frame with one row per event/checkpoint
per subject, containing |
id |
Character scalar; subject ID column name. |
cluster |
Optional character scalar; cluster column name for CRT-robust
inference. If |
knots |
Numeric vector (length |
tau_grid |
Numeric vector of evaluation times used to stack the
estimating equations. Independent of |
basis |
One of |
degree |
Integer degree for bases that use it (e.g., |
link |
Link function: |
w_recur |
Numeric vector of weights for each recurrent event type. Its
length must match the number of recurrent |
w_term |
Numeric scalar; weight for the terminal event. |
ipcw |
IPCW method: |
ipcw_formula |
A one-sided formula specifying RHS covariates for the IPCW Cox model
when |
The estimating equations solve E[Z(t)\{L(t) - \mu_\beta(t)X_{\min}(t)\}V/G]=0
over tau_grid, where L(t) is the weighted composite loss
(recurrent+terminal), \mu_\beta(t) the while-alive loss rate under the chosen
link, X_{\min}(t) = \min(T, t), V the at-risk/terminal indicator, and
G the censoring survival modeled via ipcw.
An object of class "WA" with elements:
est: named coefficient vector.
vcov: cluster-robust variance matrix.
se: standard errors.
converged: logical.
basis, degree, link, Z_cols,
knots, tau_grid, id_var, cluster_var,
w_recur, w_term, status_codes, formula.
ex_dt <- crt_dt[crt_dt$cluster %in% c(1,2,3,4,7,10), ]
fit <- WA_fit(
survival::Surv(time, status) ~ trt + Z1 + Z2,
data = ex_dt,
id = "id",
cluster = "cluster",
knots = seq(0, max(ex_dt$time, na.rm = TRUE), length.out = 6),
tau_grid = seq(0, max(ex_dt$time, na.rm = TRUE), length.out = 6),
basis = "bz", degree = 1, link = "log",
w_recur = c(1, 1), w_term = 2,
ipcw = "km"
)
s <- summary(fit)
nd <- unique(ex_dt[, c("trt","Z1","Z2")])
plot(fit, newdata = nd,
t_seq = seq(0, max(fit$tau_grid), length.out = 200),
id = 1, mode = "wa", smooth = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.