Statistical model reference
Cox Proportional Hazards Model
Review when to use this method, its data requirements, implementation patterns, and interpretation guidance.
Description
A semi-parametric regression model for analyzing survival data that estimates the effect of covariates on the hazard rate while making minimal assumptions about the baseline hazard function. It provides hazard ratios for covariates while accounting for censored data.
Use Cases
- survival analysis
- time-to-event analysis
- risk factor assessment
- clinical trial outcomes
Requirements
- Sample Size: medium, large
- Missing Data: none, random
- Data Distribution: any
- Relationship Type: proportional hazards
Variable Types
Dependent Variables
- time-to-event
Independent Variables
- continuous
- categorical
- binary
Implementation
from lifelines import CoxPHFitter
# Initialize and fit model
cph = CoxPHFitter()
cph.fit(df, duration_col='time', event_col='event', covariates=['age', 'treatment'])
# Display results
cph.print_summary()
# Plot coefficients
cph.plot()
Documentation
library(survival)
# Fit Cox model
cox_model <- coxph(Surv(time, event) ~ age + treatment, data=df)
# Summary
summary(cox_model)
# Check proportional hazards assumption
cox.zph(cox_model)
Documentation
COXREG time WITH age treatment
/STATUS=event(1)
/PRINT=CI(95) BASELINE
/PLOT SURVIVAL
/CRITERIA=PIN(.05) POUT(.10) ITERATE(20).
Documentation
PROC PHREG DATA=dataset;
MODEL time*event(0)=age treatment / TIES=EFRON;
BASELINE OUT=surv survival=_ALL_ / NOMEAN;
RUN;
Documentation
stset time, failure(event)
stcox age treatment, nohr
estat phtest
Documentation
Synthetic Data Example
A right-censored survival dataset with time-to-event data and covariates
R Code for Data Generation and Analysis
# Generate synthetic survival data
set.seed(123)
library(survival)
n <- 200
age <- rnorm(n, 50, 10)
treatment <- sample(0:1, n, replace=TRUE)
# Generate survival times with treatment effect
true_times <- rexp(n, rate=0.1*exp(0.05*age - 0.8*treatment))
# Generate censoring times
cens_times <- runif(n, 5, 15)
# Create observed times and event indicator
time <- pmin(true_times, cens_times)
event <- as.numeric(true_times <= cens_times)
df <- data.frame(time, event, age, treatment)
# Fit Cox model
cox_model <- coxph(Surv(time, event) ~ age + treatment, data=df)
# Model summary
summary(cox_model)
# Check proportional hazards
cox.zph(cox_model)
# Plot survival curves
plot(survfit(cox_model, newdata=data.frame(age=50, treatment=0:1)),
col=1:2, lwd=2, xlab="Time", ylab="Survival Probability")
legend("topright", legend=c("Control", "Treatment"), col=1:2, lwd=2)
Copy this code into your R environment to generate synthetic data and perform analysis with this model.
Expected Analysis Results
Console Output
> summary(cox_model)
Call:
coxph(formula = Surv(time, event) ~ age + treatment, data = df)
n= 200, number of events= 134
coef exp(coef) se(coef) z Pr(>|z|)
age 0.04891 1.05013 0.01042 4.693 2.68e-06 ***
treatment -0.78542 0.45615 0.17862 -4.398 1.10e-05 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
exp(coef) exp(-coef) lower .95 upper .95
age 1.0501 0.9523 1.0286 1.0721
treatment 0.4562 2.1923 0.3213 0.6476
Concordance= 0.682 (se = 0.023 )
Likelihood ratio test= 32.76 on 2 df, p=7e-08
Wald test = 31.45 on 2 df, p=1e-07
Score (logrank) test = 33.12 on 2 df, p=6e-08
These results are from running the R code on synthetic data. Your actual results may vary depending on your data.
Interpretation Guide
Need help interpreting the results of your Cox Proportional Hazards Model analysis? Our comprehensive interpretation guide explains:
- How to read and understand model outputs
- Interpreting coefficients and effect sizes correctly
- Understanding diagnostic plots and visualizations
- Common pitfalls and how to avoid them
- Making valid conclusions from your analysis