Run forward, backward, or two-way stepwise selection on an existing
hazard fit using Wald p-values or AIC deltas as the entry /
retention criterion. Phase-specific entry is supported for
multiphase models: a covariate can enter one phase and not another.
Arguments
- fit
A fitted
hazardobject built via theformula = Surv(...) ~ predictors, data = dfinterface.- scope
Candidate set.
NULL(default) uses every data-frame column not already in the model for every phase. For single-distribution fits, pass a one-sided formula (~ age + nyha) or a character vector of names. For multiphase fits, pass a named list of one-sided formulas keyed by phase.- data
Data frame the base fit was built on. Required for refits.
- direction
One of
"both"(default),"forward","backward".- criterion
One of
"wald"(default) or"aic". SAS-style p-value thresholds apply to Wald; AIC usesDeltaAIC < 0uniformly.- slentry
Entry p-value threshold for the Wald criterion. Default
0.30matches SASSLENTRY.- slstay
Retention p-value threshold for the Wald criterion. Default
0.20matches SASSLSTAY.- max_steps
Hard cap on total accepted actions. Emits a
warning()if hit. Default50.- max_move
Per-variable oscillation cap. When a variable has entered + exited more than
max_movetimes it is frozen for the remainder of the run. Default4.- force_in
Character vector of variables that must remain in the model. Such variables are still scored and reported in the selection trace, but are never dropped.
- force_out
Character vector of variables that may never be considered as candidates.
- trace
Logical; print step-by-step progress to the console. Default
TRUE.- ...
Passed to the underlying
hazard()refits (e.g.control = list(n_starts = 3)).
Value
An object of class c("hzr_stepwise", "hazard") – the
final fit augmented with:
stepsData frame with one row per accepted / frozen action; see Details.
scopeRecord of the candidate scope, plus
force_in,force_out, and the frozen set.criteriaNamed list of the threshold / direction settings actually applied.
trace_msgCharacter vector of the trace lines, captured regardless of the
traceflag.elapseddifftimefrom start to finish.final_callThe call that produced this result.
Details
The steps data frame has columns:
step_numInteger sequence starting at 1.
action"enter","drop", or"frozen".variableVariable affected.
phasePhase name (multiphase) or
NA_character_.criterion"wald"or"aic".scoreWinning score used for the decision.
stat,dfWald statistic and degrees of freedom.
p_value,delta_aicAlways populated when computable, regardless of the active criterion.
logLik,aic,n_coefGoodness-of-fit diagnostics of the model after this step.