Tutorials › High-Dimensional Genomic Data Analysis › Paired-Subject Analysis Worked Example

Linear Models for Expression Microarrays · Tutorial 406 of 795

Paired-Subject Analysis Worked Example

Learn how pairing changes the gene-wise model, its standard error, and the interpretation of ordinary and moderated treatment tests.

Intermediate 12 min read

What You'll Learn

  • Set up a subject-adjusted model for paired log-expression measurements.
  • Derive the treatment contrast and its variance multiplier for complete pairs.
  • Calculate ordinary gene-wise standard errors and t-statistics.
  • Apply a stated empirical Bayes variance prior to obtain moderated uncertainty.
  • Check model assumptions and diagnose design or pairing errors.
  • Compare paired analysis with an unpaired two-group analysis.

Why the Pairing Must Appear in the Model

In a paired microarray experiment, each subject contributes an expression measurement under both conditions. The two measurements from a subject share biological background, so the treatment comparison should be made after accounting for that subject. Treating all arrays as unrelated observations discards the pairing and can misstate the uncertainty of the treatment effect.

Expression values below are hypothetical log-scale measurements. For gene \(g\), let \(y_{gij}\) denote the measured expression for subject \(i\) in condition \(j\), where \(j=0\) is control and \(j=1\) is treatment. A subject-adjusted model is

$$ y_{gij}=\alpha_{gi}+\beta_g x_j+\varepsilon_{gij}, \qquad x_0=0,\quad x_1=1. $$

Here \(\alpha_{gi}\) is the subject-specific baseline for gene \(g\), and \(\beta_g\) is the treatment-minus-control effect on the log-expression scale. Thus a positive \(\beta_g\) means higher expression under treatment, conditional on the subject effects. The model assumes a common treatment effect across subjects, independent errors across arrays conditional on subject, and a common residual variance for the gene. The usual gene-wise t inference also assumes normally distributed errors. The common treatment effect rules out a subject-specific treatment response in this model.

Definition: In a complete paired design with \(n\) subjects, the treatment contrast for gene \(g\) is the coefficient \(\beta_g\) in the subject-adjusted model. Its estimate is the mean of the \(n\) within-subject treatment-minus-control differences. The contrast variance multiplier is \(2/n\) when the model has a separate residual for each of the two arrays per subject and a common residual variance.

From Subject Adjustment to the Paired Contrast

Subtract the control measurement from the treatment measurement for each subject. The subject effect cancels:

$$ D_{gi}=y_{gi1}-y_{gi0} =\beta_g+(\varepsilon_{gi1}-\varepsilon_{gi0}). $$

Consequently, the least-squares estimate is \(\hat{\beta}_g=\bar{D}_g\), where \(\bar{D}_g\) is the mean of the paired differences. If the residuals in the two arrays have common variance \(\sigma_g^2\) and are independent conditional on subject, then the difference error has variance \(2\sigma_g^2\). The ordinary gene-wise residual variance from the full subject-adjusted model is half the sample variance of the differences:

$$ s_g^2=\frac{1}{2(n-1)}\sum_{i=1}^n(D_{gi}-\bar{D}_g)^2. $$

There are \(2n\) observations and \(n+1\) fitted coefficients (one subject effect per subject and one treatment effect), so \(df=2n-(n+1)=n-1\). The contrast variance multiplier is \(2/n\), giving ordinary \(SE(\hat{\beta}_g)=\sqrt{2s_g^2/n}\). This is exactly the standard error of the mean paired difference, \(\sqrt{s_{D,g}^2/n}\), because \(s_{D,g}^2=2s_g^2\). This equivalence is useful for checking the model calculations.

Worked Example: Ordinary and Moderated Inference for One Gene

Suppose four hypothetical subjects have the following treatment-minus-control log-expression differences for a gene: \(0.4,\ 0.8,\ 0.6,\ 0.8\). Assume complete pairs, independent subjects, and the subject-adjusted model above. For illustration, take the estimated cross-gene prior variance as \(s_0^2=0.0200\) with prior degrees of freedom \(d_0=4\).

The estimated treatment effect is the mean difference:

$$ \hat{\beta}_g=\bar{D}_g=\frac{0.4+0.8+0.6+0.8}{4} =\frac{2.6}{4}=0.6500. $$

The differences from their mean are \(-0.25,\ 0.15,\ -0.05,\ 0.15\). Their squared deviations sum to \(0.0625+0.0225+0.0025+0.0225=0.1100\). Thus \(s_{D,g}^2=0.1100/3=0.03667\), and the full-model residual variance is \(s_g^2=0.03667/2=0.01833\), with \(df=3\). The ordinary standard error and statistic are

