Why categorical coding matters in transition models
A categorical covariate can describe treatment group, disease subtype, or another set of distinct groups. A transition-specific regression model needs numerical inputs, but assigning numbers to categories does not automatically give those numbers a meaningful order or distance. The coding must represent the intended comparisons without imposing an unintended structure.
This tutorial focuses on reference-cell, or treatment, coding. It explains how to create indicator variables for a categorical covariate, how to interpret the resulting coefficients for a particular transition, and how to compare two non-reference categories. The central distinction is between a category’s label and the numerical indicator used to represent it.
Building and interpreting the indicators
With three categories, for example, the reference category has indicator values \((Z_1,Z_2)=(0,0)\). Category \(c_1\) has values \((1,0)\), and category \(c_2\) has values \((0,1)\). The model therefore compares each non-reference category with \(c_0\). It does not assign a numerical score to the categories, and it does not assume that the effect of moving from one category to the next is constant.
For transition \(r\), the conditional hazard ratio for \(c_j\) versus the reference is \(\exp(\beta_{rj})\). To compare two non-reference categories \(c_j\) and \(c_\ell\), subtract their coefficients on the log scale and exponentiate:
These comparisons are conditional on the other covariates and apply to the specified transition. If each transition has its own regression coefficients, the same category can have different hazard ratios for different transitions. A comparison between categories within one transition is not the same estimand as a comparison of a covariate effect across two transitions.
The model and its assumptions must be suitable before interpreting these coefficients. In a transition-specific Cox model, the proportional-hazards assumption is that, within transition \(r\), the covariate effects are constant over the analysis time scale represented by the model. The transition-specific baseline intensity may vary over time. The transition risk sets must be defined correctly, and the observed covariate values must correspond to the intended prediction time. Inference also requires an appropriate censoring assumption: conditional on the modeled covariates and relevant observed history, censoring must not carry unaccounted information about the transition process. Finally, there must be enough information in the relevant risk sets to distinguish the category effects; a category absent from those risk sets, or completely confounded with another covariate, cannot have an independently estimated effect.
Worked Example: Three Categories and a Non-Reference Comparison
Suppose a hypothetical transition-specific Cox model examines the transition from a stable state to a worsening state. The categorical covariate is support group, with groups A, B, and C; A is the reference. The fitted coefficients are \(\hat\beta_{rB}=0.405\) and \(\hat\beta_{rC}=-0.223\). For this calculation, assume the model’s proportional-hazards form is appropriate, both groups occur in the transition risk sets, and the estimates are not confounded with other included covariates.
The estimated hazard ratio for B versus A is \( \exp(0.405)=1.50 \). Conditional on the other covariates, the estimated transition intensity for group B is 1.50 times the intensity for group A at a given time. The estimated hazard ratio for C versus A is \( \exp(-0.223)=0.800 \), so the estimated intensity for C is 0.800 times that for A.
To compare C directly with B, subtract the coefficients: \( \hat\beta_{rC}-\hat\beta_{rB}=-0.223-0.405=-0.628 \). Thus the estimated hazard ratio is \( \exp(-0.628)=0.534 \). In this hypothetical model, C has an estimated transition intensity about 0.534 times that of B, conditional on the other covariates. This comparison does not require refitting with B as the reference.
Suppose the estimated variances are \( \widehat{\mathrm{Var}}(\hat\beta_{rC})=0.0400 \) and \( \widehat{\mathrm{Var}}(\hat\beta_{rB})=0.0625 \), with estimated covariance \(0.0150\). The variance of the coefficient difference is \(0.0400+0.0625-2(0.0150)=0.0725\), so its standard error is \( \sqrt{0.0725}=0.269 \). A Wald 95% confidence interval on the log hazard-ratio scale is \( -0.628\pm1.96(0.269)=[-1.155,-0.101] \). Exponentiating the endpoints gives an approximate 95% confidence interval of \([0.315,0.904]\) for the C-versus-B hazard ratio. Under the model, this interval describes uncertainty in the conditional transition hazard ratio; it is not a probability statement about where the fixed parameter lies.
Why the contrast uses the coefficient covariance
A comparison of two non-reference categories is a linear contrast. The standard error must reflect the uncertainty in both coefficients and their dependence. For estimates \(\hat\beta_{rj}\) and \(\hat\beta_{r\ell}\),
This follows from the variance rule for a difference: for random variables \(A\) and \(B\), \(\mathrm{Var}(A-B)=\mathrm{Var}(A)+\mathrm{Var}(B)-2\mathrm{Cov}(A,B)\). Treating the two coefficient estimates as independent would incorrectly drop the covariance term. After obtaining the contrast estimate and its standard error, a Wald interval can be formed on the log hazard-ratio scale and exponentiated to return to the hazard-ratio scale.
Worked Example: Coding a Binary Covariate Across Two Transitions
Consider a hypothetical two-transition model for transitions from state 0 to state 1 and from state 0 to state 2. A binary covariate \(C\) indicates exposure: unexposed is the reference and exposed is coded \(Z=I(C=\text{exposed})\). Suppose the fitted transition-specific coefficients are \(0.588\) for transition \(0\to1\) and \(-0.105\) for transition \(0\to2\). Assume each transition’s proportional-hazards model and risk sets are appropriate, both exposure groups are represented in each relevant risk set, and the conditional censoring assumption is reasonable.
For transition \(0\to1\), the exposed-versus-unexposed hazard ratio is \( \exp(0.588)=1.80 \). For transition \(0\to2\), it is \( \exp(-0.105)=0.900 \). The correct interpretation is transition-specific: conditional on other model covariates, the exposed group has an estimated 1.80 times the transition intensity for \(0\to1\), and 0.900 times the transition intensity for \(0\to2\), each relative to the unexposed group.
The coding is the same in both models: unexposed has \(Z=0\), exposed has \(Z=1\). The difference in the resulting coefficients reflects the transition-specific estimates. These two numbers alone do not establish that the exposure effects differ statistically across transitions; that claim requires an appropriate contrast and its uncertainty, a distinct comparison from interpreting each coefficient separately.
Changing the reference and choosing alternatives
The reference category is a choice of parameterization, not a scientific claim that the reference group is normal, untreated, or unimportant. Changing it changes the coefficient labels and values, but not the fitted category-specific transition intensities or the comparisons implied by the model. In a Cox model, the baseline intensity provides the reference level for the covariates; the category contrasts are represented by the coefficients.
Worked Example: Releveling an Ordinal-Labeled Factor
Suppose a hypothetical model for one transition includes severity as a three-level categorical covariate: mild, moderate, and severe. With mild as the reference, the fitted coefficients are \(0.30\) for moderate and \(0.90\) for severe. Assume the model is suitable for this transition and each category is represented in its risk sets. The estimated moderate-versus-mild hazard ratio is \( \exp(0.30)=1.35 \), while severe versus mild is \( \exp(0.90)=2.46 \). Severe versus moderate is \( \exp(0.90-0.30)=\exp(0.60)=1.82 \).
Now choose severe as the reference. The new coefficients are mild versus severe, \(0-0.90=-0.90\), and moderate versus severe, \(0.30-0.90=-0.60\). Their hazard ratios are \( \exp(-0.90)=0.407 \) and \( \exp(-0.60)=0.549 \). These are the reciprocals of the corresponding comparisons with severe in the numerator. For example, \(1/1.82\approx0.549\) for moderate versus severe.
The fitted comparisons have not changed; only their reference direction has. Although the levels have an apparent order, the categorical coding does not assume equal spacing between mild, moderate, and severe or a constant increase in log intensity from one level to the next.
Reference-cell coding uses \(K-1\) indicators and gives direct comparisons with a named category. An alternative is a cell-means parameterization, which represents each category separately and then constructs contrasts between them. Effect coding uses a different set of constraints, so its coefficients do not have the same direct reference-category interpretation. These parameterizations can represent the same set of category-specific effects when they are full rank; the useful choice depends on which comparisons should be easiest to read.
Do not include all \(K\) category indicators together with an estimable intercept or equivalent unrestricted category baseline. Since the indicators sum to one for every observation, they are linearly dependent with the intercept, and the model cannot uniquely identify all those coefficients. In Cox regression the baseline intensity absorbs a common level, but the same principle applies: use an identifiable set of contrasts rather than redundant category terms.
Diagnostics and common coding errors
- Using category labels as a numerical score. Coding A, B, and C as 1, 2, and 3 and entering that single number imposes a one-parameter trend in log intensity. It is not equivalent to reference-cell coding and is generally unjustified for nominal categories.
- Leaving the reference implicit. A coefficient has no useful category interpretation until the reference level is stated. Check the software’s factor-level ordering rather than assuming which category it selected.
- Interpreting a coefficient as an absolute intensity. A coefficient is a log hazard ratio relative to the reference category for a particular transition, conditional on other covariates. It is not a difference in event probabilities or a ratio of cumulative risks.
- Using the wrong transition for the interpretation. A coefficient from one transition model describes that transition’s intensity, not every transition out of the state or the overall probability of reaching a destination.
- Ignoring sparse categories or empty risk-set comparisons. Very few events, no events, or little covariate variation can yield unstable estimates, large standard errors, or non-estimability. Inspect category counts and transition-specific events and risk sets; a software coefficient is not evidence that the comparison is well supported.
- Assuming a changed reference changes the fit. Releveling should preserve fitted transition intensities and yield equivalent contrasts. A changed fit can signal different data handling, omitted levels, or a different model—not merely a different reference.
The coding decision does not repair a misspecified transition model, inappropriate risk sets, or a time-varying effect where the model assumes a constant coefficient. Nor does it make a category comparison causal. It provides a clear and identifiable way to express conditional associations between category membership and transition intensity under the stated model assumptions.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- A four-level factor has level A as the reference. How many indicators are used, and what indicator pattern represents level C?
- For one transition, the coefficients for B and C versus reference A are \(0.20\) and \(-0.10\). Calculate the estimated hazard ratio for C versus B.
- Why is it not generally valid to code three unordered categories as 1, 2, and 3 and fit one numerical coefficient?
- When changing the reference category, which quantities should remain unchanged, and which coefficient interpretation changes?
Solutions. (1) Use \(4-1=3\) indicators, one for each non-reference level. For level C, the indicator for C is 1 and the indicators for the other non-reference levels are 0. (2) The log contrast is \(-0.10-0.20=-0.30\), so the estimated C-versus-B hazard ratio is \(\exp(-0.30)=0.741\). (3) A single numerical coefficient imposes an ordered, constant log-intensity change per one-unit increase; unordered labels do not justify that structure. Use indicators unless that trend is substantively intended. (4) Fitted category-specific transition intensities and valid pairwise contrasts should remain unchanged. Coefficients are re-expressed relative to the new reference, so their values and direct interpretations change.