Tutorials › High-Dimensional Genomic Data Analysis › Coding Covariates In A GWAS Model

Single-Variant GWAS · Tutorial 222 of 795

Coding Covariates In A GWAS Model

Build regression design matrices for GWAS covariates and interpret an adjusted SNP coefficient in context.

Intermediate 12 min read

What You'll Learn

  • Code a categorical covariate with indicators and a clearly stated reference level.
  • Represent continuous covariates in linear and logistic single-variant models.
  • Interpret an SNP coefficient while holding the included covariates fixed.
  • Understand how changing a reference level or centering a covariate changes coefficient labels.
  • Check model assumptions, design-matrix rank, and common coding pitfalls.

Why Covariate Coding Matters

A single-variant association model relates a phenotype to a genotype measure while allowing other measured characteristics to enter the model. Those additional predictors are covariates. Their coding determines what comparisons the fitted coefficients describe: for a categorical covariate, it determines the reference group; for a continuous covariate, it sets the units of its slope. Correct coding makes the adjusted SNP effect interpretable without changing the basic question: what is the association between genotype and phenotype among individuals with the same modeled covariate values?

Let \(G_i\) denote the genotype value for individual \(i\), coded as allele dosage \(0,1,\) or \(2\), and let \(Y_i\) be a quantitative phenotype. Other genotype codings, such as genotype indicators, can be used when that is the specified genetic model. Let \(Z_i\) collect covariates, such as age, sex, study site, or ancestry variables. The SNP coefficient describes an adjusted association only under the fitted model; adjustment by itself does not establish a causal effect.

Definition: A covariate is a predictor included in a regression model in addition to the SNP predictor of interest. A SNP effect is adjusted for the included covariates when its coefficient is estimated in a model that also includes those covariates. In an additive model without SNP-by-covariate interaction, the SNP coefficient describes the modeled change in outcome for a one-unit increase in \(G_i\), comparing individuals with the same values of the included covariates.

Continuous and Categorical Covariates

A quantitative covariate, such as age in years, usually enters as a numerical predictor. Its coefficient represents the modeled change in outcome per one-unit increase in that covariate, conditional on the other predictors. It is important to record units: a coefficient per year is numerically different from one per decade. Centering a continuous covariate can make the intercept easier to interpret. For example, \(A_i-50\) expresses age relative to 50 years. If the model contains no interaction involving age, centering changes the intercept but not the fitted values or the SNP coefficient.

A categorical covariate with \(K\) levels is represented by \(K-1\) indicator variables when the model includes an intercept. One level is selected as the reference. Each indicator is 1 for its named level and 0 otherwise; the coefficient for a level is its modeled contrast with the reference level, holding the other predictors fixed. The reference is a coding choice, not a claim that the group is biologically special.

For example, for study site \(S_i\) with levels A, B, and C, take A as reference and define \(I(B_i)=1\) for site B and 0 otherwise, and \(I(C_i)=1\) for site C and 0 otherwise. An individual at A has both indicators 0; an individual at B has values 1 and 0; an individual at C has values 0 and 1. Including an intercept and all three site indicators would make the columns linearly dependent, so their coefficients could not be uniquely estimated.

Worked Example: Coding a Three-Level Covariate

Suppose a hypothetical GWAS includes individuals recruited at sites A, B, and C. With site A as the reference, code the site indicators and write the corresponding model terms.

For A, the pair \((I(B_i), I(C_i))\) is \((0,0)\); for B it is \((1,0)\); and for C it is \((0,1)\). If the site terms in a linear model are \(\gamma_B I(B_i)+\gamma_C I(C_i)\), the fitted site contribution is 0 at A, \(\gamma_B\) at B, and \(\gamma_C\) at C.

For hypothetical estimates \(\hat{\gamma}_B=1.2\) phenotype units and \(\hat{\gamma}_C=-0.5\) phenotype units, the modeled contrasts relative to site A are 1.2 units for B and -0.5 units for C, conditional on the other modeled predictors. The B-versus-C contrast is \(1.2-(-0.5)=1.7\) phenotype units. These are adjusted model contrasts, not evidence that site itself caused the differences.

Linear and Logistic Model Forms

For a quantitative phenotype, a single-variant linear regression with continuous covariates \(Z_{ij}\) and categorical-covariate indicators can be written as

$$ Y_i=\beta_0+\beta_G G_i+\sum_{j=1}^{q}\beta_j Z_{ij} +\sum_{k=1}^{K-1}\gamma_k I_{ik}+\varepsilon_i. $$

