tda_zreg/tda_zreg1 are TDA's zreg/zreg1:
least squares with a censoring indicator, a Buckley-James estimator
where right-censored cases are iteratively reweighted rather than
dropped or treated as exact.
Arguments
- formula
a two-sided formula.
- data
a data frame.
- censor
the censoring indicator, as a name or a vector:
TRUEor 1 marks a case whose response is censored, as insurvival::Surv. See Details for how this maps to TDA'syw=.- options
a named list of further TDA options, passed through.
- dir
working directory.
- ...
passed to
tda_run.- dates
for
tda_zreg1, the names of the event-date columns indata–zreg1'sxv=; each becomes the time-varying indicatordate <= tat every step.
Details
censor follows R's convention (survival::Surv()'s):
TRUE or 1 marks a case whose response is censored. TDA's
own yw= runs the other way – a case counts as exact when
its indicator is zero – so this is translated for you, the same
correction tda_lsreg1 documents for its cen=.
Sent through unflipped, zreg recovers essentially nothing of a
known relationship (a near-zero slope); flipped, it recovers it
closely, checked against the uncensored least-squares fit.
The iteration often hits mxit (default 20) without TDA's
tolerance test passing, even once the estimates have stopped moving –
tda_run then warns “TDA did not converge”. Raising
options = list(mxit = ...) rarely changes the estimate by more
than its last few iterations already did; check by comparing coefficients
at two values of mxit rather than assuming the warning means the
fit is unusable.
tda_zreg1 is TDA's zreg1, the residual-life variant:
instead of one fit, it refits the Buckley-James regression of the
remaining lifetime (\(Y - t\)) at every time step
\(t = 0, 1, 2, \ldots\) while more than 10 cases remain at risk,
and the result is the whole trajectory of coefficients over time.
Time-varying covariates enter as event dates
(dates, TDA's xv=): at each step, a date column
becomes the indicator "has this event happened by \(t\)"
(date <= t), so its coefficient traces how experiencing the
event shifts expected remaining lifetime. It takes the same plain
one-row-per-case frame as tda_zreg, plus the date columns –
the dichotomisation over time is the time variation.
See also
Other regression:
TDA_FAMILIES,
TDA_QRMODELS,
tda_freg(),
tda_gdf(),
tda_l1reg(),
tda_lsreg(),
tda_mlrc_design(),
tda_mreg(),
tda_nlreg(),
tda_npreg()
Examples
set.seed(1)
d <- data.frame(x = round(rnorm(50), 2))
d$y <- round(2 - 0.8 * d$x + rnorm(50, sd = 0.4), 3)
d$cen <- as.integer(d$y > 2.2)
d$yc <- pmin(d$y, 2.2)
# zreg iterates to reweight the censored cases; a "did not converge"
# warning here is typical of the method, not a sign the fit is wrong.
# True coefficients are 2 and -0.8, so this should land close to them.
zr <- tda_zreg(yc ~ x, d, censor = "cen")
#> Warning: TDA did not converge after 21 iterations
coef(zr)
#> Intercept x
#> 2.029259 -0.800771
head(fitted(zr))
#> [1] 2.5337452 1.8851207 2.7019071 0.7480259 1.7650050 2.6858916
predict(zr, newdata = data.frame(x = c(0, 1)))
#> [1] 2.029259 1.228488