Why a Weighted Cox Fit Needs a Sandwich Variance
A weighted Cox fit solves an estimating equation in which each event is compared with a weighted average over the risk set. That average is estimated from the same people who contribute events. Consequently, the variability of the score does not generally come only from the event terms: a subject can change the risk-set average even if that subject has no event. A valid sandwich variance must include both sources of variation.
We derive the variance for independent subjects with weights treated as known and fixed for this calculation. The derivation uses a continuous-time score without ties for compactness. The same influence-function principle applies to a tied-event score, but its risk-set and event terms must be derived from the particular tie-handling estimating equation being fitted.
Estimating Equation and Assumptions
For subject \(i\), let \(N_i(t)\) be the event counting process, \(Y_i(t)\) the at-risk indicator, \(Z_i(t)\) a column vector of covariates, and \(W_i(t)\) a nonnegative, predictable weight. The regression parameter is \(\beta\). For \(k=0,1,2\), define the population weighted risk-set moments
The population risk-set mean is \(\bar z(t,\beta)=s^{(1)}(t,\beta)/s^{(0)}(t,\beta)\). Its empirical counterpart replaces each expectation by the sample average; write it as \(\bar Z_n(t,\beta)=S_n^{(1)}(t,\beta)/S_n^{(0)}(t,\beta)\). The normalized weighted Cox score is
The fitted value \(\hat\beta\) solves \(u_n(\hat\beta)=0\). Multiplying this equation by \(n\) does not change its root. Write the corresponding population equation as
For the results below, assume subjects are independent and identically distributed; the weights are known, predictable, and not estimated from this sample for purposes of the variance calculation; and the score has a unique target root \(\beta_0\). Assume \(s^{(0)}(t,\beta_0)>0\) on the event-time support, the required score and risk-set quantities have finite second moments, and the empirical risk-set averages obey uniform laws of large numbers and the relevant central limit theorem. Also assume differentiability near \(\beta_0\), stochastic equicontinuity of the score, and a nonsingular score derivative. These conditions allow the Taylor expansion and central limit argument below. They are not causal identification assumptions; weighting does not by itself guarantee that the target is identified.
Deriving the Influence Function
Let \(\mathcal P\) denote the distribution of one subject's observed trajectory. The score is a functional \(u(\mathcal P,\beta)\): changing \(\mathcal P\) changes both the average event contribution and the risk-set mean. To find the effect of one subject on the score, perturb the distribution to \(\mathcal P_\epsilon=(1-\epsilon)\mathcal P+\epsilon\Delta_o\), where \(\Delta_o\) puts all its mass on a particular observed trajectory \(o\).
At fixed \(\beta\), differentiating the ratio defining \(\bar z\) gives
Indeed, the derivative of a ratio \(s^{(1)}/s^{(0)}\) is the derivative of its numerator minus \(\bar z\) times the derivative of its denominator, all divided by \(s^{(0)}\). The terms involving the original distribution cancel in the contamination derivative, leaving the displayed expression. Meanwhile, define the weighted event measure \(\nu(dt)=E[W(t)\,dN(t)]\). Differentiating the score functional therefore yields the following score influence function at \(\beta_0\):
The first two terms are the centered direct event contribution. The final integral accounts for the change in the risk-set mean caused by the subject's observed risk-set history. Since \(u(\beta_0)=0\), that centering term is zero at the target. Also \(E[\phi(O)]=0\): the direct centered term has mean zero, and \(E[r(O,t,\beta_0)]=0\) at every \(t\), by the definition of \(\bar z\).
Worked Example: A Subject Without an Event Can Affect the Score
Consider a one-time risk set with three equally weighted subjects, covariate values \(0,1,2\), and \(\beta=0\). All three are at risk, and the subject with covariate value \(1\) has the only event. Calculate the score influence contributions.
The risk-set mean is \(\bar z=(0+1+2)/3=1\), and \(s^{(0)}=1\). The weighted event measure is \(\nu=1/3\), since one of the three equally weighted subjects has an event. The direct event contribution \(h_i\) is zero for every subject: the event subject contributes \(1-\bar z=0\), and the other two have no event. Thus \(u=0\).
For each subject, \(r_i=Z_i-\bar z\), giving \(r=(-1,0,1)\). Hence \(\phi_i=h_i-u-r_i\nu\) is \((1/3,0,-1/3)\). In particular, the subject with \(Z=0\) has no event but has a nonzero score influence contribution. An outer product of event-only terms would be zero here and would miss this risk-set variation.
From Score Influence to Sandwich Variance
Differentiate the population score with respect to \(\beta\). The derivative of \(\bar z(t,\beta)\) is the weighted risk-set covariance matrix
Because the score contains \(Z-\bar z\), its derivative is minus this covariance, integrated against the weighted event measure. Define the positive bread matrix \(J=-\partial u(\beta_0)/\partial\beta^T\). Then
Proof. The contamination derivative above is the first-order change in the score functional for one observation. Under the assumed empirical-process and moment conditions, its sample version has the expansion
A Taylor expansion of \(u_n(\hat\beta)=0\) around \(\beta_0\), using convergence of its derivative to \(-J\), gives
The independent, mean-zero influence functions have covariance \(\Omega\). The multivariate central limit theorem therefore gives convergence of their normalized sum to a mean-zero normal distribution with covariance \(\Omega\). Multiplication by \(J^{-1}\) on the left and \(J^{-T}\) on the right gives the stated limit. The variance of \(\hat\beta\) is the limiting covariance divided by \(n\). \(\square\)
Estimating the Sandwich and Constructing Intervals
Estimate the influence function by replacing its population quantities with their sample analogues at \(\hat\beta\). In particular, let \(\hat\nu_n(dt)=n^{-1}\sum_j W_j(t)dN_j(t)\), let \(\hat s^{(0)}_n(t)=S_n^{(0)}(t,\hat\beta)\), and use \(\bar Z_n(t,\hat\beta)\) in the risk-set term. The estimated contribution for subject \(i\) is
where \(\bar h_n\) is the sample average of the first integral. It is zero when the fitted score equation is solved exactly. The risk-set term must not be dropped: it is the empirical counterpart of the derivative of the risk-set average. Define \(\hat\Omega=n^{-1}\sum_i\hat\phi_i\hat\phi_i^T\). Estimate \(J\) by the sample weighted risk-set covariance integrated against \(\hat\nu_n\), denoted \(\hat J\). The estimated sandwich covariance is
For a scalar contrast \(c^T\beta\), its robust standard error is \(\{c^T\widehat{\operatorname{Var}}(\hat\beta)c\}^{1/2}\). A large-sample Wald interval is the estimate \(c^T\hat\beta\), plus or minus 1.96 robust standard errors. For a log hazard ratio \(c^T\beta\), exponentiate both endpoints to obtain an interval for the hazard ratio.
Worked Example: Calculating a Robust Confidence Interval
Suppose a fitted one-parameter weighted Cox model has \(\hat\beta=0.30\), estimated bread \(\hat J=2\), and \(n=100\) subject-level influence contributions consisting of 25 copies each of \(-1.2,-0.4,0.4,1.2\). Calculate the robust standard error and a 95% interval.
The contributions average to zero. Their mean square, and thus \(\hat\Omega\), is \((1.44+0.16+0.16+1.44)/4=0.80\). Therefore \(\widehat{\operatorname{Var}}(\hat\beta)=0.80/(100\times 2^2)=0.002\), and the standard error is \(\sqrt{0.002}=0.0447\).
The coefficient interval is \(0.30\pm1.96(0.0447)\), or approximately \((0.212,0.388)\). The estimated hazard ratio is \(e^{0.30}=1.350\); exponentiating the endpoints gives an approximate 95% interval \((e^{0.212},e^{0.388})=(1.236,1.474)\). These are large-sample Wald calculations, not a guarantee of good small-sample coverage.
What the Sandwich Does—and Does Not Do
The sandwich uses the observed variability of the full estimating-equation influence contributions, while \(\hat J\) describes how sensitively the score changes with \(\beta\). This differs from a model-based covariance that substitutes a particular model-implied score variance, often making it equal to an inverse information matrix. The sandwich can remain useful when that model-based variance formula is not justified, provided the independent-subject estimating-equation assumptions and the influence-function variance calculation are appropriate.
A tempting shortcut is to form the meat from the outer products of event-only terms \(W_i\{Z_i-\bar Z_n\}\) at each subject's events. This is generally wrong for the weighted Cox score: those terms use a shared estimated risk-set mean, and their outer products omit its first-order fluctuations. Non-event subjects can have nonzero \(\hat\phi_i\), as the example showed. Diagnostics include checking that the fitted score is near zero, that risk-set denominators remain positive, that the bread is well-conditioned, and that no small number of extreme influence contributions dominates the meat. Extreme weights can make the estimate unstable; the sandwich does not repair positivity problems, confounding, or a misspecified causal target.
This derivation treats weights as fixed. If weights are estimated, their estimation can add uncertainty and their influence must be incorporated for a variance estimator that accounts for that step. Likewise, the independence unit here is the subject: treating multiple records from one subject as independent would violate the stated assumptions. The robust sandwich is a variance method, not a substitute for specifying the correct weighted Cox estimating equation or for justifying the causal interpretation of its parameter.
Check Your Understanding
Answer each question, then compare with the brief solutions below.
- Why can a subject with no event have a nonzero score influence contribution?
- In the scalar case, if \(\hat J=4\), \(n=50\), and \(\hat\Omega=1.6\), what is the estimated sandwich variance and standard error?
- Why is an outer product of event-only score terms generally not a valid robust meat for this score?
- What does the sandwich variance calculation here assume about the weights?
Solutions. (1) The subject's \(W Y e^{\beta^T Z}\) contribution changes the empirical risk-set average, producing a nonzero risk-set term in \(\hat\phi_i\). (2) The variance is \(1.6/(50\times16)=0.002\), so the standard error is \(\sqrt{0.002}\approx0.0447\). (3) Event-only terms omit first-order variability from the shared estimated risk-set mean; the full influence contributions include that effect. (4) The weights are treated as known and fixed; uncertainty from estimating them is not included.