Why Risk-Set Membership Needs Care
A weighted Cox analysis uses a risk set at each observed event time: the people who are still under observation and could experience the event at that time. In longitudinal data, one person may appear on several start-stop rows because treatment, covariates, or weights change over follow-up. The rows are a way to record one person’s history; they are not separate people. Risk-set construction must therefore answer two questions at each event time: which people are at risk, and which single row supplies each person’s time-specific information?
This tutorial focuses on that construction. It does not derive the weighted partial likelihood or specify a marginal structural Cox model. Those later steps depend on first having the correct risk set and the correct weight for every person in it.
The strict inequality at the start and inclusive inequality at the stop give a consistent rule for intervals of the form \((a,b]\). Thus, a person whose event is recorded at \(t\) is included in the risk set for that event; a person entering exactly at \(t\) is not. An endpoint recorded as censoring at \(t\) is included under this convention. When an event and censoring are recorded at the same time, the data’s event-time ordering must be defined consistently with the analysis software.
Let \(W_i(t)\) be the analysis weight applicable to person \(i\) just before \(t\), and let \(Z_i(t)\) denote the covariate or treatment-history value recorded for that time. The weighted risk-set denominator at \(t\), for a coefficient vector \(\beta\), is
This expression is useful for checking who contributes and with what value. It is not a derivation of the Cox partial likelihood. In a longitudinal analysis, \(W_i(t)\) is commonly the cumulative treatment and censoring weight aligned to the history available immediately before \(t\). It must be finite and defined for the row active at \(t\). A weight is not a substitute for risk-set membership: a person who has already had the event or has been censored before \(t\) contributes nothing, regardless of the size of an earlier weight.
From Start-Stop Rows to People at Risk
Suppose each person’s follow-up is represented by rows \((a_{ij},b_{ij}]\), with an event indicator attached to the row ending at an event. At an event time \(t\), select rows satisfying \(a_{ij}<t\leq b_{ij}\). The set of people represented by those rows is the risk set, provided each person has at most one such row. Their weights and time-varying covariates come from those active rows, evaluated using information available before the event time.
A person can contribute more than once over the entire study, at different event times, but contributes at most once to a particular event-time denominator. If a treatment change divides one person’s follow-up into several rows, only the row containing \(t\) supplies that person’s treatment history and weight at \(t\). If a change occurs exactly at \(t\), use the convention set by the time scale and data encoding; for a predictable, just-before-\(t\) analysis, use the history before that change.
Worked Example: Selecting Rows at an Event Time
At \(t=5\), four people have the following relevant rows and information. Person A has row \((0,5]\), weight \(2\), and \(Z_A(5)=0\); A has the event at 5. Person B has row \((2,7]\), weight \(1.5\), and \(Z_B(5)=1\). Person C has row \((0,4]\) and had an event at 4. Person D enters at 5, with row \((5,8]\). Take \(\beta=\log 2\). Find the risk set and denominator.
A is included because \(0<5\leq5\). B is included because \(2<5\leq7\). C is excluded because the row ended before the event time: \(4<5\). D is excluded because its row starts at the event time, so the strict start condition \(5<5\) fails. Therefore \(\mathcal R(5)=\{A,B\}\).
For A, the denominator contribution is \(2\exp\{(\log 2)0\}=2\). For B, it is \(1.5\exp\{(\log 2)1\}=1.5(2)=3\). Hence \(D(5;\beta)=2+3=5\). A’s event status determines that A has an event at 5; it does not remove A from the risk set for that event.
Two Useful Results About Row-Based Construction
The first result makes precise why a long-format data set should be interpreted at the person level at each event time. Assume follow-up rows for each person form a partition of the observed interval: their interiors do not overlap, and their union covers that follow-up. Assume also that the endpoint convention is the same for every row.
Proof. If person \(i\) is at risk, then \(E_i<t\leq\tilde T_i\), so \(t\) lies within that person’s observed follow-up under the stated endpoint convention. Because the rows cover the follow-up, at least one row contains \(t\). Because the rows do not overlap under the convention, at most one row contains \(t\). Thus exactly one row is active. If person \(i\) is not at risk, \(t\) is outside the observed follow-up, so no row in the partition contains it. Each at-risk person therefore contributes exactly one active-row value \(W_i(t)\exp\{\beta^\mathsf{T}Z_i(t)\}\), and all other people contribute zero. Summing by active rows or by people gives the same sum. \(\square\)
Splitting an interval at a treatment or measurement time is harmless for membership if the new intervals still partition follow-up. It does, however, determine which row supplies the time-specific values. This leads to a second result.
Proof. For \(t<c\), the original row contains \(t\) exactly when \(a<t\leq c\), which is the condition for the first split row. For \(t>c\), the original row contains \(t\) exactly when \(c<t\leq b\), which is the condition for the second split row. At \(t=c\), the original row and the first split row contain \(t\), while the second does not. Thus membership is preserved, and the active row is unique. If \(W_i(t)\) and \(Z_i(t)\) are unchanged across the split, the active row yields the same \(W_i(t)\exp\{\beta^\mathsf{T}Z_i(t)\}\) as the original row. If values change at \(c\), the endpoint rule alone determines the active row, so the analysis must encode the intended temporal ordering consistently. \(\square\)
Worked Example: A Time-Varying Weight and Treatment
An event occurs at \(t=6\). Person E has rows \((0,3]\) and \((3,8]\). The second row records treatment history \(Z_E(6)=1\) and weight \(W_E(6)=2.4\). Person F has row \((1,6]\), with \(Z_F(6)=0\) and \(W_F(6)=0.8\), and has the event at 6. Person G has row \((0,5]\) and is censored at 5. With \(\beta=\log(1.5)\), find the risk set and denominator.
At 6, E’s active row is \((3,8]\), because \(3<6\leq8\). E contributes \(2.4\exp\{(\log1.5)(1)\}=2.4(1.5)=3.6\). F is included because \(1<6\leq6\), and contributes \(0.8\exp\{(\log1.5)(0)\}=0.8\). G is excluded because follow-up ended before 6. Therefore \(\mathcal R(6)=\{E,F\}\) and \(D(6;\beta)=3.6+0.8=4.4\). E’s first-row weight is irrelevant at 6; using it would misalign the weight with E’s event-time history.
Delayed Entry, Censoring, and Tied Events
With delayed entry, a person is not at risk before joining the observed cohort. If entry is at \(E_i\), the strict condition \(E_i<t\) excludes the person at an event time equal to entry. A person censored before \(t\) is excluded, while a person whose observed endpoint is an event at \(t\) is included for that event. These rules concern observed follow-up; they do not depend on whether a person’s weight is large, small, stabilized, or truncated.
If multiple events occur at the same recorded time, they share the same risk-set membership under the chosen endpoint convention. The later handling of ties affects how event contributions are combined, not the basic question of which people were at risk. Do not remove one tied event subject from the risk set before defining the risk set for the other event at that same time unless the analysis explicitly uses a sequential event-time convention.
Worked Example: Delayed Entry and a Shared Event Time
At \(t=10\), person H entered at 2 and has an event at 10, with \(W_H(10)=1.2\) and \(Z_H(10)=0\). Person J entered at 10 and remains under observation afterward, with weight \(2\) and \(Z_J(10)=1\). Person K entered at 1 and was censored at 9. Person L entered at 4, has an event at 10, and has weight \(0.5\) and \(Z_L(10)=1\). For \(\beta=\log 2\), determine the risk set and denominator shared by the two events at 10.
H is included because \(2<10\leq10\). J is excluded because its entry time is exactly 10, not less than 10. K is excluded because \(10\leq9\) is false. L is included because \(4<10\leq10\). Thus \(\mathcal R(10)=\{H,L\}\). H contributes \(1.2\exp(0)=1.2\); L contributes \(0.5\exp(\log2)=1\). The denominator is \(D(10;\beta)=2.2\). Both event subjects are in this same risk set; tied-event calculations are a separate issue.
Diagnostics, Alternatives, and Limitations
Risk-set construction should be checked before fitting a weighted model. Useful diagnostics include verifying that each person has no overlapping rows, that row endpoints cover the intended follow-up, that each event maps to exactly one row, and that the active row’s weight and history are available at every event time. For each event time, a simple tabulation of the number of distinct at-risk people should agree with a direct check of entry and exit times. If the number of active rows exceeds the number of distinct at-risk people, duplicated or overlapping rows are a likely cause.
The most common alternative is an ordinary, unweighted Cox risk set. It has the same membership rule but replaces \(W_i(t)\) by 1. Weighted estimation changes the contribution of people who are at risk; it does not generally change who is at risk. A second alternative is to think directly in counting-process notation, using \(Y_i(t)\) rather than inspecting rows. That is a concise mathematical description, while start-stop records are a practical data representation. Correctly encoded rows should reproduce the subject-level \(Y_i(t)\).
Common failures include counting every row that touches an event time, including a row that starts exactly at that time, and using a person’s baseline or previous-row weight when a different weight applies in the active interval. Another error is to count a person twice because two rows overlap at a shared endpoint. Under the \((a,b]\) convention, adjacent rows \((a,c]\) and \((c,b]\) do not overlap at \(c\): only the first contains it.
A correctly constructed risk set is necessary but does not establish the causal interpretation of a weighted analysis. That interpretation also depends on the causal assumptions and weight construction relevant to the study. Nor can a risk-set calculation repair incorrect event times, unrecorded entry, or an ill-defined weight. Before interpreting a fitted model, verify that follow-up, event coding, time-varying histories, and weights share the same time scale and endpoint convention.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- At \(t=7\), classify a person with row \((2,7]\) as at risk, and explain which endpoint rule applies.
- A person has rows \((0,4]\) and \((4,9]\). Which row is active at \(t=4\)?
- At \(t=5\), person A is at risk with weight 2 and \(Z=0\), while person B is at risk with weight 1 and \(Z=1\). If \(\beta=\log3\), calculate the weighted denominator.
- Why does a person with a very large weight still contribute nothing at an event time after their censoring time?
Solutions. 1. The person is at risk because \(2<7\leq7\); the inclusive stop condition includes the endpoint. 2. The first row \((0,4]\) is active because it includes 4; the second row starts at 4 and requires \(4<4\), which is false. 3. A contributes \(2\exp\{(\log3)0\}=2\), and B contributes \(1\exp\{(\log3)1\}=3\), so the denominator is \(2+3=5\). 4. Risk-set membership requires the person’s observed follow-up to extend to the event time. A weight changes the size of a risk-set contribution, not whether the person is still under observation.