Tutorials › High-Dimensional Genomic Data Analysis › Design Matrices for Group Comparisons

Linear Models for Expression Microarrays · Tutorial 387 of 795

Design Matrices for Group Comparisons

Build and check indicator-coded design matrices, then translate their fitted coefficients into expression levels and group differences.

Intermediate 10 min read

What You'll Learn

  • Represent each sample’s group membership with a row of a design matrix.
  • Interpret the intercept and indicator coefficients under reference-group coding.
  • Construct multi-group matrices and read their coefficients in context.
  • Recognize full-rank requirements and common coding failures.
  • Compare reference-group coding with cell-means coding.

Why the Design Matrix Matters

In a gene-wise linear model, the observed expression values for one gene are related to a set of sample-level predictors through a design matrix. For a group comparison, that matrix records which experimental group each sample belongs to. Its columns determine how the fitted model describes group expression, so the same group means can have different coefficient interpretations under different codings.

Here, \(y_g\) is the vector of expression measurements for gene \(g\), one entry per array, \(X\) is the design matrix, and \(\beta_g\) is the vector of gene-specific coefficients. A standard model is \(y_g=X\beta_g+\varepsilon_g\). The entries of \(y_g\) are typically on a log-expression scale. The coding of \(X\), not a change in the observed data, determines what each element of \(\beta_g\) means.

Definition: A design matrix \(X\) is a numerical matrix whose rows correspond to samples and whose columns encode predictors in a linear model. In indicator coding, a column takes value 1 when a sample belongs to a specified group and 0 otherwise. A model is identifiable from its design when the columns of \(X\) are linearly independent, so \(X\) has full column rank.

For the group-mean interpretation, suppose the model’s conditional mean is correctly specified, errors have mean zero given the design, and the design has full column rank. For conventional model-based inference, the usual additional assumptions are independent errors with common variance; normal errors are used for exact small-sample inference. These assumptions concern the observations and error distribution, not whether a particular indicator column is written correctly. A full-rank matrix permits unique coefficient estimates, but cannot by itself guarantee that the experimental design or error assumptions are appropriate.

Two Groups: Reference-Group Coding

For two groups, choose one group as the reference. Code it as 0 in an indicator column and code the other group as 1. With control as the reference and treated as the indicated group, the model for one gene is

$$ y_{ig}=\beta_{0g}+\beta_{1g}z_i+\varepsilon_{ig}, \qquad z_i= \begin{cases} 0,&\text{sample }i\text{ is control},\\ 1,&\text{sample }i\text{ is treated}. \end{cases} $$

The corresponding design matrix has an intercept column of ones and an indicator column \(z\). For a control sample, the fitted mean is \(\beta_{0g}\); for a treated sample, it is \(\beta_{0g}+\beta_{1g}\). Thus \(\beta_{0g}\) is the control-group mean in the fitted model, and \(\beta_{1g}\) is the treated-minus-control difference in fitted means. The coefficients have the same units as the response: for log-expression data, they are on the log-expression scale.

Worked Example: Two Groups With Control as the Reference

Suppose one gene has hypothetical log-expression values 5.2, 4.8, and 5.0 for three control arrays, and 6.1, 5.9, and 6.4 for three treated arrays. Using control as the reference, the design matrix is

$$ X= \begin{bmatrix} 1&0\\ 1&0\\ 1&0\\ 1&1\\ 1&1\\ 1&1 \end{bmatrix}, \qquad y_g= \begin{bmatrix} 5.2\\4.8\\5.0\\6.1\\5.9\\6.4 \end{bmatrix}. $$

The control mean is \((5.2+4.8+5.0)/3=15.0/3=5.000\). The treated mean is \((6.1+5.9+6.4)/3=18.4/3=6.133\). Because this design gives each group its own fitted mean,

$$ \hat{\beta}_{0g}=5.000, \qquad \hat{\beta}_{1g}=6.133-5.000=1.133. $$

The fitted value for a control array is 5.000, and for a treated array it is \(5.000+1.133=6.133\). In this hypothetical data, the treated group’s fitted mean is 1.133 log-expression units higher than the control group’s fitted mean. This describes a difference in observed groups under the model; it does not, by itself, establish a causal treatment effect.

The indicator’s meaning follows directly by substituting its values into the model: setting \(z_i=0\) leaves the intercept, while setting \(z_i=1\) adds the indicator coefficient. Reversing the reference group changes the coefficient interpretation and signs, but not the fitted group means. This is why a coefficient should always be read together with the coding.

More Than Two Groups

For \(K\) groups, reference-group coding uses an intercept and \(K-1\) indicator columns. If group 1 is the reference, the model is

$$ y_{ig}=\beta_{0g}+\sum_{k=2}^{K}\beta_{kg}z_{ik}+\varepsilon_{ig}, $$

where \(z_{ik}=1\) if sample \(i\) is in group \(k\), and is 0 otherwise. Each sample belongs to exactly one group. Therefore, group 1 has all indicator values zero and fitted mean \(\beta_{0g}\). Group \(k\), for \(k\ge 2\), has fitted mean \(\beta_{0g}+\beta_{kg}\). Consequently, \(\beta_{kg}\) is the fitted mean in group \(k\) minus the fitted mean in the reference group.

Worked Example: Three Groups With Group A as the Reference

Consider hypothetical log-expression values for one gene: group A has 4.8 and 5.2; group B has 5.7 and 5.9; group C has 4.9 and 5.1. With A as the reference and columns ordered as intercept, B indicator, C indicator, the design matrix and response vector are

