| Type: | Package |
| Title: | Remedy the Violation of the Proportional Hazards Assumption of Cox Regression |
| Version: | 0.1.1 |
| Description: | Remedying proportional hazards assumption violations of a Cox proportional hazards model using stepwise changepoint and time-varying coefficient methods based on Cox (1972) <doi:10.1111/j.2517-6161.1972.tb00899.x> and Grambsch and Therneau (1994) <doi:10.1093/biomet/81.3.515>. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Imports: | survival |
| Suggests: | KMsurv |
| NeedsCompilation: | no |
| Packaged: | 2026-06-05 00:23:45 UTC; user |
| Author: | Hamin Kim [aut, cre] |
| Maintainer: | Hamin Kim <siru9170@naver.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-06-09 16:00:08 UTC |
cox.rvph (Remedy for Violations of the Proportional Hazards Assumption of Cox regression)
Description
Stepwise or time-varying remedies for proportional hazards assumption violations of a cox regression model
Usage
cox.rvph(
data,
time,
event,
covariate,
adjust_vars = NULL,
method = c("step", "timev"),
g_candidates = NULL,
max_K = 4,
p_threshold = 0.05,
verbose = TRUE
)
Arguments
data |
dataset |
time |
time variable |
event |
event indicator |
covariate |
covariate that violates the proportional hazards assumption |
adjust_vars |
optional adjustment variables |
method |
"step" or "timev" |
g_candidates |
A list of candidate time functions used in the time-varying coefficient method. If NULL, a default set of candidate functions (linear, log, sqrt, quadratic, inverse, and scaled) is used. Users may also supply custom transformation functions. |
max_K |
maximum number of segments |
p_threshold |
threshold for PH test |
verbose |
logical; whether to print progress messages |
Details
Users should first assess the proportional hazards (PH) assumption
using cox.zph() before applying cox.rvph().
Variables showing evidence of non-proportional hazards may then be modeled using stepwise or time-varying remedies.
The step method performs segmented modeling by searching
for optimal cut points in time by maximizing the partial likelihood. If the resulting model satisfies
the PH assumption with relatively few cut points, hazard ratios (HRs)
may be interpreted separately within each time interval.
However, if many cut points are required or PH violations persist,
a smooth time-varying effect may be more appropriate. In such cases,
the timev method fits several candidate time-transformation
functions g(t) and selects the model with the smallest AIC.
By default, the following candidate functions are evaluated:
linear (t),
log (\log(t+1)),
sqrt (\sqrt{t}),
quadratic (t^2),
inverse (1/(t+1)),
and scaled (t/\max(t)).
Users may alternatively provide their own candidate functions
through the g_candidates argument.
For the selected time-varying model, the hazard ratio at time
t is given by:
HR(t) = \exp(\beta + \gamma g(t))
where \beta is the baseline coefficient and
\gamma represents the time-varying interaction effect.
Users may evaluate this expression at clinically relevant time points
to interpret how the hazard ratio changes over time.
Interpretation:
For the step method, hazard ratios are interpreted
separately within each estimated time interval.
Example output (method: step):
$K
[1] 2
$tau
[1] 5
$fit
coef exp(coef) p
covariate_seg1 0.946 2.576 <0.001
covariate_seg2 -0.351 0.704 0.127
Interpretation (method: step):
For the step method, hazard ratios are interpreted
separately within each estimated time interval.
Interpretation:
covariate_seg1 HR = 2.58
covariate_seg2 HR = 0.70
If the estimated cut point is \tau = 5, this indicates
that before time 5 the hazard is approximately 2.58 times higher,
whereas after time 5 the hazard ratio decreases to approximately 0.70.
Example output (method: timev):
$selected_g
[1] "sqrt"
$fit
coef exp(coef) p
protime 2.961 19.319 <0.001
interaction -0.086 0.918 <0.001
bili 0.022 1.022 0.211
.
.
Interpretation (method: timev):
For the timev method, hazard ratios vary continuously over time.
Example model:
HR(t) = \exp(2.96 - 0.086 \sqrt{t})
This indicates that the hazard ratio decreases gradually over time.
Users may substitute clinically meaningful values of t
to estimate hazard ratios at specific time points.
Value
list containing model results
Examples
if (requireNamespace("KMsurv", quietly = TRUE)) {
data(larynx, package = "KMsurv")
cox.rvph(
data = larynx,
time = "time",
event = "delta",
covariate = "stage",
adjust_vars = "age",
method = "step"
)
}