crabbymetrics
  • Home
  • API
    • API Overview
    • Regression And GLMs
    • Survival / Event-Time
    • Causal Inference And Panels
    • Hypothesis Testing And Utilities
    • Transforms
    • Estimation Interfaces
  • Binding Crash Course
  • Regression And GLMs
    • OLS
    • ABC OLS
    • Anytime-Valid Confidence Sequences
    • Ridge
    • Bagged Polynomial Regression
    • Fixed Effects OLS
    • ElasticNet
    • Logit
    • Multinomial Logit
    • Poisson
    • MLE Prediction Interface
    • Survival / Recurrent Events
    • GMM
    • FTRL
    • MEstimator Poisson
  • Causal Inference
    • Balancing Weights
    • EPLM
    • Average Derivative
    • Double ML And AIPW
    • Richer Regression
    • TwoSLS
    • Synthetic Control
    • Synthetic DID
    • Horizontal Panel Ridge
    • Matrix Completion
    • Interactive Fixed Effects
    • Staggered Panel Event Study
    • Joint Hypothesis Tests
  • Transforms
    • PCA And Kernel Basis
  • Ablations
    • Variance Estimators
    • Semiparametric Estimator Comparisons
    • Two-Period Semiparametric DID
    • Bridging Finite And Superpopulation
    • Panel Estimator DGP Comparisons
    • Same Root Panel Case Studies
    • Randomized Sketching And Least Squares
  • Optimization
    • Optimizers
    • GMM With Optimizers
  • Ding: First Course
    • Overview And TOC
    • Ch 1 Correlation And Simpson
    • Ch 2 Potential Outcomes
    • Ch 3 CRE And Fisher RT
    • Ch 4 CRE And Neyman
    • Ch 9 Bridging Finite And Superpopulation
    • Ch 11 Propensity Score
    • Ch 12 Double Robust ATE
    • Ch 13 Double Robust ATT
    • Ch 21 Experimental IV
    • Ch 23 Econometric IV
    • Ch 27 Mediation

On this page

  • 1 Where it fits
  • 2 Python API
  • 3 Minimal example
  • 4 summary() contract

CoxPH

Semiparametric proportional hazards via the Cox partial likelihood

from _api_doc_utils import *

1 Where it fits

Group: Survival / event-time models

CoxPH estimates log hazard ratios without parameterizing the baseline hazard:

\[ h_i(t \mid x_i) = h_0(t) \exp(x_i'eta). \]

That means the paved prediction target is relative risk rather than absolute survival. The latent linear index is still useful and is exposed as predict_lin(x).

2 Python API

Constructor: cm.CoxPH

Use fit(x, time, event). predict_lin(x) returns the log hazard ratio and predict_relative_risk(x) exponentiates it. The default predict(x) is the same relative-risk object. summary() reports coefficients, standard errors, hazard ratios, and optimization diagnostics.

print(inspect.signature(cm.CoxPH))
cls = cm.CoxPH
display(HTML(html_table(["Public method"], public_methods(cls))))

3 Minimal example

rng=np.random.default_rng(33)
x=rng.normal(size=(260,2)); rate=0.05*np.exp(x@np.array([0.5,-0.25])); t_event=rng.exponential(1.0/rate); c=rng.exponential(25,size=260)
time=np.minimum(t_event,c); event=(t_event<=c).astype(float)
model=cm.CoxPH(); model.fit(x,time,event)
print(model.predict_lin(x[:5]))
print(model.predict(x[:5]))

4 summary() contract

The table below is generated by fitting the live class in this repository and then inspecting summary(). Shapes are shown because most values are plain NumPy arrays or scalars.

rng=np.random.default_rng(133); x=rng.normal(size=(130,2)); rate=0.06*np.exp(x@np.array([0.45,-0.2])); te=rng.exponential(1.0/rate); c=rng.exponential(20,size=130); time=np.minimum(te,c); event=(te<=c).astype(float)
model=cm.CoxPH(); model.fit(x,time,event)
summary = model.summary()
display(HTML(html_table(["summary() key", "shape"], summary_shape_rows(summary))))