Skip to content

Cox proportional-hazards regression of time to event

stats_cox_regression

Fits a Cox proportional-hazards regression of time to event, with hazard ratios and tests.

Runs
On the server
Level
Checked against a reference: statsmodels 0.15.0 PHReg, Fox and Weisberg's and Therneau's printed values, and a second implementation in Python
Ask your assistant

What it is

Returns Cox proportional-hazards coefficients, hazard ratios, SE, z, p and likelihood-ratio, Wald and score tests. Use when each subject has a time to event or censoring and hazard ratios are wanted for covariates or factors, optionally by strata. Not for survival curves, medians or a log-rank test (use `stats_survival_analysis`) or event counts over person-time (use `stats_poisson_regression`). Ties, replicates and covariate scales are required; infinite estimates are refused (MLE_NOT_FINITE); no baseline survival or proportional-hazards test is returned. A measurement's unit is required, never assumed: any unit of the kit's table, returned in its canonical spelling; a unit group takes one unit, never converted.

Field: Statistics and design.

What it does

You give

  • ties (required): How tied event times enter the partial likelihood: 'breslow' or 'efron'. Required, no default; with no tied event times both give the same fit.
  • response (required): Times and statuses, one entry per subject.
  • replicates (required): What one subject is: 'independent' (independent subjects, for example one animal each; opens z, p, the tests and the intervals), 'technical' (not independent, for example several tumours or wells from one animal, or litter-mates) or 'unspecified'. Required: never inferred.
  • level (required): Confidence level of the Wald intervals: 0.9, 0.95 or 0.99 (or 90, 95, 99 %). Must be above 0 and below 1.
  • covariates: At most 4 covariates. Optional.
  • factors: At most 3 factors, each with at most 12 levels. With the covariates, at most 20 coefficients: covariates + levels beyond each reference. Optional.

and 1 more, listed below

No request is recorded for this tool.

Limits

  • Research statistics and experimental-design arithmetic on the data, margins, prevalence and settings you supply.
  • Not for diagnosis or treatment decisions and not a regulatory analysis.
  • It does not choose a design, a margin, a cut-off or a sample size for you.
  • At most 500 subjects, 4 covariates, 3 factors of up to 12 levels each, 20 strata and 20 coefficients; `stats_survival_analysis` accepts larger data sets for curves and the log-rank test.
  • Proportional hazards are assumed and not tested; no baseline survival, time-varying covariates, robust or clustered standard errors, or frailty.
  • Infinite estimates are refused, never approximated; a fit that cannot be decided exactly or does not converge returns an error, never a number.
  • Wald z, p and intervals are large-sample approximations that can be unreliable with few events per coefficient.
  • Every computed number a reply returns, other than an integer or an exact decimal, is rounded once to 12 significant figures: to the nearest, a change of at most 5 × 10⁻¹² of its value, except that a lower bound is rounded down and an upper bound up, a change of less than 1 × 10⁻¹¹; the method computes, and decides any pass or fail, on the unrounded value.

It will not answer when

  • no subject had the event.
  • fewer events than one more than the coefficients (events < p + 1), counted across strata (Drybench ruling, 10 November 2026, K5, a labelled judgement: a floor against meaningless Wald inference, not an existence rule).
  • the chain of risk-set difference rows is rank-deficient: a predictor is a combination of others or of the strata, or varies only among subjects censored before the first event (Drybench ruling, 10 November 2026, J1, J3).
  • the reciprocal 1-norm condition of the information, equilibrated by powers of two on its diagonal, is below 1e-5 at β = 0 or at the fit, or the information loses positive definiteness during the fit (Drybench ruling, 10 November 2026, J3, a labelled judgement).
Every input, with its units7 inputs
  • ties (required): How tied event times enter the partial likelihood: 'breslow' or 'efron'. Required, no default; with no tied event times both give the same fit.
  • response (required): Times and statuses, one entry per subject.
  • replicates (required): What one subject is: 'independent' (independent subjects, for example one animal each; opens z, p, the tests and the intervals), 'technical' (not independent, for example several tumours or wells from one animal, or litter-mates) or 'unspecified'. Required: never inferred.
  • level (required): Confidence level of the Wald intervals: 0.9, 0.95 or 0.99 (or 90, 95, 99 %). Must be above 0 and below 1.
  • covariates: At most 4 covariates. Optional.
  • factors: At most 3 factors, each with at most 12 levels. With the covariates, at most 20 coefficients: covariates + levels beyond each reference. Optional.
  • strata: Optional. Each stratum has its own baseline hazard; the coefficients are shared and strata get no coefficient. At most 20 strata. Optional.
