| cox_rhogamma | R Documentation |
Fits a weighted Cox proportional hazards model using flexible time-dependent weights (e.g., Fleming-Harrington, Magirr-Burman). Supports resampling-based inference for variance estimation and bias correction.
cox_rhogamma(
dfcount,
scheme = "fh",
scheme_params = list(rho = 0, gamma = 0.5),
draws = 0,
alpha = 0.05,
verbose = FALSE,
lr.digits = 4
)
dfcount |
List; output from |
scheme |
Character; weighting scheme. See |
scheme_params |
List; parameters for the selected scheme. Default:
|
draws |
Integer; number of resampling draws for variance estimation and bias correction. If 0, only asymptotic inference is performed. Default: 0. |
alpha |
Numeric; significance level for confidence intervals. Default: 0.05. |
verbose |
Logical; whether to print detailed output. Default: FALSE. |
lr.digits |
Integer; number of decimal places for formatted output. Default: 4. |
This function solves the weighted Cox partial likelihood score equation: U(beta) = sum_i w_i K_i (dN_0/Y_0 - dN_1/Y_1) = 0
where K_i are time-dependent weights and Y_j, dN_j are risk sets and event counts for group j.
When draws > 0, the function performs resampling to:
Estimate finite-sample variance (more accurate than asymptotic)
Compute bias correction for \hat{\beta}
Provide improved confidence intervals for small samples
The score test at \beta=0 corresponds to the weighted log-rank test.
A list containing:
List with fitted model components:
bhat: Estimated log hazard ratio
sig_bhat_asy: Asymptotic standard error
u.zero: Score statistic at beta=0 (log-rank)
z.score: Standardized score statistic
sig2_score: Variance of score statistic
wt_rg: Vector of time-dependent weights
bhat_debiased: Bias-corrected estimate (if draws > 0)
sig_bhat_star: Resampling-based standard error (if draws > 0)
Data frame with asymptotic HR and CI
Data frame with resampling-based HR and CI (if draws > 0)
Formatted string with HR and asymptotic CI
Formatted string with HR and resampling CI (if draws > 0)
Bias-corrected score statistic (if draws > 0)
Formatted log-rank test result
The treatment variable in dfcount must be coded as 0=control, 1=experimental.
Magirr, D. and Burman, C. F. (2019). Modestly weighted logrank tests. Statistics in Medicine, 38(20), 3782-3790.
df_counting for preprocessing
wt.rg.S for weighting schemes
cox_score_rhogamma for score function
Other survival_analysis:
KM_diff(),
df_counting(),
wt.rg.S()
Other weighted_tests:
df_counting(),
wt.rg.S()
# First get counting process data
library(survival)
str(veteran)
veteran$treat <- as.numeric(veteran$trt) - 1
dfcount <- df_counting(
df = veteran,
tte.name = "time",
event.name = "status",
treat.name = "treat"
)
# Fit weighted Cox model with FH(0,0.5) weights
fit <- cox_rhogamma(
dfcount = dfcount,
scheme = "fh",
scheme_params = list(rho = 0, gamma = 0.5),
draws = 1000,
verbose = TRUE
)
print(fit$cox_text_star) # Resampling-based CI
print(fit$zlogrank_text) # Weighted log-rank test
# Compare asymptotic and resampling CIs
print(fit$hr_ci_asy)
print(fit$hr_ci_star)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.