Tutorials › Response-Adaptive Randomization › Coding and Scaling Covariates for Allocation Models

Covariate-Adaptive and Covariate-Adjusted Allocation · Tutorial 442 of 501

Coding and Scaling Covariates for Allocation Models

Represent baseline covariates clearly in adaptive outcome models, and determine whether a coding or scaling change preserves the model’s predictions.

Intermediate 10 min read

What You'll Learn

  • Encode a categorical baseline variable with a reference category and \(K-1\) indicators.
  • Distinguish binary indicator coding from using a full set of category indicators with an intercept.
  • Center and scale continuous covariates, including the corresponding coefficient transformations.
  • Check when recoding preserves a model’s predictions and when changing the model specification does not.
  • Diagnose rank deficiency, inconsistent coding, and extrapolation caused by poorly chosen scales.

Why Coding Matters in an Allocation Model

An adaptive outcome model uses baseline information to describe expected outcomes for treatment and patient profiles. A model’s coding determines how its coefficients are expressed: a coefficient may compare a category with a reference group, or describe the outcome change for a one-unit covariate increase. These choices affect interpretation and numerical stability. They do not necessarily change the fitted predictions used by an allocation procedure.

The key distinction is between changing the representation of the same model and changing the model itself. A one-to-one change of coordinates, with coefficients transformed accordingly, preserves the model’s possible predictions. Omitting a category indicator, changing a covariate’s functional form, or leaving old coefficients in place after changing the coding can alter predictions. Since allocation probabilities may depend on model-based predictions, this distinction matters operationally as well as statistically.

Reference and Indicator Coding

Definition: For a categorical baseline variable with \(K\) categories, reference coding selects one category as the reference and represents each of the other \(K-1\) categories with an indicator variable. An indicator equals 1 when an observation belongs to its named category and 0 otherwise. With an intercept, the intercept describes the reference category (at the specified values of any other covariates), and each indicator coefficient is a difference from that reference.

For a binary variable, coding one category as 1 and the other as 0 is indicator coding; the 0 category serves as the reference. For a variable with more than two categories, the same idea uses one indicator for every nonreference category. This is often called treatment or dummy coding. The word “treatment” in that name refers to the contrast coding, not necessarily to a clinical treatment.

With an intercept, including indicators for all \(K\) categories creates exact linear dependence: for every participant, the \(K\) indicators sum to 1, which is also the intercept column. A model cannot uniquely estimate all \(K\) category coefficients and the intercept from this redundant representation. Use \(K-1\) indicators with an intercept, or use all \(K\) indicators without an intercept when that parameterization is appropriate.

Worked Example: Coding a Three-Level Baseline Variable

Suppose a hypothetical trial records baseline disease severity as mild, moderate, or severe. Use mild as the reference category. For participant \(i\), define \(D_{Mi}=1\) for moderate severity and \(0\) otherwise, and \(D_{Si}=1\) for severe severity and \(0\) otherwise. A linear outcome model, at a fixed treatment and other covariate values, can include

$$ E(Y_i\mid D_{Mi},D_{Si})=\beta_0+\beta_M D_{Mi}+\beta_S D_{Si}. $$

For a mild participant, the indicators are \((0,0)\), so the fitted mean is \(\beta_0\). For a moderate participant, they are \((1,0)\), giving \(\beta_0+\beta_M\); for a severe participant, they are \((0,1)\), giving \(\beta_0+\beta_S\). If the fitted coefficients are \(\beta_0=10\), \(\beta_M=2\), and \(\beta_S=5\), the predicted means are 10, 12, and 15 outcome units, respectively.

The coefficients 2 and 5 are differences from mild, not absolute means for moderate and severe. If all three indicators were included alongside the intercept, their sum would equal 1 for every row, so the parameters would not be uniquely identified without an additional constraint or a different parameterization.

Centering and Scaling Continuous Covariates

A continuous baseline covariate can be used in its original units or transformed before it enters the model. Centering subtracts a chosen value \(c\), commonly the sample mean or a clinically meaningful value. Scaling divides by a positive constant \(s_x\), such as a sample standard deviation or a meaningful unit increment. These operations change coefficient units and often make the intercept easier to interpret.