$$ X= \begin{bmatrix} 1&0&0\\ 1&0&0\\ 1&1&0\\ 1&1&0\\ 1&0&1\\ 1&0&1 \end{bmatrix}, \qquad y_g= \begin{bmatrix} 4.8\\5.2\\5.7\\5.9\\4.9\\5.1 \end{bmatrix}. $$

The group means are \(\bar{y}_A=(4.8+5.2)/2=5.000\), \(\bar{y}_B=(5.7+5.9)/2=5.800\), and \(\bar{y}_C=(4.9+5.1)/2=5.000\). Thus the fitted coefficients under this coding are

$$ \hat{\beta}_{0g}=5.000,\qquad \hat{\beta}_{Bg}=5.800-5.000=0.800,\qquad \hat{\beta}_{Cg}=5.000-5.000=0.000. $$

The fitted group means are 5.000 for A, \(5.000+0.800=5.800\) for B, and \(5.000+0.000=5.000\) for C. The zero estimate for the C indicator means the fitted C and A means coincide in this example; it does not establish that their population means are equal.

A different, also valid, parameterization is cell-means coding: use one indicator column for every group and omit the intercept. Each coefficient is then the fitted mean for its group. For the preceding example, the columns are indicators for A, B, and C, and the fitted coefficients are 5.000, 5.800, and 5.000. The fitted values are identical to those from reference-group coding; only the coefficient meanings differ.

Worked Example: Cell-Means Coding With Unequal Group Sizes

Suppose hypothetical control values are 3.0 and 3.6, while treated values are 4.0, 4.2, and 4.4. In cell-means coding, with columns for control and treated, the design and response are

$$ X= \begin{bmatrix} 1&0\\ 1&0\\ 0&1\\ 0&1\\ 0&1 \end{bmatrix}, \qquad y_g= \begin{bmatrix} 3.0\\3.6\\4.0\\4.2\\4.4 \end{bmatrix}. $$

The control-column coefficient is the control mean: \((3.0+3.6)/2=6.6/2=3.300\). The treated-column coefficient is the treated mean: \((4.0+4.2+4.4)/3=12.6/3=4.200\). The fitted value for any control sample is 3.300, and for any treated sample it is 4.200. The unequal group sizes do not change the coefficient meanings, though they do affect the information available for estimating the group means.

Checking a Design Matrix

A correctly constructed matrix reflects the actual sample allocation and uses a consistent column order. Before fitting the gene-wise models, check that each row corresponds to the intended array, each indicator matches that array’s group, and the matrix has full column rank. If there are \(K\) groups and all are represented, the reference-coded matrix with an intercept and \(K-1\) indicators has \(K\) independent columns. In cell-means coding, all \(K\) group columns are independent when each group is represented.

A common mistake is to include an intercept and indicators for all \(K\) groups at once. Every row then has exactly one group indicator equal to 1, so the sum of the group-indicator columns equals the intercept column. The columns are linearly dependent, and the coefficients cannot be uniquely determined. Omit one indicator when using an intercept, or use all group indicators without an intercept.

Other warning signs include an indicator column that is all zero because a group has no samples, a row whose indicators assign it to multiple groups in a mutually exclusive design, or sample labels that do not match the expression matrix’s sample order. These are not cosmetic issues: they can change the fitted values or make the model unidentifiable. Inspect group counts and a few sample-to-row mappings before fitting.

What the Coefficients Do—and Do Not—Say

For a design containing only group indicators, the fitted value for each sample is its group’s sample mean. If the design has additional columns, such as a batch indicator, the group coefficient interpretation depends on that expanded model and its coding; it need not equal the raw difference between group averages. A group comparison can also be impossible to separate from batch when group and batch are perfectly confounded. In that case, the design lacks information to distinguish their effects.

Reference-group coding is useful when the scientific description naturally names a baseline group and asks how other groups differ from it. Cell-means coding is convenient when the quantities of direct interest are the group means themselves. Neither encoding is universally preferable: choose based on clear interpretation and correct model specification. The fitted values are unchanged by a valid reparameterization, but individual coefficients are not interchangeable across codings.

These models describe gene-level expression on the response scale used in the analysis. They do not resolve whether the measured arrays are independent biological replicates, whether the error variance is appropriate, or whether the evidence across thousands of genes requires multiplicity control. Those questions require attention beyond the construction and interpretation of the group design matrix.

Key takeaway: First identify the sample groups and choose an explicit coding. Then read each coefficient by substituting the indicator values for the relevant group. Under reference-group coding, the intercept is the reference mean and each indicator coefficient is a difference from that mean; under cell-means coding, each coefficient is a group mean.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. With control coded 0 and treated coded 1, what do the intercept and indicator coefficient represent?
  2. There are four groups, with group A as the reference. How many columns are in the reference-coded design, including the intercept?
  3. Why is an intercept plus one indicator for every group not full rank when each sample is in exactly one group?
  4. In cell-means coding, hypothetical group values are 2.0 and 4.0 for group A, and 3.0 and 5.0 for group B. What are the fitted coefficients?
  5. What does a zero indicator coefficient mean under reference-group coding, and what does it not establish?

Solutions. (1) The intercept is the fitted control mean, and the indicator coefficient is the fitted treated-minus-control difference. (2) Four columns: one intercept and three indicators. (3) The group-indicator columns sum to the intercept column, creating linear dependence. (4) The A coefficient is \((2.0+4.0)/2=3.0\); the B coefficient is \((3.0+5.0)/2=4.0\). (5) The fitted group mean equals the reference-group fitted mean; this alone does not establish equality of the population means.

Clinical Biostats