Tutorials › Competing Risks and Multi-State Models › Choosing Covariate Coding for Cause-Specific Cox Models

Regression: Cause-Specific Cox and Fine-Gray · Tutorial 126 of 699

Choosing Covariate Coding for Cause-Specific Cox Models

Learn to choose and verify categorical covariate coding, then express cause-specific hazard comparisons as interpretable coefficient contrasts.

Advanced 12 min read

What You'll Learn

  • Set up reference-level coding for a factor in a cause-specific Cox model.
  • Interpret each coefficient as an adjusted cause-specific hazard ratio against the reference category.
  • Calculate a hazard ratio and confidence interval for a nonreference-versus-nonreference comparison.
  • Understand why changing the reference level changes coefficients but not fitted comparisons.
  • Distinguish a general factor effect from a one-degree-of-freedom trend assumption.
  • Check model matrices and event counts for coding errors and unstable estimates.

Why Covariate Coding Matters

A categorical predictor does not have a numerical slope until its levels are represented in a model. That representation determines which coefficient appears in the output and which comparison it describes. In a cause-specific Cox model, an incorrectly chosen reference level or an unexamined contrast can make a correct fit difficult to interpret—or can impose a restrictive pattern that was not intended.

The issue is not that one valid coding scheme creates a different scientific model from another. When two schemes represent the same set of possible linear predictors, they give the same fitted relative hazards and likelihood. They differ in the coordinates used to report those effects. The analyst’s task is to make those coordinates transparent and to calculate the comparison that answers the scientific question.

Definition: For cause \(k\), a cause-specific Cox model with predictor vector \(x\) has hazard $$ \lambda_k(t\mid x)=\lambda_{k0}(t)\exp(x^\mathsf{T}\beta_k), $$ where \(\lambda_{k0}(t)\) is the cause-specific baseline hazard and \(\beta_k\) is the coefficient vector. A categorical factor with \(K\) levels is represented by contrasts that encode its levels in the predictor vector. Under reference-level coding, one level is omitted and serves as the comparison category; the other \(K-1\) coefficients give log cause-specific hazard ratios relative to it, conditional on the other model covariates.

The model is fitted separately for a specified cause. In the cause-specific analysis, a competing event ends a person’s time in that cause’s risk set. Coding choices do not change that event definition. The usual interpretation also presumes independent subjects, appropriate handling of censoring conditional on the modeled covariates, and a correctly specified cause-specific Cox model, including proportional effects for the coefficients being interpreted. These assumptions concern the model and data, not the choice of reference category.

Reference-Level Coding

Suppose a factor has levels A, B, and C, and A is selected as the reference. Its two indicator variables are \(I(B)\) and \(I(C)\). In a model with another covariate \(z\), the linear predictor for cause \(k\) is $$ \eta_k=\beta_{Bk}I(B)+\beta_{Ck}I(C)+\gamma_k z. $$

For a person in A, both indicators are zero. Holding \(z\) fixed, the B-versus-A cause-specific hazard ratio is \(\exp(\beta_{Bk})\), and the C-versus-A ratio is \(\exp(\beta_{Ck})\). The factor has two coefficients because it has three levels and one level is the reference. The intercept-like baseline hazard is not a coefficient for the reference category; it is the hazard for the reference covariate pattern, with its time dependence left unspecified.

Worked Example: Choosing a Reference for a Three-Level Factor

Consider a hypothetical study of time to one specified cause of failure, with competing events handled as competing events in the cause-specific analysis. A treatment factor has levels Standard, Regimen B, and Regimen C. Standard is selected as the reference. A fitted model, adjusted for age, reports \(\hat\beta_B=0.30\) with \(SE=0.224\), and \(\hat\beta_C=0.80\) with \(SE=0.300\). These are hypothetical model estimates.

The fitted model compares each regimen with Standard at the same age. For Regimen B, the estimated log hazard ratio is 0.30, so the estimated cause-specific hazard ratio is $$ \exp(0.30)=1.350. $$ Thus, at a given time and age, the estimated cause-specific hazard for Regimen B is 1.35 times the corresponding hazard for Standard. This is a hazard comparison, not a comparison of cumulative probabilities of experiencing the event.

For Regimen C, the estimated ratio is $$ \exp(0.80)=2.226. $$ This says the estimated cause-specific hazard for C is 2.23 times that for Standard, conditional on age. The coefficients do not directly compare B with C; that requires a contrast of the two coefficients.

For illustration, a Wald 95% interval for the B-versus-Standard log hazard ratio is \(0.30\pm1.96(0.224)=(-0.139,0.739)\). Exponentiating both endpoints gives an interval of approximately \((0.870,2.094)\) for the hazard ratio. Under the model and Wald approximation, the procedure used to construct such intervals has 95% coverage over repeated samples; this is not a 95% probability statement about the fixed parameter in this particular interval.