Here \(\beta_0\) is the intercept, \(\beta_G\) is the SNP coefficient, and each \(I_{ik}\) is an indicator for a non-reference category. Under this additive specification, \(\beta_G\) is the modeled difference in mean phenotype for a one-unit increase in genotype dosage, conditional on the included covariates. For dosage coding, one unit corresponds to one additional copy of the coded allele. The error assumptions for the usual linear-model standard errors include independent errors with mean zero and constant variance conditional on the predictors; the conditional mean must also be adequately represented by the chosen linear predictor. A coefficient can still be estimated when some standard-error assumptions fail, but conventional inference may not be reliable.

For a binary outcome \(Y_i\in\{0,1\}\), the corresponding logistic regression uses the same predictor coding but models the conditional probability \(p_i=P(Y_i=1\mid G_i,Z_i)\):

$$ \log\!\left(\frac{p_i}{1-p_i}\right) =\beta_0+\beta_G G_i+\sum_{j=1}^{q}\beta_j Z_{ij} +\sum_{k=1}^{K-1}\gamma_k I_{ik}. $$

This model assumes independent binary outcomes conditional on the predictors, a correctly specified linear predictor for the log odds, and estimable coefficients (in particular, no perfect separation). In this additive model, \(\beta_G\) is the change in conditional log odds for a one-unit increase in dosage, holding the covariates fixed. The indicator coding and reference-level interpretation are the same as in linear regression, although the outcome scale differs.

Worked Example: A Continuous Covariate in a Linear Model

Consider hypothetical quantitative-phenotype data modeled by dosage \(G_i\) and centered age \(C_i=A_i-50\), where \(A_i\) is age in years. There are two observations in each of four genotype-by-age groups. Their phenotype values are: \(G=0,C=-10\): 1 and 3; \(G=0,C=10\): 7 and 9; \(G=1,C=-10\): 3 and 5; \(G=1,C=10\): 9 and 11.

The four group means are \(2,8,4,\) and \(10\), respectively. The genotype contrast at \(C=-10\) is \(4-2=2\) phenotype units per dosage, and at \(C=10\) it is \(10-8=2\). The age contrast over 20 years is \(8-2=6\) units for \(G=0\), so the fitted age slope is \(6/20=0.3\) units per year. The same slope appears for \(G=1\): \((10-4)/20=0.3\).

Thus the fitted additive model is \(\hat{Y}_i=5+2G_i+0.3C_i\). The intercept is 5 phenotype units at dosage 0 and age 50. At a fixed age, one additional allele dosage is associated with a modeled increase of 2 phenotype units. The two observations in each cell differ by 2 in opposite directions around their cell mean, so their residuals sum to zero; the balanced design also lets the stated contrasts identify the model coefficients. This example illustrates coefficient coding and arithmetic, not a claim about real data.

What “Adjusted” Means in the Model

The SNP coefficient is estimated jointly with the covariate coefficients. In a linear model, least squares chooses coefficients to minimize the sum of squared differences between observed and fitted outcomes. In a logistic model, the coefficients are estimated from the binary-outcome likelihood. In either case, adjustment means that the fitted SNP association is conditional on the covariate terms as represented in the model. It does not mean that every possible source of group difference has been controlled.

The role of coding can be seen from the design matrix, whose columns contain the intercept, genotype, and coded covariates. If a category is represented by an indicator, the corresponding coefficient is a contrast against the reference category. If a continuous covariate is rescaled, its coefficient changes to match the new unit. The fitted model and SNP coefficient are unchanged by a change of reference level for a categorical covariate, provided the model spans the same set of fitted values.

Justification: For a two-level covariate with indicator \(D_i\), the terms \(\beta_0+\gamma D_i\) give intercept \(\beta_0\) in the reference group \(D_i=0\), and intercept \(\beta_0+\gamma\) in the other group \(D_i=1\). If the second group becomes the reference, write \(D_i'=1-D_i\). Then \(\beta_0+\gamma D_i=(\beta_0+\gamma)-\gamma D_i'\). The same fitted values result, with a shifted intercept and a reversed group contrast. If the SNP term \(\beta_G G_i\) remains in both models and there is no interaction, its coefficient is unchanged.

Worked Example: Reading an Adjusted Logistic Model

Suppose a hypothetical case-control analysis uses dosage \(G_i\), age centered at 50 years \(C_i=A_i-50\), and a site indicator \(D_i\) equal to 1 for site B and 0 for reference site A. Assume a fitted model has coefficients \(\hat{\beta}_0=-2.0\), \(\hat{\beta}_G=0.40\), \(\hat{\beta}_{age}=0.030\) per year, and \(\hat{\gamma}_B=-0.50\).

