Functions & Formulae

Each applied formula has its own function page, with a signature, implementations, and tests.

Cox proportional hazards model function for hazards, partial likelihood and baseline curves

c(time, status, x) = (beta_hat, SE_beta, H_0(t), S_0(t))

Maps right-censored survival records with covariates to the coefficients of the Cox model, their standard errors and the estimated baseline curve. HE-FM-CPH-001 gives the hazard and survival of one covariate profile from a baseline and a linear predictor, HE-FM-CPH-002 the partial likelihood over the risk sets, HE-FM-CPH-003 one step of the Breslow baseline cumulative hazard, HE-FM-CPH-004 the Breslow and Efron terms for two tied deaths, and HE-FM-CPH-005 a hazard ratio that changes with log time. HE-CF-CPH-001 maximises the partial likelihood by Newton-Raphson. HE-FM-HR-002 turns a coefficient into a hazard ratio, HE-FM-HR-006 gives its confidence interval, HE-FN-CUMH-001 links a cumulative hazard to survival and HE-FM-HR-003 is the power rule for a survival curve, and none of these is restated here as a formula of its own. Notation follows the Cox Proportional Hazards article.

  • Hazard and survival of one covariate profile from a Cox baseline and linear predictor

    lp = beta_1 * x_1 + beta_2 * x_2; RS = exp(lp); h_x = h_0 * RS; S_x = S_0^RS

    The linear predictor adds each coefficient times its covariate value, the risk score is its exponential, and the hazard of the profile is the baseline hazard times the risk score. Two covariates are written out, and further covariates add further terms to lp. With a single treatment covariate at 1, RS is the hazard ratio of HE-FM-HR-002 and h_x is HE-FM-HR-001 solved for the treatment hazard; this record adds covariates of any scale and any number. The last part takes the form of HE-FM-HR-003, which computes it for a treatment hazard ratio; Bradburn and colleagues print the same form for any covariate values, S(t) = S_0(t)^exp(gamma). The baseline is the profile with every covariate at zero, so absolute hazards and survival need it, and a coefficient alone gives only a relative effect.

  • Cox partial likelihood over three event times with a binary covariate

    r = exp(beta); p_1 = r^x_1 / (n0_1 + n1_1 * r); p_2 = r^x_2 / (n0_2 + n1_2 * r); p_3 = r^x_3 / (n0_3 + n1_3 * r); L = p_1 * p_2 * p_3; logL = log(L)

    At each event time the term is the risk score of the person who had the event divided by the summed risk scores of everyone still at risk just before that time. Multiplying the terms gives the partial likelihood, in which the baseline hazard has cancelled, so beta can be estimated without it. With x coded 1 for treatment and 0 for the comparator, a treated person scores r = exp(beta), the form of HE-FM-HR-002, and a comparator person scores 1, so each risk set reduces to two counts. Three event times are written out, and more event times add further terms. Only the order of events matters, not the gaps between them. The maximising value of beta comes from HE-CF-CPH-001, and HE-FM-HR-002 then gives the hazard ratio.

  • Breslow baseline cumulative hazard step and survival of both arms at one Cox event time

    r = exp(beta); dH = d / (n0 + n1 * r); H = H_prev + dH; S_0 = exp(-H); S_1 = S_0^r

    At each event time the baseline cumulative hazard rises by the number of events divided by the summed risk scores of those at risk, with the coefficient held at its estimate. This is the Nelson cumulative hazard estimator with case weights equal to the risk scores, in Therneau's words, and at beta = 0 the increment is the plain count over the number at risk. Starting from H_prev = 0 and repeating the line gives the whole curve. Three parts are live steps, r = exp(beta) from HE-FM-HR-002 for the 0 and 1 covariate, S_0 = exp(-H) from HE-FN-CUMH-001 and S_1 = S_0^r in the form of HE-FM-HR-003 with HR = r. Survival for the comparator is the baseline when x = 0 marks the comparator. Both curves change only at event times and stop informing anything after the last follow-up.

  • Breslow and Efron partial likelihood terms and hazard increments for two tied Cox deaths

    R_2 = R_s - 0.5 * (s_1 + s_2); P_B = s_1 * s_2 / R_s^2; P_E = s_1 * s_2 / (R_s * R_2); dH_B = 2 / R_s; dH_E = 1 / R_s + 1 / R_2

    When two people die at the same recorded time, the Breslow rule keeps both in the risk set for both draws, so one person could in effect die twice, as Therneau puts it. The Efron rule treats the draws as sequential, and the second draw keeps each of the two with weight one half because the first to die is unknown, which subtracts half of their summed scores. P_B and P_E replace the two single-death terms of HE-FM-CPH-002 at that time. dH_B and dH_E replace d / (n0 + n1 r) in HE-FM-CPH-003. For positive scores P_E exceeds P_B and dH_E exceeds dH_B (derived, and checked on a grid), and the gap closes as the risk set grows relative to the two deaths.

  • Cox hazard ratio that changes with log time through a covariate interaction

    beta_t = b_0 + b_1 * log(t); HR_t = exp(beta_t)

    Adding an interaction between a covariate and log time lets the log hazard ratio change along a straight line in log time, so the covariate's effect is no longer constant. b_0 is the coefficient of the covariate and b_1 the coefficient of its interaction with log time. At t = 1 in the units of the fit the log time term vanishes, so exp(b_0) is the hazard ratio at that one time and not an average. HE-FM-HR-002 is the special case b_1 = 0. The form is a way of handling non-proportional hazards within a Cox model, and a covariate whose value changes during follow-up is a separate idea.

This set of formulae is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).

Author: Dr Darrin Baines · Publisher: Intelligent Parameters Ltd · Identifier: https://healtheconomics.wiki/concept/cox-proportional-hazards/formulae