Definition: Given a covariate \(x_i\), centering and scaling produce \(z_i=(x_i-c)/s_x\), where \(c\) is the chosen center and \(s_x>0\) is the chosen scale. If a model includes an intercept and the same linear covariate, this affine transformation is reversible: \(x_i=c+s_xz_i\).

In a linear predictor \(\beta_0+\beta_x x_i\), the intercept is the predicted value at \(x_i=0\), which might be outside the relevant range. Rewriting the same predictor in terms of \(z_i\) gives

$$ \beta_0+\beta_x x_i =(\beta_0+c\beta_x)+(s_x\beta_x)z_i. $$

Thus the transformed coefficients are \(\beta_0^*=\beta_0+c\beta_x\) and \(\beta_z=s_x\beta_x\). The predictions are unchanged, while the transformed intercept describes \(x_i=c\), and the transformed slope describes the predictor change for a \(s_x\)-unit increase in the original covariate. In a generalized linear model, the same identity applies to the linear predictor; applying the inverse link then gives identical predicted means or probabilities.

Worked Example: Centering and Scaling Age

Consider a hypothetical outcome model with linear predictor \(\eta_i=4+0.08x_i\), where age \(x_i\) is measured in years. For a 60-year-old, \(\eta_i=4+0.08(60)=8.8\). Suppose age is instead expressed as \(z_i=(x_i-50)/10\), so \(z_i=1\) means age 60. Substitution gives

$$ 4+0.08x_i =4+0.08(50+10z_i) =8+0.8z_i. $$

The transformed intercept is 8 and the coefficient of \(z_i\) is 0.8. At age 60, the transformed predictor is \(8+0.8(1)=8.8\), exactly as before. At age 50, it is \(8+0.8(0)=8\), which also equals the original predictor \(4+0.08(50)=8\). If this is a logistic model, the predicted probability is the inverse-logit of \(\eta_i\) in either representation; because the linear predictors match, the predicted probabilities match as well.

If the original coefficient 0.08 were mistakenly retained after replacing \(x_i\) with \(z_i\), the age-60 predictor would be \(4+0.08(1)=4.08\), not 8.8. The transformation preserves predictions only when the coefficients are expressed in the new coordinates.

What Changes Predictions—and What Does Not

A useful way to check a coding change is to write down the linear predictor before and after the change and substitute the new variables. If the expressions are algebraically identical for every possible covariate profile, then the model’s fitted predictions are identical when coefficients are transformed consistently. This is a statement about the model’s representation, not a claim that every estimation procedure or allocation algorithm will behave identically under all implementations.

For ordinary unpenalized regression with the same observations and a full-rank, equivalent design matrix, changing from one full set of coordinates to another leaves the fitted values unchanged. The coefficient values and interpretations can differ. The justification is direct: each predictor value represented by the original model is also represented by the transformed model, and vice versa. Therefore both models minimize the same residual criterion over the same set of possible fitted-value vectors. For a generalized linear model, the same equivalence holds when the linear predictors attainable under the two parameterizations are the same.

Worked Example: Releveling a Category Without Changing Predictions

Return to the hypothetical severity model, whose fitted means are 10 for mild, 12 for moderate, and 15 for severe. Now choose severe as the reference. Define indicators \(D_{Mi}=1\) for moderate and \(D_{Li}=1\) for mild. The same three fitted means are represented by

$$ E(Y_i\mid D_{Mi},D_{Li})=15-3D_{Mi}-5D_{Li}. $$

For severe participants, both indicators are 0 and the prediction is 15. For moderate participants, the prediction is \(15-3=12\). For mild participants, it is \(15-5=10\). The intercept and contrasts differ from those in the first coding, but the prediction for each category is unchanged. Releveling therefore changes the questions answered directly by the coefficients, not the category-specific fitted means.

Now suppose the moderate indicator is accidentally omitted while mild remains the reference. The resulting model assigns both moderate and severe participants the same category contribution (zero). It cannot represent the original three distinct means. This is not merely a new coding of the same model: it removes a distinction and can change fitted predictions.

Interactions and Practical Model Checks