For an individual with dosage 1, age 60 years (\(C_i=10\)), and site B (\(D_i=1\)), the fitted log odds are

$$ \hat{\eta}_i=-2.0+0.40(1)+0.030(10)-0.50(1)=-1.80. $$

The fitted probability is \(1/(1+\exp(1.80))\approx0.1419\), or about 14.2%. At the same age and site, increasing dosage from 1 to 2 adds \(0.40\) to the fitted log odds. This interpretation is conditional on the model's covariates and assumes no SNP-by-age or SNP-by-site interaction. It does not assert that the same probability difference occurs at every baseline risk.

Checking the Coding and Its Limits

Before interpreting a fitted SNP coefficient, verify that the design matrix represents the intended comparisons and that the model is estimable. A full-rank design matrix is needed for unique ordinary regression coefficients. Exact redundancy can arise from including an intercept with indicators for every category, or from a covariate that is a perfect linear combination of other columns. Sparse categories may also make estimates unstable even when the matrix is technically full rank.

Check whether continuous covariates are entered in appropriate units and whether a straight-line effect is a reasonable working specification on the modeled scale. In logistic regression, this concerns linearity in log odds, not necessarily linearity in probability. Inspect category counts and missingness, and confirm that the reference level and allele dosage direction match the intended analysis. For a logistic fit, warnings, very large coefficient estimates, or fitted probabilities extremely close to zero or one can signal separation or sparse data. For a linear fit, residual patterns can reveal lack of fit or unequal variability; the later interpretation of standard errors also depends on the error assumptions.

Coding choices are not substitutes for model choices. A continuous covariate entered as a single linear term imposes a particular shape; indicators for categories impose group-specific offsets relative to a reference. If scientifically justified, nonlinear terms or interactions may be needed, but they change the meaning of the SNP coefficient. In particular, with an interaction between genotype and a covariate, there is no single SNP effect shared across all covariate values: the SNP effect depends on that covariate.

ChoiceWhat its coefficient representsCommon check
Continuous covariate in original unitsModeled outcome change per one unitConfirm units and functional form
Centered continuous covariateSame slope; intercept evaluated at the centering valueState the centering value
Categorical indicatorContrast with the chosen reference levelCheck reference and indicator definitions
All category indicators plus interceptNon-unique coefficients because of redundancyOmit one reference indicator

Common Pitfalls

  • Using every category indicator with an intercept. This creates exact redundancy. Omit one indicator and state its category as the reference.
  • Calling a coefficient “adjusted” without naming the covariates. State which predictors are included and describe the SNP contrast conditional on them.
  • Forgetting units or centering. A slope per year is not a slope per decade, and a centered-age intercept is evaluated at the centering age.
  • Interpreting a logistic coefficient as a probability difference. It is a change in log odds; the corresponding probability change depends on the starting probability.
  • Assuming adjustment guarantees an unbiased or causal SNP effect. The coefficient is conditional on the specified model and measured covariates, not automatically on every relevant factor.

The main alternatives in coding categorical predictors are different choices of reference level or equivalent contrast systems. These alter coefficient labels and interpretations but, when they represent the same model space, not fitted values or the SNP coefficient in an additive model. For continuous predictors, changing units or centering changes coefficient scale or the intercept but not fitted values. Choosing a different functional form or adding interactions is a substantive model change, not merely a recoding.

Check Your Understanding

Try each question, then compare your reasoning with the brief solutions.

  1. A covariate has levels North, South, and West. With North as reference, what indicators are needed, and what does the South coefficient compare?
  2. A model uses age in decades rather than years. If the age slope is 0.6 phenotype units per decade, what is the corresponding slope per year?
  3. Why can an intercept and indicators for all four levels of a categorical covariate not be included as separate columns?
  4. In an additive logistic model, what does the SNP dosage coefficient describe, and what additional feature would make the SNP effect vary by age?
  5. What changes, and what does not, when a continuous covariate is centered but no interaction involving it is included?

Solutions. (1) Use indicators for South and West; the South coefficient is the modeled South-versus-North contrast, conditional on other predictors. (2) \(0.6/10=0.06\) phenotype units per year. (3) The four indicators sum to the intercept column, so the design is rank-deficient; omit one reference indicator. (4) It is the change in conditional log odds per one-unit dosage increase at fixed modeled covariates; a SNP-by-age interaction makes that effect depend on age. (5) The intercept shifts to the covariate's centering value, while fitted values and the covariate slope and SNP coefficient remain unchanged.

Clinical Biostats