$$ SE(\hat{\beta}_g)=\sqrt{\frac{2(0.01833)}{4}}=0.09574, \qquad t_g=\frac{0.6500}{0.09574}=6.789. $$

For a two-sided ordinary test at \(\alpha=0.05\), the \(t\) reference distribution has 3 degrees of freedom, with critical value about 3.182. The statistic exceeds that value. Under the stated model, the data provide evidence that the treatment changes this gene's mean log expression; the estimated change is \(0.6500\) log-expression units.

For the moderated calculation, the posterior variance estimate is the weighted average of the gene's residual variance and the prior variance, with weights given by their degrees of freedom:

$$ s_{g,\mathrm{post}}^2 =\frac{d_0s_0^2+df\,s_g^2}{d_0+df} =\frac{4(0.0200)+3(0.01833)}{7} =0.01929. $$

The moderated standard error is \(\sqrt{2(0.0192857)/4}=0.09820\), so the moderated statistic is \(0.6500/0.09820=6.619\), with \(d_0+df=7\) degrees of freedom. The 5% two-sided critical value for 7 degrees of freedom is about 2.365, so this moderated test also rejects \(H_0:\beta_g=0\). The effect estimate is unchanged; moderation changes the variance estimate and reference degrees of freedom, not the fitted treatment contrast.

Moderating Uncertainty Across Genes

Gene-wise residual variances can be unstable when each gene has only a few residual degrees of freedom. Empirical Bayes moderation adds information across genes by shrinking each variance estimate toward a shared prior estimate (or toward a fitted mean-variance trend when that model is used). In the simple common-prior calculation here, the posterior variance and moderated statistic are

$$ s_{g,\mathrm{post}}^2 =\frac{d_0s_0^2+df\,s_g^2}{d_0+df}, \qquad t_{g,\mathrm{mod}} =\frac{\hat{\beta}_g}{\sqrt{s_{g,\mathrm{post}}^2(2/n)}}. $$

The moderated t reference distribution uses \(d_0+df\) degrees of freedom. This calculation relies on the variance-prior assumptions used to obtain \(s_0^2\) and \(d_0\); in particular, the genes contribute information about a common variance distribution. The earlier material on empirical Bayes shrinkage describes the variance-prior framework. The numerical prior values in the examples are stipulated for illustration, not estimated from the few displayed genes.

Moderation does not guarantee that every standard error decreases. A gene with \(s_g^2<s_0^2\) is typically moved upward toward the prior, while a gene with \(s_g^2>s_0^2\) is moved downward. The effect estimate itself is not shrunk by this variance moderation. A mean-variance trend or robust prior fit may be appropriate when a single common variance prior is inadequate.

Worked Example: A Gene With Low Residual Variance

For a second hypothetical gene measured in the same four-pair design, suppose \(\hat{\beta}_g=0.2000\) and \(s_g^2=0.005000\), with \(df=3\). Use the same stipulated prior values \(s_0^2=0.0200\) and \(d_0=4\). The ordinary standard error is

$$ SE(\hat{\beta}_g)=\sqrt{\frac{2(0.005000)}{4}}=0.05000, \qquad t_g=\frac{0.2000}{0.05000}=4.000. $$

For ordinary inference, the 5% two-sided critical value with 3 degrees of freedom is 3.182, so the ordinary test rejects \(H_0:\beta_g=0\). The moderated variance is

$$ s_{g,\mathrm{post}}^2 =\frac{4(0.0200)+3(0.005000)}{7} =\frac{0.09500}{7}=0.01357. $$

The posterior variance is larger than this gene's raw variance because the raw estimate is below the prior estimate. The moderated standard error is \(\sqrt{2(0.0135714)/4}=0.08237\), and \(t_{g,\mathrm{mod}}=0.2000/0.08237=2.428\) with 7 degrees of freedom. Since 2.428 is just above the 5% two-sided critical value of about 2.365, the moderated test rejects at that level, but the evidence is much less compelling than the ordinary statistic alone would suggest. This example shows why moderation is not synonymous with making every gene appear more significant.

Checking the Pairing and the Design

