Skip to contents

Implements weighted Cox proportional hazards regression models specifically designed for rare events and imbalanced survival data. Uses average hazard weights to improve estimation accuracy when events are rare or covariates are imbalanced, providing more reliable hazard ratios and confidence intervals in challenging clinical research scenarios.

Usage

coxphw(
  data,
  elapsedtime,
  outcome,
  covariates,
  outcomeLevel = "1",
  weight_method = "average",
  alpha = 0.5,
  offset_variable,
  stratify_variable,
  cluster_variable,
  confidence_level = 0.95,
  max_iterations = 100,
  convergence_tolerance = 1e-06,
  bootstrap_ci = FALSE,
  bootstrap_samples = 500,
  show_model_summary = TRUE,
  show_coefficients = TRUE,
  show_weights = TRUE,
  show_diagnostics = TRUE,
  show_comparison = TRUE,
  show_weight_plots = TRUE,
  show_residual_plots = TRUE,
  show_survival_plots = TRUE,
  show_forest_plot = TRUE,
  showSummaries = FALSE,
  showExplanations = FALSE
)

Arguments

data

the data as a data frame

elapsedtime

Survival time or follow-up duration variable

outcome

Event indicator variable (0/1, FALSE/TRUE, or factor)

covariates

Predictor variables for the Cox model

outcomeLevel

Level of outcome variable indicating event occurrence

weight_method

Weighting method for the partial likelihood

alpha

Weight parameter (0=log-rank, 0.5=average, 1=Breslow)

offset_variable

Optional offset variable for the model

stratify_variable

Variable for stratified analysis

cluster_variable

Variable defining clusters for robust variance

confidence_level

Confidence level for intervals

max_iterations

Maximum number of iterations

convergence_tolerance

Convergence tolerance for estimation

bootstrap_ci

Compute bootstrap confidence intervals

bootstrap_samples

Number of bootstrap samples

show_model_summary

Display comprehensive model summary

show_coefficients

Display coefficient estimates table

show_weights

Display weight distribution analysis

show_diagnostics

Display model diagnostics

show_comparison

Compare weighted vs standard Cox models

show_weight_plots

Display weight distribution plots

show_residual_plots

Display residual diagnostic plots

show_survival_plots

Display survival curves

show_forest_plot

Display forest plot of hazard ratios

showSummaries

Generate natural language summaries

showExplanations

Show detailed methodology explanations

Value

A results object containing:

results$modelSummarya table
results$coefficientsa table
results$weightAnalysisa table
results$diagnosticsa table
results$modelComparisona table
results$convergenceInfoa table
results$rareEventAnalysisa table
results$weightPlotsan image
results$residualPlotsan image
results$survivalPlotsan image
results$forestPlotan image
results$comparisonPlotsan image
results$summaryTablea html
results$methodExplanationa html

Tables can be converted to data frames with asDF or as.data.frame. For example:

results$modelSummary$asDF

as.data.frame(results$modelSummary)

Examples

# Example: Weighted Cox regression for rare events
library(survival)
library(coxphw)

coxphw(
    data = rare_event_data,
    elapsedtime = "time",
    outcome = "status",
    outcomeLevel = "1",
    covariates = c("age", "treatment", "biomarker"),
    weight_method = "average",
    alpha = 0.5
)