Signature
S = S_prev * (1 - (d_1 + d_2) / n); F_1 = F_1_prev + S_prev * d_1 / n; F_2 = F_2_prev + S_prev * d_2 / n
| Inputs | Definition | Unit |
|---|---|---|
S_prev | Probability of being free of both events just before time s; 1 before the first event | probability |
d_1 | Number of patients whose first event at time s is cause 1 | patients |
d_2 | Number of patients whose first event at time s is cause 2 | patients |
n | Number of patients free of both events and uncensored just before time s | patients |
F_1_prev | Value of F_1 just before time s; 0 before the first event | probability |
F_2_prev | Value of F_2 just before time s; 0 before the first event | probability |
S | Probability of being free of both events just after time s, with both causes counted as events | probability |
|---|---|---|
F_1 | Probability of having had cause 1 by time s, before any cause 2 event | probability |
F_2 | Probability of having had cause 2 by time s, before any cause 1 event | probability |
Function
Cause-specific cumulative incidence and subdistribution hazard from competing event records
Takes records of the time to each patient's first event, with the event type or a censoring flag, and returns event-free survival S(t), the cumulative incidence F_1(t) and F_2(t) of each cause, the cumulative cause-specific hazards H_1(t) and H_2(t) and the subdistribution hazard lambda_1(t). The constant-hazard closed form of the cumulative incidence is live as HE-FM-TP-004 with Delta read as t, and its k-exit form adds only more terms, so neither is restated. The survival part of each step takes the form of the Kaplan-Meier step HE-FM-ADMC-002 with all causes counted as events, and the error of one minus Kaplan-Meier for one cause is HE-ER-AR-002. For two groups, HE-FM-COMR-004 carries the factor in HE-FM-COMR-003 to the subdistribution relative hazard sdRH(t). Notation follows the Competing Risks article.
Computational function
Computational function: cumulative incidence and cause-specific cumulative hazard table from patient records
Builds the whole cumulative incidence and cumulative hazard table from patient records, applying HE-FM-COMR-001 and HE-FM-COMR-002 at every event time. The inputs differ from the formulas, since it takes whole vectors of times and causes in place of counts at one time and finds the event times, risk sets and tied events itself.
Inputs and outputs:
time: Time of each patient's first event or censoring. Unit: time.;cause: 1 for the cause of interest, 2 for the competing cause, 0 for censoring. Unit: code.;s,n,d1,d2: Distinct event times in increasing order, the number at risk just before each, and the events of each cause. Unit: time, patients, patients, patients.;surv,F1,F2: Event-free survival and the cumulative incidence of each cause after each event time. Unit: probability.;H1,H2: Cumulative cause-specific hazards after each event time. Unit: cumulative hazard.;ok: On the calculator line, 1 when S, F_1 and F_2 sum to 1 within 0.001. Unit: flag.Assumption: Censoring is independent and a patient censored at an event time stays in the risk set for that time, as in HE-AS-ADMC-004 and as
time >= xdoes here. Records with no event return an empty result, NULL in R and empty lists in Python, and a single record with an event returns one row with n of 1.Worked example (One row, runs on the calculator line): Time 13 of the twelve-patient table of Andersen and colleagues, with one cause 1 event among 6 at risk.
S_prev = 0.733333; F_1_prev = 0.175; F_2_prev = 0.091667; H_1_prev = 0.183333; H_2_prev = 0.111111; d_1 = 1; d_2 = 0; n = 6; S = 0.611111; F_1 = 0.297222; F_2 = 0.091667; H_1 = 0.35; H_2 = 0.111111; ok = 1Worked example (Whole table, for reading against the R and Python code): The twelve patients of Table 1 return risk sets 12, 10, 9, 6, 5, 4 and 1 at the seven event times, and the last row matches the printed S of 0, F_1 of 0.419, F_2 of 0.581, H_1 of 0.600 and H_2 of 1.311. The scalar example above and HE-EX-COMR-001 run on the calculator.
time = [5, 6, 7, 8, 9, 12, 13, 15, 16, 20, 22, 23]; cause = [1, 0, 1, 2, 0, 0, 1, 2, 1, 0, 0, 2]; n = [12, 10, 9, 6, 5, 4, 1]; surv_last = 0; F1_last = 0.419444; F2_last = 0.580556; H1_last = 0.6; H2_last = 1.311111Excel: With records in TimesRange and CauseRange and the distinct event times in column A from row 2,
=COUNTIF(TimesRange,">="&A2)gives n in column B,=COUNTIFS(TimesRange,A2,CauseRange,1)gives d_1 in column C and=COUNTIFS(TimesRange,A2,CauseRange,2)gives d_2 in column D. Column E, named SurvCol, starts=1-(C2+D2)/B2and continues=E2*(1-(C3+D3)/B3). Column F, named CumIncEventCol, starts=C2/B2and continues=F2+E2*C3/B3. Column G, named CumIncCompetingCol, starts=D2/B2and continues=G2+E2*D3/B3. Column H, named CumHazEventCol, starts=C2/B2and continues=H2+C3/B3. Column I, named CumHazCompetingCol, starts=D2/B2and continues=I2+D3/B3.R:
cr_table <- function(time, cause) { if (!any(cause > 0)) return(NULL); s <- sort(unique(time[cause > 0])); n <- sapply(s, function(x) sum(time >= x)); d1 <- sapply(s, function(x) sum(time == x & cause == 1)); d2 <- sapply(s, function(x) sum(time == x & cause == 2)); surv <- cumprod(1-(d1+d2)/n); before <- c(1, head(surv, -1)); data.frame(s = s, n = n, d1 = d1, d2 = d2, surv = surv, F1 = cumsum(before*d1/n), F2 = cumsum(before*d2/n), H1 = cumsum(d1/n), H2 = cumsum(d2/n)) }Base R only;cr_table(c(5, 6, 7, 8, 9, 12, 13, 15, 16, 20, 22, 23), c(1, 0, 1, 2, 0, 0, 1, 2, 1, 0, 0, 2))returns the second example.Python:
def cr_table(time, cause): s = sorted({t for t, c in zip(time, cause) if c > 0}); n = [sum(1 for t in time if t >= x) for x in s]; d1 = [sum(1 for t, c in zip(time, cause) if t == x and c == 1) for x in s]; d2 = [sum(1 for t, c in zip(time, cause) if t == x and c == 2) for x in s]; surv = list(itertools.accumulate([1-(a+b)/m for a, b, m in zip(d1, d2, n)], operator.mul)); before = ([1.0]+surv)[:len(s)]; F1 = list(itertools.accumulate(w*a/m for w, a, m in zip(before, d1, n))); F2 = list(itertools.accumulate(w*b/m for w, b, m in zip(before, d2, n))); H1 = list(itertools.accumulate(a/m for a, m in zip(d1, n))); H2 = list(itertools.accumulate(b/m for b, m in zip(d2, n))); return {"s": s, "n": n, "d1": d1, "d2": d2, "surv": surv, "F1": F1, "F2": F2, "H1": H1, "H2": H2}Needsimport itertools, operator; returns the same values as the R function.Test (Last row against the printed table): With the twelve patients of the second example, the last values of CumIncEventCol, CumIncCompetingCol, CumHazEventCol and CumHazCompetingCol are compared with the table. Expected result TRUE. FALSE shows a wrong risk set or weight, and a doubled or halved column also fails. Excel check:
=AND(ABS(INDEX(CumIncEventCol,ROWS(CumIncEventCol))-0.419444)<0.0005,ABS(INDEX(CumIncCompetingCol,ROWS(CumIncCompetingCol))-0.580556)<0.0005,ABS(INDEX(CumHazEventCol,ROWS(CumHazEventCol))-0.6)<0.0005,ABS(INDEX(CumHazCompetingCol,ROWS(CumHazCompetingCol))-1.311111)<0.0005)Test (Every row sums to one): Each row of SurvCol, CumIncEventCol and CumIncCompetingCol sums to 1, on any records. Expected result TRUE. FALSE shows a row where the columns no longer partition the cohort. Excel check:
=SUMPRODUCT(--(ABS(SurvCol+CumIncEventCol+CumIncCompetingCol-1)<0.000001))=ROWS(SurvCol)Common error (Censored patients kept in the risk set): Counting n as the starting number less earlier events only, the error of HE-ER-ADMC-003, gives risk sets 12, 11, 10, 9, 8, 7 and 6 for the twelve patients, and F_1 of 0.333 and F_2 of 0.250 at the last time with S of 0.417, against 0.419, 0.581 and 0 (derived from the table).
Source: Andersen PK, Geskus RB, de Witte T, Putter H. Competing risks in epidemiology: possibilities and pitfalls. International Journal of Epidemiology. 2012;41(3):861-870. Equation (2) and Table 1. https://doi.org/10.1093/ije/dyr213
S = S_prev * (1 - (d_1 + d_2) / n); F_1 = F_1_prev + S_prev * d_1 / n; F_2 = F_2_prev + S_prev * d_2 / n; H_1 = H_1_prev + d_1 / n; H_2 = H_2_prev + d_2 / n; ok = abs(S + F_1 + F_2 - 1) < 0.001
Try this function
Implementations
Excel
Cumulative incidence step from named cells
With the state before the step in SurvPrev, PrevCumIncEvent and PrevCumIncCompeting and the counts in EventsOfInterest, CompetingEvents and AtRisk, the three formulas return SurvNew, CumIncEvent and CumIncCompeting. AtRisk of 0 returns #DIV/0!, which cannot arise at a real event time because the patient having the event is in the risk set. A blank count is read as 0 by the arithmetic.
=SurvPrev*(1-(EventsOfInterest+CompetingEvents)/AtRisk); =PrevCumIncEvent+SurvPrev*EventsOfInterest/AtRisk; =PrevCumIncCompeting+SurvPrev*CompetingEvents/AtRisk
Assumptions
First events of mutually exclusive causes
Each patient contributes one first event of one cause or a censoring time. Once a patient has had either event, that patient leaves the risk set n and the other event can no longer be observed, which is the competing risks setting Austin and colleagues define.
Independent censoring in the cumulative incidence risk set
A patient censored at time s is representative of those still at risk at s, the condition Andersen and colleagues state for estimating from censored data. n counts those still at risk just before s, as their N_s does, so a patient censored before s is out of n and any patient with an event earlier than s is out of n whatever the cause.
Worked examples
Time 7 in the twelve-patient table of Andersen and colleagues
Table 1 of Andersen and colleagues follows 12 patients with two competing events. At time 7 there is one event of cause 1 among 10 at risk, after one cause 1 event at time 5 among 12. The source prints the sum of 1/12 and 0.917 times 1/10, which gives 0.175. The inputs here hold 11/12 and 1/12 to six decimals.
S_prev = 0.916667; F_1_prev = 0.083333; F_2_prev = 0; d_1 = 1; d_2 = 0; n = 10; S = 0.825; F_1 = 0.175; F_2 = 0
Time 8 competing event in the twelve-patient table
The next event in the same table is cause 2, with 9 at risk. F_1 stays at 0.175 although the patient can no longer have cause 1, F_2 rises to 0.092 as printed, and S falls to 0.733 as printed.
S_prev = 0.825; F_1_prev = 0.175; F_2_prev = 0; d_1 = 0; d_2 = 1; n = 9; S = 0.733333; F_1 = 0.175; F_2 = 0.091667
Last row of the twelve-patient table, where cause 1 levels off
The last patient at risk has cause 2 at time 23. S reaches 0 and the two cumulative incidences finish at the printed 0.419 and 0.581, so F_1 levels off well below 1 even with all follow-up used up.
S_prev = 0.366667; F_1_prev = 0.419444; F_2_prev = 0.213889; d_1 = 0; d_2 = 1; n = 1; S = 0; F_1 = 0.419444; F_2 = 0.580556
Limiting case with no competing events
With d_2 and F_2_prev both zero, F_1 equals 1 minus S at every step, which is the complement of HE-FM-ADMC-002. The inputs repeat the step of HE-EX-ADMC-004, where survival moves from 0.875 to 0.75 with one event among 7 at risk.
S_prev = 0.875; F_1_prev = 0.125; F_2_prev = 0; d_1 = 1; d_2 = 0; n = 7; S = 0.75; F_1 = 0.25; F_2 = 0
One event of each cause tied at the same time
Illustrative inputs. With one event of each cause among 20 at risk, both increments use the same S_prev of 0.8, each adding 0.04, and S falls by both together to 0.72. The three results still sum to 1.
S_prev = 0.8; F_1_prev = 0.15; F_2_prev = 0.05; d_1 = 1; d_2 = 1; n = 20; S = 0.72; F_1 = 0.19; F_2 = 0.09
Common errors
Weights taken from a Kaplan-Meier curve of cause 1 alone
Censoring the competing events and using the resulting curve in place of S_prev reproduces one minus Kaplan-Meier, the error of HE-ER-AR-002. In the twelve-patient table it gives 0.484 for cause 1 at the end of follow-up against the correct 0.419 (derived from the table), an overstatement of about 15.5%.
Weighting the increment by survival after the event
Using S in place of S_prev in the increment removes the event being counted from its own weight. In the twelve-patient table F_1 finishes at 0.352 against 0.419 (derived from the table), and the sum of S, F_1 and F_2 no longer equals 1.
Adding the event shares without any survival weight
Summing d_1 / n over the event times gives H_1 of HE-FM-COMR-002 and not a risk. In the twelve-patient table this gives 0.600 against the correct 0.419, a cumulative hazard read as a probability.
Sources
Andersen and colleagues on the cumulative incidence integral and its estimate from a small table
Andersen PK, Geskus RB, de Witte T, Putter H. Competing risks in epidemiology: possibilities and pitfalls. International Journal of Epidemiology. 2012;41(3):861-870. Section Competing risks, Equation (2), gives F_1(t) as the integral of S(s) h_1(s) with S(s) the probability of staying event free. Table 1, in section Survival analysis, applies it to 12 patients, with the arithmetic for time 7 printed in the note and the statement that the survival estimate and the two cumulative incidences sum to 1. The table on PubMed Central prints 0.214 for cause 2 at time 13, where that statement and the recursion give 0.092 (derived); the records follow the recursion.
Austin and colleagues on the cumulative incidence function and its sum over causes
Austin PC, Lee DS, Fine JP. Introduction to the analysis of survival data in the presence of competing risks. Circulation. 2016;133(6):601-609. Section Estimating Crude Incidence defines the cumulative incidence function for cause k as Pr(T <= t, D = k), states that the estimates for the individual outcomes sum to the estimate for the composite outcome, and states that it will not necessarily approach unity as time becomes large.
Canonical Identity
Stable URI · Machine-readable · Resolvable · CC BY 4.0