Every refusal, with its code12 refusals
CodeWhen
NO_EVENTS_TOTALno subject had the event.
TOO_FEW_EVENTSfewer events than one more than the coefficients (events < p + 1), counted across strata (Drybench ruling, 10 November 2026, K5, a labelled judgement: a floor against meaningless Wald inference, not an existence rule).
RANK_DEFICIENTthe chain of risk-set difference rows is rank-deficient: a predictor is a combination of others or of the strata, or varies only among subjects censored before the first event (Drybench ruling, 10 November 2026, J1, J3).
DESIGN_ILL_CONDITIONEDthe reciprocal 1-norm condition of the information, equilibrated by powers of two on its diagonal, is below 1e-5 at β = 0 or at the fit, or the information loses positive definiteness during the fit (Drybench ruling, 10 November 2026, J3, a labelled judgement).
MLE_NOT_FINITEthe partial likelihood is monotone (some direction orders every event at its risk set's maximum), decided exactly before fitting.
LENGTHS_DIFFERtwo columns of one call differ in length.
REFERENCE_NOT_A_LEVELa factor's reference is not one of its levels.
FACTOR_ONE_LEVELa factor with one level.
TOO_MANY_LEVELSa factor with more than 12 levels, or strata with more than 20 (one condition, one spelling: Drybench's Cox build ruling B1).
TOO_MANY_COEFFICIENTSmore than 20 coefficients (covariates + levels beyond each reference).
NONPOSITIVE_ON_LOGa log10 covariate with a value at or below 0.
NO_PREDICTORSno covariate and no factor.

The calculation

The method's equations, constants and worked example.

Cox proportional-hazards regression by maximum partial likelihood, Breslow or Efron tiesstats-cox-regression@1.0.3

Equation 1

at each event time t in a stratum, with risk set R (every subject in that stratum with time ≥ t

a subject censored at t is at risk) and d tied events D: Breslow ℓ += Σ_D x′β − d·log Σ_R exp(x′β)

Efron ℓ += Σ_D x′β − Σ_{k=0}^{d−1} log(Σ_R exp(x′β) − (k/d)·Σ_D exp(x′β))

with wⱼ = exp(xⱼ′β) and, for the k-th tied draw, S0ₖ = Σ_R w − cₖΣ_D w, S1ₖ = Σ_R w·x − cₖΣ_D w·x, S2ₖ = Σ_R w·xx′ − cₖΣ_D w·xx′ (Efron cₖ = k/d

Breslow cₖ = 0): U += Σ_D x − Σₖ S1ₖ/S0ₖ and I = −∂²ℓ/∂β∂β′ += Σₖ (S2ₖ/S0ₖ − (S1ₖ/S0ₖ)(S1ₖ/S0ₖ)′), k = 0 … d − 1

no intercept (it is absorbed into the baseline hazard). Status 1 is the event and 0 censoring. The design X is that of the binomial and Poisson records without the intercept: covariates in the order given (value, or log10 on 'log10'), then each factor's non-reference levels sorted by name as 0/1 indicators

strata enter only through the risk sets. The matrix forms S1 and S2 for several covariates are the record's extension of the vignette's one-covariate source

SymbolMeaning
x′βlinear predictor
dtied events at t (a count)
xa subject's row of the design
βcoefficients
tan event time (in the caller's time unit), as-given
R, Dthe risk set and the tied events at t
S0ₖ, S1ₖ, S2ₖweighted sums over the risk set, as defined in the text
U, Iscore vector and observed information

Source 1.

Equation 2

Newton–Raphson from β = 0

stop when the Newton decrement UᵀI⁻¹U ≤ 1e-20, taking that last step too (the information re-evaluated there)

at most 100 iterations

a step is halved, at most 10 times, while ℓ falls by more than 64·ε·|ℓ| (Drybench ruling, 10 November 2026, J4.3)

covariates centred by their means and exp(x′β) held relative to a running maximum over the risk set (J4.1)

SymbolMeaning
decrementUᵀI⁻¹U

Source 1.

Equation 3

Our derivation, published source not yet read (Drybench ruling, 10 November 2026, K2): no finite maximum exists exactly when some δ ≠ 0 has (x_i − x_j)′δ ≥ 0 for every event i and every j in its risk set (the same cone for Breslow and Efron)

decided exactly on an O(n) chain of difference rows (each event time's representative against the other tied events, the next time's representative and the censored subjects between) with the separation LP

rank first on the same rows

SymbolMeaning
δa direction in coefficient space

Source 1.

Equation 4

Standard forms, not in the vignette: Wald β̂ᵀI(β̂)β̂, score U(0)ᵀI(0)⁻¹U(0), likelihood ratio 2(ℓ(β̂) − ℓ(0)), each on p df against the χ² upper tail

stratified when strata are given

SE = √diag I(β̂)⁻¹ (the observed information)

per coefficient z = β̂/SE, p = 2(1 − Φ(|z|)), interval β̂ ± z₍₁₊ₗ₎/₂·SE, hazard ratio exp(β̂) with limits exp of the interval's

eventsPerCoefficient = events/p

SymbolMeaning
pcoefficients (a count)
z₍₁₊ₗ₎/₂the standard normal quantile Φ⁻¹((1 + l)/2), l the caller's level
Φthe standard normal distribution function
ℓthe log partial likelihood

Source 1.

Conventions

  • ties = breslow: Each of the d events tied at one time enters the partial likelihood over the whole risk set at that time, as if no tied subject left the risk set before the others.
  • ties = efron: The d events tied at one time are treated as occurring in an unknown order: for the k-th of them (k = 0, …, d − 1), the risk-set sum is reduced by k/d of the tied subjects' sum.

A definition, not a model: the equation states what the quantity means. A different convention gives a different number.

Worked example

Worked example: one case of stats-cox-regression@1.0.3, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.

Inputs

  • ties = breslow
  • response.time[0] = 1 d
  • response.time[1] = 1 d
  • response.time[2] = 6 d
  • response.time[3] = 6 d
  • response.time[4] = 8 d
  • response.time[5] = 9 d
  • response.status[0] = 1
  • response.status[1] = 0
  • response.status[2] = 1
  • response.status[3] = 1
  • response.status[4] = 0
  • response.status[5] = 1
  • response.eventLabel = death
  • replicates = independent
  • level = 0.95
  • covariates[0].name = x
  • covariates[0].values[0] = 1
  • covariates[0].values[1] = 1
  • covariates[0].values[2] = 1
  • covariates[0].values[3] = 0
  • covariates[0].values[4] = 0
  • covariates[0].values[5] = 0
  • covariates[0].scale = linear

Steps

  1. r = 4.3722813, from response.time, response.status, covariates; by equation 1.
  2. estimate = 1.4752849, from r; by equation 1; gives coefficients[0].estimate.
  3. information = 0.63416814, from r; by equation 4.
  4. se = 1.2557344, from information; by equation 4; gives coefficients[0].se.
  5. z = 1.1748383, from estimate, se; by equation 4; gives coefficients[0].z.
  6. hazard-ratio = 4.3722813, from r; by equation 1; gives coefficients[0].hazardRatio.estimate.

The working, as the case writes it:

statsmodels' largest relative error against the 50-digit solve on beta and SE: 1.51e-16

the case tolerance is relative max(1e-9, 10 × that)

effective relative bound under the absolute rules 0.0e+00 (at most 1e-7)

Answer

coefficients[0].estimate = 1.4752849

coefficients[0].se = 1.2557344

coefficients[0].z = 1.1748383

coefficients[0].hazardRatio.estimate = 4.3722813

Where these values came from: an outside program, statsmodels PHReg; SciPy; mpmath (tolerances) statsmodels 0.15.0; scipy 1.18.1; mpmath 1.4.1; Therneau, Software validation (survival package vignette, Dec 2022), section 3.1: beta and the log partial likelihoods at their printed precision; the score statistic U(0)^2/H(0) exact from the printed U(0) and H(0) (1 and 0.625: 1.6); the rest statsmodels 0.15.0.

At build the tool returned this answer within the tolerance the file states: estimates, SE, z, limits, hazard ratios, log partial likelihoods and test statistics relative max(1e-9, 10 × statsmodels' measured error against the 50-digit solve) per case (where units differ under one path, absolute: the larger of that size of the smallest magnitude and 100 × the measured error times the largest, an interval limit's magnitude being |estimate| + half-width; the log partial likelihoods absolute at that size of their magnitude); a coefficient's p that times (z_max² + 1), a test's p that times (x_max/2 + df + 1), a hazard ratio that times max(1, |ln ratio|), their sensitivities; no absolute rule looser than 1e-7 relative on any value it governs; Fox and Weisberg's and Therneau's printed values at half a unit of their print; counts, df, events per coefficient, names, codes and statuses exact.

Sources

  1. Therneau TM. Software validation. Vignette of the R survival package, Dec 2022 (updated)

    Used for: Cox proportional-hazards regression by maximum partial likelihood, Breslow or Efron ties. At: section §2, eqs. (1)–(5); §3.1 (Breslow, Test data 1, the censored subject at risk at t = 1); §3.2 (Efron as sequential draws, the tied subjects at weight 1/2 for the second); section §3.1: the Newton–Raphson increments −H⁻¹U from β = 0 (the first iterate 8/5 for Test data 1); the stopping rule, caps, centring and rescale are the library's own, stated; section §3.3 (pp. 9–10): an infinite MLE under the exact partial likelihood, which this method does not offer: Test data 1 is finite under Breslow and Efron (§3.1, §3.2) and infinite under the exact likelihood, so the condition is specific to the ties method; the condition here is the library's derivation for Breslow and Efron only; section §2 (U and the Hessian H); §3.1 and §3.2 (U(0), H(0), H(β̂) for Test data 1); the Wald, score and likelihood-ratio tests, the χ² p and the Wald intervals are standard forms, not in the vignette.

    Read in full, 10 November 2026

How it is checked

Level

Checked against a reference.

Checked against

An outside program, statsmodels PHReg; SciPy; mpmath (tolerances), statsmodels 0.15.0; scipy 1.18.1; mpmath 1.4.1; another program's fit of our model; a reference program this project wrote itself, second implementation (Python 3.13; NumPy, SciPy distribution functions and mpmath only), 2026-11-14, Newton-Raphson in double precision by the record's stopping rule, polished in mpmath 1.4.1 at 60 digits and rounded once; the cone and rank decisions in exact rationals; not an outside program.

Cases

No case set is linked to this version.

Not checked

The monotone-likelihood condition is derived for Breslow and Efron only; it does not hold for the exact or discrete partial likelihood. Therneau's printed Efron LL(β̂) for Test data 1 (−3.358979) is a misprint for −3.358975 and is not asserted.

What was not checked, in fullfrom the method records
  • The monotone-likelihood condition is derived for Breslow and Efron only; it does not hold for the exact or discrete partial likelihood.
  • Therneau's printed Efron LL(β̂) for Test data 1 (−3.358979) is a misprint for −3.358975 and is not asserted.
  • An undecided monotone-likelihood test (300 exact pivots) and non-convergence are internal invariants that return an error and no number; if any input reaches the first it becomes the declared refusal SEPARATION_UNDECIDED with Drybench's pre-agreed text (the Cox caps ruling, A2), with that input as its fixture; the Wald intervals' coverage at few events or near monotone likelihood; strata against a printed source (statsmodels, the 50-digit solve and a metamorphic case only); time-varying covariates, (start, stop] input, case weights, robust or clustered SE, frailty, exact or discrete ties, Firth's penalty, residuals, baseline survival and concordance; Cox 1972, Breslow 1974, Efron 1977 and Heinze and Schemper 2001 not read.
  • Fox and Weisberg's appendix (the printed Rossi fit) was read on 11 November 2026 and not re-read in the D-0219 full check.
Changes to its methods0 changes

No change is logged for these method versions.