Contrasts Answer Comparisons Beyond the Reference

Any comparison between two factor levels is a contrast: a linear combination of fitted coefficients whose weights sum to zero when expressed across level-specific effects. With A as reference, the log hazard ratio for C versus B is \(\beta_{Ck}-\beta_{Bk}\). Its variance depends on both coefficient variances and their covariance. It is generally incorrect to calculate its standard error by subtracting the standard errors or by treating the estimates as independent.

Worked Example: Comparing Two Nonreference Levels

Use the hypothetical adjusted fit above, and suppose its estimated covariance matrix for \((\hat\beta_B,\hat\beta_C)\) is $$ \widehat{\mathrm{Var}} \begin{pmatrix} \hat\beta_B\\ \hat\beta_C \end{pmatrix} = \begin{pmatrix} 0.050 & 0.030\\ 0.030 & 0.090 \end{pmatrix}. $$ Calculate the C-versus-B comparison.

The estimated log hazard ratio is the contrast \(0.80-0.30=0.50\). Its estimated variance is $$ \widehat{\mathrm{Var}}(\hat\beta_C-\hat\beta_B) =0.090+0.050-2(0.030)=0.080, $$ so its standard error is \(\sqrt{0.080}=0.2828\). The estimated C-versus-B cause-specific hazard ratio is \(\exp(0.50)=1.649\).

A Wald 95% interval on the log scale is $$ 0.50\pm1.96\sqrt{0.080}=( -0.0544,\ 1.0544). $$ Exponentiating gives approximately \((0.947,2.870)\). The interval includes 1, so these data do not provide strong evidence at the two-sided 5% level that the cause-specific hazards for C and B differ, conditional on age and under the model. The interval is also compatible with appreciably lower or higher hazard for C.

The corresponding Wald statistic for testing equal cause-specific hazards, \(H_0:\beta_C-\beta_B=0\), is $$ z=\frac{0.50}{\sqrt{0.080}}=1.768. $$ The two-sided normal-approximation p-value is about 0.077. This p-value is the probability, under the null and the reference approximation, of a statistic at least as extreme as the observed one; it is not the probability that the null hypothesis is true.

In matrix notation, a requested comparison can be written \(L\beta_k\), where \(L\) is a row vector specifying the contrast. Its estimated variance is \(L\widehat{\mathrm{Var}}(\hat\beta_k)L^\mathsf{T}\). This is the general calculation behind the example. For a joint test that a \(K\)-level factor has no cause-specific association, the null is that all \(K-1\) factor coefficients are zero in reference coding. A joint Wald test uses the coefficient vector and its full covariance matrix; it is not the same question as whether one selected coefficient is individually significant.

Changing the Reference Does Not Change the Comparisons

A reference category should be selected for interpretability, not because it is expected to produce a more favorable result. If the same factor is represented with a different reference and the model still includes the same covariates, fitted linear predictors can be preserved exactly. Consequently, the partial likelihood and fitted relative hazards are unchanged, apart from numerical rounding or differences caused by software options.

For example, changing the reference from A to B in the fit above gives a coefficient for A versus B of \(-0.30\) and a coefficient for C versus B of \(0.80-0.30=0.50\). The corresponding hazard ratios are \(\exp(-0.30)=0.741\) for A versus B and \(\exp(0.50)=1.649\) for C versus B. The first is the reciprocal of B versus A; the second is the nonreference comparison calculated directly in the previous example.

Worked Example: Verifying a Reference-Level Change

Suppose the original coefficient covariance entries are \(\mathrm{Var}(\hat\beta_B)=0.050\), \(\mathrm{Var}(\hat\beta_C)=0.090\), and \(\mathrm{Cov}(\hat\beta_B,\hat\beta_C)=0.030\). With B as reference, the new coefficients are \(\hat\beta_A^*=-\hat\beta_B\) and \(\hat\beta_C^*=\hat\beta_C-\hat\beta_B\). Their estimates are \(-0.30\) and \(0.50\).

The new variance for the C-versus-B coefficient is $$ \mathrm{Var}(\hat\beta_C^*)=0.090+0.050-2(0.030)=0.080. $$ The new variance for A versus B is \(0.050\), since changing the sign does not change a variance. The covariance between the new coefficients is $$ \mathrm{Cov}(-\hat\beta_B,\hat\beta_C-\hat\beta_B) =-0.030+0.050=0.020. $$ These transformed estimates describe the same fitted factor effects in a different coordinate system. The standard error for C versus B is \(\sqrt{0.080}=0.2828\), agreeing with the direct contrast calculation.

