Why an Interaction Is a Difference of Differences
In a factorial microarray experiment, the response for a gene may depend on two factors, such as treatment and genotype. An interaction asks whether the treatment effect differs between genotypes. It is not enough to observe that expression changes in one group or that a gene has a large expression value: the interaction is a comparison of changes.
For a two-by-two design, let \(m_{00},m_{01},m_{10},m_{11}\) denote the four expected log-expression levels, where the first index indicates factor A and the second factor B. The interaction of interest can be written as the change in B's effect across A levels:
If \(\theta=0\), the expected difference between the B levels is the same at both A levels. A nonzero value represents a departure from additivity on the modeled log-expression scale. The sign depends on the ordering of the factor levels, so it must be stated.
Model and Moderated Test
For each gene \(g\), model the normalized log-expression measurements as
Here \(\mathbf{y}_g\) contains the sample measurements for gene \(g\), \(X\) is the design matrix shared across genes, and \(\boldsymbol{\beta}_g\) contains its coefficients. The model assumes that the mean is correctly represented by \(X\boldsymbol{\beta}_g\), that residuals are independent with mean zero, and that the residual variance is constant across samples for this gene. Normal residuals support the small-sample reference distribution. The design must also have enough independent information to estimate the requested coefficients; confounded factor effects cannot be separated by fitting an interaction term.
A cell-means parameterization assigns one coefficient to each factor combination. Then the contrast vector for the two-by-two interaction is \(\mathbf{c}=(1,-1,-1,1)^\mathsf{T}\), when cell means are ordered as \((m_{00},m_{01},m_{10},m_{11})\). Thus \(\hat{\theta}_g=\mathbf{c}^\mathsf{T}\hat{\boldsymbol{\beta}}_g\). Reference-level coding gives different coefficient names, but the fitted cell means and the specified contrast do not change.
Let \(s_g^2\) be the gene-wise residual variance estimate with \(df_g\) residual degrees of freedom. Empirical-Bayes moderation combines this estimate with the across-gene prior variance \(s_0^2\) and prior degrees of freedom \(d_0\):
For a prespecified contrast matrix \(C\) with rank \(q\), the moderated F-statistic is
Under the linear-model and variance-prior assumptions, the reference distribution is \(F_{q,\,df_g+d_0}\). For a single contrast, \(q=1\), the statistic equals the square of the moderated t-statistic. The test concerns \(H_0:C\boldsymbol{\beta}_g=\mathbf{0}\); it does not test whether the gene has any expression or any effect outside the selected contrast.
Worked Analyses
Worked Example: A Two-by-Two Treatment-by-Genotype Interaction
Suppose a hypothetical microarray experiment measures log2 expression for a gene in two genotypes (A0, A1) and two conditions (control, treated), with two independent samples per cell. The fitted cell means are 5.0, 5.4, 5.2, and 6.3, respectively, in the order A0-control, A0-treated, A1-control, A1-treated. Assume the gene-wise residual variance estimate is \(s_g^2=0.16\) on \(df_g=4\), while the empirical-Bayes prior estimates are \(s_0^2=0.09\) and \(d_0=4\).
The prespecified interaction is the treatment effect in A1 minus the treatment effect in A0:
This is \(0.7\) log2-expression units. With two independent samples per cell and equal residual variance, each cell mean has variance \(\sigma_g^2/2\). The difference-in-differences uses four cell means with coefficients of magnitude one, so its variance factor is \(4/2=2\). Moderating the variance gives
The one-contrast moderated statistic is \(t=0.7/0.5=1.4\), or \(F=1.4^2=1.96\), with \(df=(1,8)\). Its two-sided p-value is approximately 0.20. At a 0.05 significance level, this test does not provide strong evidence against a zero interaction for this gene. A 95% moderated t interval is \(0.7\pm2.306(0.5)\), or approximately \((-0.453,1.853)\) log2 units.
The magnitude has a useful multiplicative interpretation. The ratio of the treatment fold change in A1 to that in A0 is \(2^{0.7}\approx1.62\). Thus the estimated treatment fold change is about 1.62 times as large in A1 as in A0. This is an estimate, not evidence by itself that the interaction is nonzero.
Worked Example: Connecting the Contrast to Regression Coding
Use the same hypothetical cell means, but fit the reference-coded model with A0-control as the reference:
The reference cell mean gives \(\hat{\beta}_0=5.0\). The A1-control mean is 5.2, so \(\hat{\beta}_A=5.2-5.0=0.2\). The A0-treated mean is 5.4, so \(\hat{\beta}_B=5.4-5.0=0.4\). Finally, the A1-treated mean must equal \(5.0+0.2+0.4+\hat{\beta}_{AB}=6.3\), giving \(\hat{\beta}_{AB}=0.7\).
The interaction coefficient is exactly the difference-in-differences for this coding. The calculation also checks the fit: the four predicted means are \(5.0\), \(5.2\), \(5.4\), and \(5.0+0.2+0.4+0.7=6.3\). If the reference levels or factor ordering changed, the coefficient's sign or interpretation could change; the cell-mean contrast should therefore be written explicitly before testing.
Worked Example: A Smaller Estimate with Moderated Evidence
For another hypothetical gene in the same balanced design, suppose the cell means are 7.0 (A0-control), 7.5 (A0-treated), 7.4 (A1-control), and 8.5 (A1-treated). Let \(s_g^2=0.25\), \(df_g=4\), \(s_0^2=0.10\), and \(d_0=6\). The estimated interaction is
The moderated variance is \(\{6(0.10)+4(0.25)\}/(6+4)=1.60/10=0.16\). With two samples in each cell, \(SE=\sqrt{2(0.16)}=\sqrt{0.32}\approx0.566\). Therefore \(t=0.6/0.566\approx1.06\) and \(F\approx1.12\), with \(df=(1,10)\). The two-sided p-value is about 0.31. The estimated interaction is 0.6 log2 units, but this test does not give strong evidence of a nonzero interaction. As in the first example, the estimate and its uncertainty answer different questions.
Justification and Design Checks
The standard error calculation in the balanced two-by-two example follows directly from variance propagation. If the four sample cell means are independent and each is based on \(n\) samples with common residual variance \(\sigma_g^2\), each cell-mean variance is \(\sigma_g^2/n\). For \(\hat{\theta}=\bar{Y}_{11}-\bar{Y}_{10}-\bar{Y}_{01}+\bar{Y}_{00}\), independence makes the variance of the sum equal the sum of the four variances; the signs disappear on squaring:
Replacing \(\sigma_g^2\) by the moderated estimate gives \(SE=\sqrt{4s_{g,\mathrm{post}}^2/n}\). In an unbalanced design, or with a more complex design matrix, do not use this shortcut: calculate the contrast variance as \(s_{g,\mathrm{post}}^2 C(X^\mathsf{T}X)^{-1}C^\mathsf{T}\). This accounts for the actual allocation and coefficient covariance.
Before interpreting a result, verify that all four cells are represented, the design matrix is full rank for the requested effects, and sample labels and factor reference levels are correct. The linear model's independence assumption is especially important: repeated measurements or matched samples require an appropriate design representation, not a claim that all observations are independent. Inspect residual patterns for serious outliers or changing variance. Empirical-Bayes moderation stabilizes gene-wise variance estimates using information across genes; it does not repair a misspecified mean model, confounding, dependence, or poor normalization.
Choosing and Interpreting the Interaction Test
A prespecified contrast answers a focused question, such as whether the treatment effect differs between two selected genotypes. An omnibus interaction test instead tests a collection of interaction coefficients jointly. In a two-by-two design, there is only one interaction degree of freedom, so the planned contrast and omnibus interaction test coincide when they express the same comparison. With more factor levels, an omnibus test can detect some interaction pattern without identifying which particular contrast is responsible; a targeted contrast is more directly interpretable but only tests the specified pattern.
The interaction is scale-dependent. In this tutorial the model is fitted to log2 expression, so additivity and interaction refer to that scale. Exponentiating a log2 difference-in-differences yields a ratio of fold changes. It does not establish that the treatment causes an expression change unless the experimental design and study assumptions support a causal interpretation. Nor does a small p-value imply a large biological effect; report \(\hat{\theta}_g\), its units, and uncertainty alongside the test.
- Wrong: “Treatment is significant in A1, but not significant in A0, so the treatment-by-genotype interaction is significant.”
- Correction: A difference between separate significance decisions is not itself a test of the difference. Test the contrast \((m_{11}-m_{10})-(m_{01}-m_{00})\) directly.
- Wrong: Treating a positive interaction coefficient as inherently stronger treatment response without stating the factor coding.
- Correction: State the factor order and contrast direction, then interpret the sign in those terms.
Check Your Understanding
Try each problem, then compare with the solutions below.
- For cell means \(m_{00}=4.0\), \(m_{01}=4.6\), \(m_{10}=4.5\), and \(m_{11}=5.4\), calculate the interaction defined as the B effect at A1 minus the B effect at A0.
- In the first worked example, why is the standard error based on four cell means rather than only the two treated means?
- A researcher finds a small p-value for the treatment effect in one genotype and a large p-value in another. Does this establish an interaction? Explain.
- In a balanced two-by-two design with \(n=2\) samples per cell and moderated variance \(s_{g,\mathrm{post}}^2=0.20\), calculate the standard error of the difference-in-differences.
Solutions. (1) The contrast is \((5.4-4.5)-(4.6-4.0)=0.9-0.6=0.3\) response units. (2) The interaction subtracts the B effect at A0 from the B effect at A1; all four cell means enter with coefficient magnitude one, so all four contribute variance. (3) No. Separate tests do not test the difference between effects; test the specified interaction contrast directly. (4) \(SE=\sqrt{4(0.20)/2}=\sqrt{0.40}\approx0.632\) response units.