When a model includes treatment-by-covariate interactions, transformations must be applied to the interaction terms as well as to the main effects. For example, with treatment indicator \(A_i\) and centered covariate \(z_i=(x_i-c)/s_x\), a linear predictor containing \(\beta_0+\beta_A A_i+\beta_x x_i+\beta_{Ax}A_ix_i\) can be rewritten using \(z_i\). Since \(x_i=c+s_xz_i\), the treatment coefficient becomes \(\beta_A+c\beta_{Ax}\), and the coefficient of \(A_iz_i\) becomes \(s_x\beta_{Ax}\). Retaining the old interaction coefficient after scaling would generally change predictions.

A common convention is to include the lower-order terms whenever an interaction is included. With that structure, centering changes the coefficient interpretations but preserves the same fitted relationships when all corresponding coefficients are transformed. If a model omits lower-order terms or imposes other constraints, equivalence must be checked from the actual model formula rather than assumed.

In practice, check the following before using a transformed baseline variable in an adaptive outcome model:

  • Category map: confirm that each recorded category maps to exactly one intended indicator pattern and that the reference category is explicit.
  • Redundancy: with an intercept, do not include every category indicator unless a deliberate identifying constraint is used.
  • Units and center: record the original units, center, and scale so coefficients and predictions can be interpreted and reproduced.
  • Model terms: transform interactions and any polynomial terms consistently; transforming only the main effect may change the model.
  • Prediction checks: calculate predictions for several profiles using both parameterizations. Differences beyond rounding suggest a coding or coefficient-conversion error.
  • Data support: verify that the center and scale are sensible and that categories or covariate ranges used for prediction are represented adequately. Scaling cannot remedy sparse categories or unsupported extrapolation.

Centering and scaling are often preferred to raw measurements when the raw zero is scientifically meaningless, units are very large or small, or numerical computation is poorly conditioned. They do not create information, correct a misspecified outcome model, or make an unsupported patient profile reliable. Standardizing a covariate also changes the meaning of its coefficient: it is now tied to the chosen scale, so report that scale.

Choosing a Coding Convention

Reference coding is especially useful when comparisons with a particular baseline category are central to interpretation. Alternative contrast systems can instead express comparisons with an overall mean or other specified combinations of categories. With the same model space, these are alternative coordinate systems: coefficient interpretations change, but fitted values do not. The choice should make the model easiest to interpret and communicate, while avoiding redundant columns.

For continuous variables, retaining original units makes a slope easy to explain per year, kilogram, or other natural unit. Centering can make the intercept meaningful, and scaling can make coefficient magnitudes easier to compare or improve numerical conditioning. In penalized models, models with prior distributions on coefficients, or algorithms that use coefficient-dependent constraints, rescaling can affect the fitted result unless the penalty, prior, or constraint is transformed too. Thus the simple prediction-invariance argument applies directly to equivalent unpenalized model parameterizations, not automatically to every estimation procedure.

Key takeaway: Coding and scaling are not cosmetic once coefficients are used operationally. A reversible transformation with consistently transformed coefficients preserves the model’s predictions; an inconsistent conversion, redundant coding, or changed set of model terms may not.

Check Your Understanding

Answer each question, then compare with the brief solutions below.

  1. A four-category baseline variable is entered in a model with an intercept. How many reference-coded indicators are needed, and why not four?
  2. A linear predictor is \(2+3x\). Write an equivalent predictor using \(z=(x-4)/2\).
  3. In a binary indicator model, what does the intercept represent when the indicator is coded 0 for the reference category and 1 for the other category?
  4. Why might predictions change if a continuous covariate is centered but its original coefficient is left unchanged?
  5. Name one reason scaling may not preserve fitted results in a penalized model, even when it is a reversible covariate transformation.

Solutions. (1) Three indicators are needed: the fourth category is represented by all three being 0, and four indicators plus an intercept are linearly dependent because the indicators sum to 1. (2) Since \(x=4+2z\), \(2+3x=2+3(4+2z)=14+6z\). (3) It is the model’s predicted value on its linear-predictor scale for the reference category, at the specified values of other covariates. (4) Centering changes the covariate values; the intercept and slope must also be transformed to preserve the original linear predictor. (5) A penalty that depends on coefficient magnitudes may change under rescaling unless the penalty is transformed to match the new coefficient scale.

Clinical Biostats