From a Biological Question to a Contrast
A fitted gene-wise linear model describes expression through model coefficients, but a biological question is usually phrased in terms of group means. It may ask whether expression is higher in one condition than another, or whether one group differs from the average of several others. A contrast turns that question into a specified linear combination of coefficients or means. Writing the combination explicitly makes clear what is being estimated, how its units should be interpreted, and whether the study design can identify it.
Suppose that for gene \(g\), the observed expression values are collected in the vector \(y_g\), and the design matrix is \(X\). The gene-wise linear model is \(y_g=X\beta_g+\varepsilon_g\). Here \(\beta_g\) is the coefficient vector for gene \(g\). For the usual least-squares expression model, the design is treated as fixed, the model mean is correctly specified, and errors have mean zero and a common variance within that gene: \(\operatorname{E}(\varepsilon_g)=0\) and \(\operatorname{Var}(\varepsilon_g)=\sigma_g^2 I\). Independence is a standard working assumption for the errors. The estimate \(\hat{\beta}_g\) is obtained from the fitted model; if \(X\) has full column rank, it is \((X'X)^{-1}X'y_g\).
The distinction between a coefficient and a contrast matters. Under reference-group coding, a coefficient may already represent a particular difference of means. Under other codings, the same difference may require combining several coefficients. The model coding is a way to represent the fitted means; the question being asked determines the contrast.
Writing Contrasts for Group Means
First consider a model that directly represents the means of three groups as \(\beta_{g,1}=\mu_{g,1}\), \(\beta_{g,2}=\mu_{g,2}\), and \(\beta_{g,3}=\mu_{g,3}\). The expression mean in group 2 minus the mean in group 1 is \(c'\beta_g\) for \(c=(-1,1,0)'\). The order of subtraction is deliberate: a positive estimate means higher fitted expression in group 2 than group 1.
More generally, a contrast among \(K\) group means has weights \(a_1,\ldots,a_K\) with \(\sum_{k=1}^K a_k=0\). For example, \(\mu_{g,1}-(\mu_{g,2}+\mu_{g,3}+\mu_{g,4})/3\) has weights \(1,-1/3,-1/3,-1/3\). Their sum is zero, and the contrast compares group 1 with the equally weighted average of the other three means. These weights are not determined by the sample sizes: they encode the scientific comparison.
For a general design matrix, write the intended quantity in the model's coefficient coordinates. With reference-group coding for three groups, \(\beta_{g,0}\) may be the reference mean, while \(\beta_{g,1}\) and \(\beta_{g,2}\) are differences from that mean. Then the difference between group 2 and group 3 is \(\beta_{g,1}-\beta_{g,2}\), not either coefficient alone. Its contrast vector is \((0,1,-1)'\) in the coefficient order \((\beta_{g,0},\beta_{g,1},\beta_{g,2})\).
Worked Example: Treatment Versus Control in a Three-Group Model
All values in this example are hypothetical. For one gene, a cell-means model has fitted log2 expression means of 6.2 in control, 7.0 in treatment A, and 6.5 in treatment B. The group sample sizes are 4, 5, and 4, respectively, and the fitted gene-wise residual variance is \(s_g^2=0.36\) log2-expression-units squared. The model assumes independent errors with a common variance within this gene; these conditions are being used for the calculation.
For treatment A minus control, use \(c=(-1,1,0)'\). The estimate is \(c'\hat{\beta}_g=(-1)(6.2)+(1)(7.0)+(0)(6.5)=0.8\) log2 expression units. Thus the fitted mean is 0.8 log2 units higher for treatment A than for control.
In a cell-means model with independent groups, the variance of a group mean estimate is \(\sigma_g^2/n_k\), and different group mean estimates have covariance zero. Therefore the estimated variance of this difference is \(s_g^2(1/4+1/5)=0.36(0.45)=0.162\). The standard error is \(\sqrt{0.162}=0.4025\) log2 expression units. The estimate and its standard error describe the same contrast; the estimate alone does not establish that the difference is statistically distinguishable from zero.
Estimability and Standard Errors
A requested contrast must be supported by the design. If \(X\) has full column rank, every coefficient combination \(c'\beta_g\) is estimable. If the design is rank deficient, some coefficient vectors are not uniquely determined by the fitted mean \(X\beta_g\). In that case, \(c'\beta_g\) is estimable exactly when \(c\) lies in the row space of \(X\). Equivalently, every vector \(v\) satisfying \(Xv=0\) must also satisfy \(c'v=0\). This condition ensures that different coefficient vectors producing the same fitted means also produce the same requested contrast.
When \(X\) has full column rank and errors have covariance \(\sigma_g^2 I\), the least-squares coefficient covariance is \(\sigma_g^2(X'X)^{-1}\). Replacing the unknown variance by the fitted gene-wise residual variance gives the estimated standard error of the contrast:
This expression follows directly from the variance of a linear transformation. Since \(c'\hat{\beta}_g\) is a scalar linear combination of the coefficient estimates, \(\operatorname{Var}(c'\hat{\beta}_g)=\operatorname{Var}(c'\hat{\beta}_g)\) can be expanded as \(c'\operatorname{Var}(\hat{\beta}_g)c\). Substituting \(\operatorname{Var}(\hat{\beta}_g)=\sigma_g^2(X'X)^{-1}\) gives \(\sigma_g^2c'(X'X)^{-1}c\). Taking the square root after replacing \(\sigma_g^2\) by \(s_g^2\) yields the stated standard error.
For a cell-means model with independent groups, the same result simplifies. If group \(k\) has \(n_k\) observations and the contrast weights are \(a_k\), then \(\widehat{\operatorname{Var}}(\sum_k a_k\hat{\mu}_{g,k})=s_g^2\sum_k a_k^2/n_k\). The squared weights appear because variances scale by the square of a multiplier. This is why the standard error for a difference depends on both group sizes and the gene-wise residual variance.
Worked Example: A Group Compared With the Average of Three Groups
All numbers are hypothetical. A four-group cell-means model gives fitted log2 expression means \(8.1, 7.5, 7.2,\) and \(6.9\). The sample sizes are \(6,3,4,\) and \(5\), and the fitted gene-wise residual variance is \(s_g^2=0.25\) log2-expression-units squared. Assume independent observations and a common within-gene error variance, as required for this standard error calculation.
The question is whether group 1 differs from the equally weighted average of groups 2, 3, and 4. The weights are \(c=(1,-1/3,-1/3,-1/3)'\), which sum to zero. The estimated contrast is \(8.1-(7.5+7.2+6.9)/3=8.1-7.2=0.9\) log2 expression units.
For the standard error, square each weight and divide by its group's sample size:
The estimate is 0.9 log2 units above the specified average, with estimated standard error about 0.2518 log2 units. The comparison gives each of groups 2, 3, and 4 equal weight even though their sample sizes differ. Sample sizes affect precision, not the definition of the average being compared.
Worked Example: Detecting a Nonestimable Treatment Effect
All data here are hypothetical. Suppose the only control samples were measured in batch A and the only treated samples in batch B. With an intercept, treatment indicator, and batch-B indicator, the design matrix has rows of the form \((1,0,0)\) for controls and \((1,1,1)\) for treated samples. The treatment and batch columns are identical. The model can describe a difference between the observed groups, but it cannot separate a treatment effect from a batch effect.
The coefficient vector is ordered as \((\beta_{g,0},\beta_{g,T},\beta_{g,B})'\). The desired treatment effect adjusted for batch would use \(c=(0,1,0)'\). But \(v=(0,1,-1)'\) satisfies \(Xv=0\), while \(c'v=1\ne0\). Thus \(c\) is not in the row space of \(X\), so the adjusted treatment effect is not estimable. Reporting a standard error for that coefficient combination would not repair the lack of identification.
By contrast, \(c=(0,1,1)'\) satisfies \(c'v=0\). It represents the combined shift associated with the treatment and batch indicators, which is estimable from these data. That combined shift is not, however, the treatment effect alone. The distinction is substantive: a quantity can be mathematically estimable but fail to answer the scientific question of interest.
Practical Checks and Common Pitfalls
Before interpreting a gene-wise contrast, verify that the vector's coefficient order matches the fitted design, that the signs reflect the intended subtraction, and that the weights define the desired comparison. Then check estimability and calculate the standard error from the same fitted model and contrast. If the estimated variance is unusually large, inspect the group sample sizes and the design matrix: sparse groups, near-confounding, or redundant columns can make a contrast imprecise or nonestimable.
A contrast is not automatically a causal effect. It is a comparison of modeled expression means; causal interpretation requires a design and assumptions that justify it. Likewise, a small standard error does not establish that the model is correctly specified. Plot residuals and fitted values where appropriate, and examine whether the design has the intended observations in each group. These checks can reveal outliers, variance patterns, or confounding that undermine the working model.
A common mistake is to use the sample-size-weighted average of comparison groups when the scientific question asks for their equal-weighted average. Another is to treat a reference-coded coefficient as the only possible group comparison. The correction is to write the estimand in words, translate those words into explicit weights, and then express those weights in the model's coefficient coordinates. Pairwise comparisons are useful when each pair is of interest, but they do not replace a specified multi-group contrast. An omnibus test addresses whether a collection of effects is jointly zero; it does not, by itself, report the particular direction and magnitude captured by one contrast.
Multiplying every contrast weight by a nonzero constant also multiplies the estimate and standard error by that constant's absolute value. The underlying comparison is the same up to scale, but its reported magnitude and units change. For interpretability, use weights that directly match the question, such as a difference in means or a difference from an average.
Check Your Understanding
For each question, identify the relevant contrast or calculation. Solutions are included after the questions.
- In a three-group cell-means model ordered as control, low dose, high dose, write the contrast for high dose minus low dose.
- For group means \((5.0, 5.6, 4.8)\), what is the estimate for the contrast \((0,1,-1)'\)?
- A contrast compares group 1 with the equally weighted average of groups 2 and 3. Write its weights and verify they sum to zero.
- Why is a treatment effect not separately estimable when the treatment indicator equals the batch indicator for every sample?
Solutions. (1) The vector is \((0,-1,1)'\), because it subtracts the low-dose mean from the high-dose mean. (2) The estimate is \(5.6-4.8=0.8\) expression units. (3) The weights are \((1,-1/2,-1/2)'\); their sum is \(1-1/2-1/2=0\). (4) Treatment and batch have identical columns, so the data cannot distinguish their contributions to the fitted means. The adjusted treatment-only coefficient is therefore not estimable from that design.