1
Verify the experimental unit.
Each subject must have measurements in both conditions for the complete-pair calculation. Match arrays using subject identifiers, not row order alone.
2
Specify the contrast direction.
Define treatment minus control. Reversing the subtraction changes the sign of \(\hat{\beta}_g\), though not its two-sided test statistic in absolute value.
3
Check the model rank and residual degrees of freedom.
For \(n\) complete pairs, the subject indicators and treatment effect give \(df=n-1\). A different value can indicate a coding error, omitted observations, or redundant columns.
4
Inspect residuals and variance behavior.
For each gene, examine unusually large paired differences and residual patterns. Across genes, assess whether the variance prior is plausible and whether a mean-variance trend or hypervariable genes are affecting the fit.

A subject-adjusted model assumes that the treatment effect is represented by one coefficient shared across subjects. If treatment responses vary substantially by subject, that simple model may not describe the data adequately. Strong outliers, unequal array quality, influential samples, missing pairs, or a poor variance-prior fit can also undermine the stated standard errors or moderated tests. With missing observations, a linear model may still be fit, but the complete-pair formulas and degrees of freedom above no longer apply automatically.

Comparing the Main Approaches

ApproachWhat it accounts forMain caution
Subject-adjusted paired modelSubject baselines and the within-subject treatment contrastRequires correct subject matching and an adequate common-effect model
Ordinary paired t inferenceUses the sample variance of paired differences for one geneVariance estimates are noisy when the number of pairs is small
Moderated paired inferenceUses the same fitted contrast and borrows information to stabilize variance estimatesDepends on the across-gene variance-prior assumptions and fit
Unpaired two-group analysisCompares condition means without subject adjustmentIgnores the pairing and can lose precision or give inappropriate uncertainty

For a complete two-condition design, analyzing the within-subject differences with a one-sample t procedure and fitting the subject-adjusted linear model give the same ordinary treatment estimate and standard error when their variance conventions are aligned. The unpaired analysis is not a substitute: it treats observations from the same subject as if they did not share a subject baseline. Finally, gene-level p-values do not by themselves control the error rate across thousands of tested genes; genome-wide conclusions require an appropriate multiple-testing procedure.

Common Pitfalls and Limits

  • Using the wrong variance multiplier. In the full model with separate array residuals, the contrast multiplier is \(2/n\), not \(1/n\). The paired-difference variance is twice the full-model residual variance, which reconciles the two formulas.
  • Pairing samples by position. A mistaken match changes the differences and can invalidate the analysis. Confirm subject IDs and condition labels before fitting.
  • Interpreting the moderated test as a changed effect estimate. Moderation stabilizes uncertainty; \(\hat{\beta}_g\) remains the fitted contrast.
  • Assuming a smaller moderated standard error for every gene. A raw variance below the prior can be moderated upward, as in the low-variance example.
  • Overstating what a significant test establishes. A small p-value is evidence against the zero-contrast model under the assumptions; it is not the probability that the null is true and does not establish a causal mechanism.
  • Ignoring the experimental design after fitting. A few pairs provide limited information about subject-to-subject response variation, outliers, and distributional departures. Moderation stabilizes variance estimates but cannot repair incorrect labels, confounding, or an unsuitable model.
Key takeaway: For complete paired data, fit subject effects and estimate the treatment contrast from within-subject differences. Use \(df=n-1\) and the matching variance multiplier \(2/n\) in the full-model parameterization. Moderated inference changes the variance estimate by borrowing across genes, while leaving the gene's fitted treatment effect intact.

Check Your Understanding

Work through these checks, then compare your reasoning with the solutions.

  1. There are five complete pairs. What are the residual degrees of freedom and the treatment contrast variance multiplier in the full subject-adjusted model?
  2. For four pairs, a gene has paired-difference sample variance \(0.0240\). What is the full-model residual variance and ordinary standard error of the mean difference?
  3. With \(df=3\), \(s_g^2=0.0300\), \(s_0^2=0.0200\), and \(d_0=4\), calculate the moderated variance estimate.
  4. Why can an ordinary unpaired two-group analysis be inappropriate when each subject is measured under both conditions?

Solutions. (1) \(df=n-1=4\); the multiplier is \(2/n=2/5=0.4000\). (2) Since \(s_{D,g}^2=2s_g^2\), the full-model residual variance is \(0.0240/2=0.0120\). The standard error is \(\sqrt{0.0240/4}=\sqrt{0.006000}=0.07746\), equivalently \(\sqrt{2(0.0120)/4}\). (3) \(s_{g,\mathrm{post}}^2=[4(0.0200)+3(0.0300)]/7=0.1700/7=0.02429\). (4) The unpaired analysis discards the shared subject baseline and does not use the within-subject comparisons; its uncertainty calculation therefore does not represent the paired design.

Clinical Biostats