Choosing Among Contrast Schemes

Reference-level coding is often the clearest choice when the main question compares each category with a meaningful baseline, such as usual care or the lowest exposure group. Other full-rank contrast schemes can be useful, but their coefficient meanings must be stated explicitly. Effect coding, for example, can express level effects relative to a constraint such as a sum-to-zero condition; it does not make each coefficient a comparison with the baseline category. Orthogonal or Helmert contrasts can target ordered comparisons. A factor with scientifically ordered levels can also be assigned numeric scores, but doing so imposes a trend structure rather than allowing an unrelated effect for every level.

Worked Example: Factor Effect or Linear Trend?

Suppose a hypothetical exposure factor has three ordered categories: low, medium, and high. A reference-coded model uses low as the reference and estimates separate coefficients \(\hat\beta_M=0.25\) and \(\hat\beta_H=0.70\). The estimated medium-versus-low hazard ratio is \(\exp(0.25)=1.284\), while high versus low is \(\exp(0.70)=2.014\). This model allows the two increments to differ.

If instead the categories are scored 0, 1, and 2 and entered as one numeric predictor \(s\), the model has linear predictor \(\theta s\). The model then requires the medium-versus-low and high-versus-medium log hazard ratios to be equal: each is \(\theta\). The high-versus-low ratio is \(\exp(2\theta)\). For instance, a fitted \(\hat\theta=0.30\) implies adjacent-category ratios of \(\exp(0.30)=1.350\) and a high-versus-low ratio of \(\exp(0.60)=1.822\).

That one-coefficient trend model is not merely another way to print the unrestricted two-coefficient factor model. It imposes an equal-step log-hazard pattern. Use numeric scoring when that restriction is scientifically justified, or assess it against the more flexible factor representation; do not treat category labels as equally spaced measurements automatically.

Diagnostics, Limitations, and Common Mistakes

Before interpreting output, inspect the factor levels and the model matrix. Confirm which level is the reference, that each intended level is represented, and that the number of independent columns matches the intended contrasts. Tabulate the number at risk and the number of events of the target cause in each level. Sparse levels can yield unstable estimates, large standard errors, or monotone likelihood; changing the reference will not fix a lack of information. An empty level, a duplicated indicator, or an unexpected factor ordering can signal a coding error or a rank-deficient model.

Coding decisions also have limits. A reference-level coefficient is conditional on the other covariates in the specified model; it is not automatically a marginal association. A hazard ratio is not a risk ratio, and coding alone does not yield cumulative incidence. If the proportional hazards or other model assumptions fail, a cleanly labeled contrast can still be a poor summary of the time-dependent association. Those issues require model assessment beyond the factor’s coding.

Key takeaway: Choose a coding scheme that represents the scientific comparisons, name its reference or contrast constraints, and calculate the corresponding linear contrast with the fitted covariance matrix. Equivalent full-rank codings change coefficient labels and values, not the underlying fitted cause-specific hazard comparisons.

Check Your Understanding

For each question, first identify the comparison represented by the coding, then check the solution.

  1. A four-level factor uses level D as the reference. How many factor coefficients are fitted, and what does the coefficient for level A represent?
  2. With level 1 as reference, \(\hat\beta_2=0.20\) and \(\hat\beta_3=0.65\). What is the estimated cause-specific hazard ratio for level 3 versus level 2?
  3. In a three-level factor model, the estimated variances of \(\hat\beta_2\) and \(\hat\beta_3\) are 0.04 and 0.09, and their covariance is 0.01. Find the standard error for \(\hat\beta_3-\hat\beta_2\).
  4. Why does coding ordered categories as scores 0, 1, and 2 impose a different model from using a two-coefficient factor representation?
  5. After changing the reference category, the displayed coefficients change. Does that alone imply the fitted model has changed? Explain.

Solutions. (1) Three coefficients are fitted. The coefficient for A is the log cause-specific hazard ratio for A versus D, conditional on the other covariates. (2) The log ratio is \(0.65-0.20=0.45\), so the estimated ratio is \(\exp(0.45)=1.568\) for level 3 versus level 2. (3) The contrast variance is \(0.09+0.04-2(0.01)=0.11\), so its standard error is \(\sqrt{0.11}=0.3317\). (4) A numeric score uses one slope and requires equal log-hazard increments between adjacent scores; the unrestricted factor model estimates the two increments separately. (5) No. With equivalent full-rank codings, the linear predictors and fitted comparisons are unchanged; the coefficients have been re-expressed relative to a different reference.

Back to Tutorials
Clinical Biostats