Why Coding Choices Matter
A genotype and an exposure do not enter a regression model as abstract labels: each must be represented by numerical variables. The representation determines which groups are compared directly, what a coefficient means, and which patterns the model allows. A model can therefore be technically fit but answer a different question from the one intended if its coding is not made explicit.
For example, coding genotypes as 0, 1, and 2 treats each additional copy of an allele as the same-sized step. Coding the same three genotypes with indicator variables instead allows separate comparisons of each genotype with a chosen reference group. Neither encoding is automatically correct for every analysis. The choice should match the scientific contrast of interest and the assumptions the analyst is prepared to make.
In the equations below, let \(G\) denote genotype, with values 0, 1, and 2 for the number of copies of a specified allele, and let \(E\) denote an exposure. Let \(Y\) be a quantitative outcome. We focus on how to encode \(G\) and \(E\), and on the contrasts represented by the resulting coefficients.
Four Common Genotype Codings
For a biallelic variant, suppose \(G=0\), \(G=1\), and \(G=2\) correspond to zero, one, or two copies of the allele being counted. The labels must be stated: counting the other allele reverses the ordering. Three commonly used one-degree-of-freedom codings and a categorical coding are shown below.
| Coding | Model variable(s) | Directly represented comparison |
|---|---|---|
| Allele-count (additive) | \(G=0,1,2\) | Change in the modeled mean per additional counted allele |
| Dominant | \(D_{\mathrm{dom}}=I(G\geq 1)\) | Any carrier versus noncarrier |
| Recessive | \(D_{\mathrm{rec}}=I(G=2)\) | Two copies versus zero or one copy |
| Categorical | \(D_1=I(G=1),\ D_2=I(G=2)\) | Each nonreference genotype versus the chosen reference genotype |
Here \(I(\cdot)\) equals 1 when its condition is true and 0 otherwise. In the allele-count model, a single coefficient imposes a linear trend across the three genotype values: the modeled difference from \(G=0\) to \(G=1\) is the same as the modeled difference from \(G=1\) to \(G=2\). The label “additive” in this coding describes the allele-count scale. By itself, it does not mean that an outcome effect is additive on every other scale.
Dominant and recessive coding each combine two genotype groups. They therefore impose equality of the modeled means within the combined groups, apart from other terms in the model. Categorical coding does not impose an ordered trend: with \(G=0\) as reference, it estimates separate \(G=1\) versus \(G=0\) and \(G=2\) versus \(G=0\) contrasts. For three genotype categories, this uses two indicator variables rather than one.
Worked Example: Comparing Genotype Codings
Suppose a hypothetical study has the same number of participants in each genotype group, and the observed outcome means at a fixed exposure level are 10, 12, and 17 units for \(G=0,1,2\), respectively. Compare the contrasts implied by the four genotype codings. For the allele-count fit, use ordinary least squares with an intercept and \(G\).
Allele-count coding. With equal group sizes, the regression slope from the three group means is the covariance of genotype and outcome means divided by the variance of genotype. The mean genotype is 1 and the mean outcome is 13, so
The fitted intercept is \(13-(3.5)(1)=9.5\) units. The model therefore predicts 9.5, 13.0, and 16.5 units for \(G=0,1,2\). These are not the observed means at the two endpoints: the one-slope coding summarizes a linear trend rather than reproducing all three group means.
Dominant coding. The noncarrier group has mean 10 units. With equal numbers in the \(G=1\) and \(G=2\) groups, the carrier mean is \((12+17)/2=14.5\) units. The dominant contrast is therefore \(14.5-10=4.5\) units: any carrier versus noncarrier.
Recessive coding. The \(G=2\) mean is 17 units. The combined \(G=0\) and \(G=1\) mean is \((10+12)/2=11\) units, so the recessive contrast is \(17-11=6\) units: two copies versus zero or one copy.
Categorical coding. Taking \(G=0\) as reference gives the separate contrasts \(12-10=2\) units for \(G=1\) versus \(G=0\), and \(17-10=7\) units for \(G=2\) versus \(G=0\). These comparisons do not require the equal-step trend imposed by allele-count coding. The calculations presume equal group sizes; with unequal sizes, pooled group means and fitted coefficients depend on the observed group counts and the specified model.
Binary Exposure Coding and Reference Groups
For a binary exposure, one common coding sets \(E=0\) for unexposed and \(E=1\) for exposed. In a model containing an intercept, the unexposed group is the exposure reference. Reversing the codes makes the exposed group the reference. The observed data have not changed, but coefficient values and their direct comparisons have.
For illustration, consider a categorical genotype model with \(G=0\) as the genotype reference. Define \(D_1=I(G=1)\) and \(D_2=I(G=2)\). A model with a binary exposure and genotype-by-exposure terms can be written as follows. The error term represents variation around the conditional mean.
Under this coding, \(\beta_0\) is the modeled mean for \(G=0,E=0\). The terms \(\beta_1\) and \(\beta_2\) compare \(G=1\) and \(G=2\), respectively, with \(G=0\) when \(E=0\). The coefficient \(\beta_E\) compares \(E=1\) with \(E=0\) within the reference genotype \(G=0\). The remaining coefficients describe how those genotype comparisons change between the two exposure values. Their exact contrasts follow from the coding and model, not just from the names of the coefficients.
Worked Example: Reading Binary-Exposure Contrasts
Suppose hypothetical cell means, in outcome units, are as follows. Assume equal sample sizes in all six cells, and fit the categorical-genotype model above with no additional covariates.
| Genotype | Unexposed (\(E=0\)) | Exposed (\(E=1\)) |
|---|---|---|
| \(G=0\) | 10 | 13 |
| \(G=1\) | 12 | 17 |
| \(G=2\) | 16 | 18 |
This model has a separate parameter for each of the six cell means, so it reproduces the listed means. At \(G=0,E=0\), the model gives \(\hat{\beta}_0=10\). At \(E=0\), the \(G=1\) versus \(G=0\) contrast is \(12-10=2\), so \(\hat{\beta}_1=2\); the corresponding \(G=2\) versus \(G=0\) contrast is \(16-10=6\), so \(\hat{\beta}_2=6\).
Within the reference genotype, the exposure contrast is \(13-10=3\), so \(\hat{\beta}_E=3\). For \(G=1\), the exposure contrast is \(17-12=5\). The coefficient for the \(G=1\)-by-exposure term is the difference between that contrast and the reference-genotype exposure contrast: \(\hat{\beta}_{1E}=5-3=2\). For \(G=2\), the exposure contrast is \(18-16=2\), giving \(\hat{\beta}_{2E}=2-3=-1\).
These calculations identify what each coefficient compares under the stated coding. If instead the exposure were coded \(E'=1-E\), the exposed group would become the exposure reference. The model would then use a different intercept and different direct reference contrasts, while representing the same six cell means. Always report which exposure value is coded zero.
Continuous Exposure Coding
A continuous exposure is usually retained as a numerical variable when the intended model assumes a linear relationship over the range being analyzed. If \(E\) is measured in a stated unit, its coefficient is a change in the modeled outcome per one-unit increase in \(E\), conditional on the other model terms. This coding does not divide participants into exposed and unexposed groups.
Centering replaces \(E\) with \(E_c=E-c\), where \(c\) is a chosen value, often a scientifically meaningful exposure level or the sample mean. In a model with an intercept, the intercept then corresponds to \(E=c\). Centering changes the point at which genotype reference contrasts are stated, but it does not change the unit of exposure or the fitted linear trends. Rescaling, such as replacing years with decades, changes the numerical size and units of the exposure coefficient.
For categorical genotype coding and a continuous exposure, a useful model is
Here \(\beta_0\) is the modeled mean for \(G=0\) at \(E=c\). The coefficients \(\beta_1\) and \(\beta_2\) compare the other genotypes with \(G=0\) at that exposure value. The coefficient \(\beta_E\) is the modeled exposure slope for \(G=0\), in outcome units per exposure unit. The interaction terms encode differences between genotype-specific exposure slopes and the reference-genotype slope. With an allele-count variable instead of \(D_1,D_2\), the model imposes a more restricted pattern across genotype values.
Worked Example: Centering a Continuous Exposure
Consider hypothetical conditional mean relationships for a quantitative outcome, where \(E\) is an exposure measured in units of dose per day:
Fit the categorical-genotype form using \(E_c=E-4\). The reference exposure is thus \(E=4\) dose units per day. Substituting \(E=4\) into each relationship gives means of \(50+2(4)=58\), \(53+3(4)=65\), and \(56+5(4)=76\) outcome units. Therefore, with \(G=0\) as the reference, the intercept is 58, the \(G=1\) contrast at \(E=4\) is \(65-58=7\), and the \(G=2\) contrast at \(E=4\) is \(76-58=18\) units.
The exposure slopes are 2, 3, and 5 outcome units per dose unit per day for \(G=0,1,2\), respectively. Relative to \(G=0\), the slope differences are \(3-2=1\) and \(5-2=3\) outcome units per dose unit per day. Thus the centered model has intercept and genotype contrasts defined at \(E=4\), while retaining these genotype-specific slopes. If the same model were written with uncentered \(E\), its intercept and genotype contrasts would instead refer to \(E=0\); the slopes would remain the same.
Choosing and Reporting a Coding
The appropriate coding depends on the scientific comparison and the structure one is willing to impose. Allele-count coding is compact and can be useful when a linear per-allele pattern is a reasonable working assumption. Dominant and recessive codings answer specific carrier-status or two-copy comparisons, respectively, but combine genotypes that categorical coding keeps distinct. Categorical coding is more flexible for three genotype groups, at the cost of estimating more parameters.
For a continuous exposure, retain its quantitative scale when a linear exposure pattern is a reasonable model over the relevant range. If exposure categories are scientifically motivated, state the cut points and the reference category. Dichotomizing a continuous measure solely for convenience changes the question and discards within-category distinctions. Centering can make reference contrasts more meaningful; it does not itself make a nonlinear relationship linear.
Before fitting or interpreting a model, state the allele being counted, the genotype coding, the exposure coding and units, and the reference values. For example: “Genotype was coded as the number of copies of allele A; exposure was measured in dose units per day and centered at 4; genotype 0 was the reference.” This information makes the model’s contrasts reproducible and interpretable.
Model Conditions and a Common Pitfall
The worked regression examples use conditional mean models. For ordinary least squares coefficient estimates to represent the stated modeled contrasts, the mean function must be specified as written and the relevant design columns must be estimable from the data. Exact conventional small-sample inference additionally relies on assumptions such as independent errors with mean zero and constant variance; normally distributed errors give the usual exact \(t\)- and \(F\)-based results under the linear model. The examples calculate coding contrasts from means and do not claim statistical significance.
Sparse genotype-by-exposure cells can make some contrasts imprecise or inestimable. For instance, if no participants have \(G=2,E=1\), a model that requires that cell mean cannot estimate it from the data without additional assumptions. Coding choices cannot create information that is absent. Analysts should check that the groups and exposure ranges needed for their intended contrasts are represented.
- Mistake: “The allele-count coefficient is simply the difference between \(G=2\) and \(G=0\).” Correction: It is a fitted per-allele slope under the linear trend constraint; twice that slope equals the model-implied \(G=2\) versus \(G=0\) difference, not necessarily the observed difference when the trend does not fit.
- Mistake: “The genotype main-effect coefficient is a genotype comparison for everyone.” Correction: In a model with genotype-by-exposure terms, it is a comparison at the exposure reference value—zero for uncentered exposure, or the centering value for centered exposure.
- Mistake: “Changing the 0 and 1 labels changes the data or underlying group means.” Correction: It changes the parameterization and direct reference contrasts. State the coding before interpreting coefficients.
- Mistake: “Dominant and recessive coding are just alternative labels for categorical coding.” Correction: They combine genotype categories and impose equality within the combined groups; categorical coding can estimate separate means for all three genotypes.
Check Your Understanding
For each question, identify the coding or reference contrast involved.
- With \(G=0,1,2\) as a numerical allele count, what pattern across genotype means does a one-slope model impose?
- If \(D_{\mathrm{dom}}=I(G\geq1)\), which two genotype groups are compared?
- In a categorical-genotype model with \(G=0\) as reference and a binary exposure coded 0 for unexposed, what does the genotype-1 main-effect coefficient compare?
- A continuous exposure is centered at 6 units. At what exposure value are the intercept and genotype contrasts defined?
- Why can a categorical genotype model represent a pattern that an allele-count model cannot?