Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Batch-by-Condition Interactions

Batch Effects Confounded With Biological Condition · Tutorial 135 of 700

Batch-by-Condition Interactions

Use an interaction model to describe condition effects that vary across batches, and assess which of those effects the observed design can identify.

Advanced 12 min read

What You'll Learn

  • Write a reference-coded model with batch, condition, and batch-by-condition interaction terms.
  • Interpret the condition effect separately within each batch.
  • Relate an interaction coefficient to a difference between batch-specific condition effects.
  • Determine when missing batch-condition combinations make interaction effects unestimable.
  • Compare an interaction model with an additive model and recognize common diagnostic concerns.

Why Allow the Condition Effect to Vary by Batch?

An additive model assumes that the condition difference is the same in every batch. That may be a reasonable simplification when batches shift expression by similar amounts in both conditions. But if the measured condition difference varies across batches, an additive model cannot represent that pattern: it forces one shared condition coefficient to summarize potentially different batch-specific effects.

A batch-by-condition interaction relaxes that restriction. It allows the modelled condition difference to depend on batch. This is a statement about the statistical mean model, not by itself a claim that batch causes the difference or that a biological mechanism has been identified. In single-cell data, the response could be a gene’s suitably transformed expression, with the model fitted separately for each gene. The interpretation of an interaction is always on the scale used by the model.

Model and Interpretation

Let \(Y_{ig}\) be the response for cell or observational unit \(i\) and gene \(g\). Let \(b(i)\) denote the unit’s batch, and let \(x_i=0\) for the reference condition and \(x_i=1\) for the other condition. For \(B\) batches, use batch 1 as the reference and write the linear mean model for one gene as follows:

$$ Y_{ig}=\mu_g+\sum_{b=2}^{B}\alpha_{bg}I\{b(i)=b\} +\beta_g x_i+\sum_{b=2}^{B}\delta_{bg}I\{b(i)=b\}x_i+\varepsilon_{ig}. $$

Here \(I\{\cdot\}\) is an indicator that equals 1 when its condition holds and 0 otherwise. The reference-batch coefficients are \(\alpha_{1g}=0\) and \(\delta_{1g}=0\) by convention; they are not additional parameters. The term \(\alpha_{bg}\) describes the difference between batch \(b\) and batch 1 in the reference condition. The coefficient \(\beta_g\) is the condition difference in batch 1. For another batch \(b\), \(\delta_{bg}\) is the change in that condition difference relative to batch 1.

Definition: A batch-by-condition interaction is a term that allows the expected response difference between conditions to vary across batches. Under the reference coding above, the condition effect in batch 1 is \(\beta_g\), and the condition effect in batch \(b\) is \(\beta_g+\delta_{bg}\). Thus, \(\delta_{bg}\) is the difference between the condition effect in batch \(b\) and the condition effect in batch 1.

This parameterization requires care in interpretation: \(\beta_g\) is not an average condition effect across all batches. It is specifically the condition effect in the reference batch. Changing the reference batch changes the individual coefficient meanings, though fitted cell means and appropriately defined comparisons do not change when the model is identifiable.

Worked Example: Interpreting an Interaction From Cell Means

Suppose hypothetical log-scale expression means for one gene are 2.0 in the reference condition and 3.5 in the other condition in batch 1. In batch 2, the corresponding means are 3.0 and 5.7. These four means are assumed to come from a design containing observations in all four batch-condition combinations.

In batch 1, the condition effect is \(3.5-2.0=1.5\) log-scale units. In batch 2, it is \(5.7-3.0=2.7\) log-scale units. The interaction is the difference between these effects:

$$ \delta_{2g}=(5.7-3.0)-(3.5-2.0)=2.7-1.5=1.2. $$

The reference-coded coefficients are \(\mu_g=2.0\), \(\alpha_{2g}=3.0-2.0=1.0\), \(\beta_g=1.5\), and \(\delta_{2g}=1.2\). The model therefore predicts a batch-2 condition effect of \(\beta_g+\delta_{2g}=1.5+1.2=2.7\) log-scale units. This is a description on the model’s log scale; it is not automatically a 2.7-fold change or evidence of a causal effect.

Why the Interaction Is a Difference of Differences

The formula follows directly from the four expected means in a two-batch, two-condition model. With batch 1 as the reference, the expected responses are \(\mu_g\) for batch 1 in the reference condition, \(\mu_g+\beta_g\) for batch 1 in the other condition, \(\mu_g+\alpha_{2g}\) for batch 2 in the reference condition, and \(\mu_g+\alpha_{2g}+\beta_g+\delta_{2g}\) for batch 2 in the other condition. Subtracting the within-batch condition differences gives:

$$ \begin{aligned} &\left[(\mu_g+\alpha_{2g}+\beta_g+\delta_{2g}) -(\mu_g+\alpha_{2g})\right]\\ &\quad-\left[(\mu_g+\beta_g)-\mu_g\right] =(\beta_g+\delta_{2g})-\beta_g =\delta_{2g}. \end{aligned} $$

The shared baseline \(\mu_g\) and batch shift \(\alpha_{2g}\) cancel. What remains is exactly the amount by which the batch-2 condition effect differs from the batch-1 condition effect. In a model with several batches, each \(\delta_{bg}\) is a comparison to the reference batch. A joint test that all interactions are zero asks whether the model’s condition effects are equal across batches; it does not test whether the condition effect itself is zero.

Estimability Depends on the Observed Combinations

Including an interaction term in a formula does not guarantee that the data identify it. An effect is estimable when the observed design contains enough information to determine it uniquely, despite any alternative coefficient values that produce the same fitted means for the observed units. For a design matrix \(X\) and coefficient vector \(\theta\), a linear function \(c^\mathsf{T}\theta\) is estimable precisely when it has the same value for every coefficient vector that gives the same \(X\theta\). Equivalently, \(c\) must lie in the row space of \(X\).

With reference coding, a complete crossing—observations in every batch-condition combination—makes all cell means and their contrasts estimable, provided the model has no other exact redundancies. If a combination is absent, the pattern of missingness matters. Some effects may still be estimable, while others are not. In particular, a within-batch condition difference requires observations in both conditions in that batch when the model allows that batch its own condition effect.

Worked Example: An Unobserved Combination Leaves an Interaction Unidentified

Consider two batches and a binary condition. Suppose the observed hypothetical combinations are batch 1 in both conditions and batch 2 only in the reference condition. With parameter order \((\mu_g,\alpha_{2g},\beta_g,\delta_{2g})\), the design rows for these three observed combinations are:

$$ \begin{array}{c|cccc} &\mu_g&\alpha_{2g}&\beta_g&\delta_{2g}\\ \text{Batch 1, reference}&1&0&0&0\\ \text{Batch 1, other}&1&0&1&0\\ \text{Batch 2, reference}&1&1&0&0 \end{array} $$

The \(\delta_{2g}\) column is all zeros, so changing \(\delta_{2g}\) cannot change any fitted value for the observed data. The design has rank 3 rather than 4. The batch-1 condition effect \(\beta_g\) is estimable from the two batch-1 means, and the reference-condition difference between batches \(\alpha_{2g}\) is estimable. But the batch-2 condition effect \(\beta_g+\delta_{2g}\) is not estimable: batch 2 has no observations in the other condition, so its within-batch condition difference is missing.

An estimated batch-2 condition effect cannot be recovered simply by fitting the interaction model or applying a batch correction. Setting \(\delta_{2g}=0\) would impose the additive assumption that the condition effect is shared across batches; it would not make the data identify an unrestricted batch-2 interaction.

Worked Example: Effects Can Be Estimable in Some Batches but Not Others

Now suppose there are three batches. Batches 1 and 2 each contain both conditions, while batch 3 contains only the reference condition. Use parameters \((\mu_g,\alpha_{2g},\alpha_{3g},\beta_g,\delta_{2g},\delta_{3g})\). The observed design rows are:

$$ \begin{array}{c|rrrrrr} &\mu_g&\alpha_{2g}&\alpha_{3g}&\beta_g&\delta_{2g}&\delta_{3g}\\ 1,\ \text{reference}&1&0&0&0&0&0\\ 1,\ \text{other}&1&0&0&1&0&0\\ 2,\ \text{reference}&1&1&0&0&0&0\\ 2,\ \text{other}&1&1&0&1&1&0\\ 3,\ \text{reference}&1&0&1&0&0&0 \end{array} $$

There are five independent rows for six parameters. The observed means identify \(\mu_g\), \(\alpha_{2g}\), \(\alpha_{3g}\), \(\beta_g\), and \(\delta_{2g}\), but the \(\delta_{3g}\) column is zero. Therefore, the condition effect is estimable in batch 1 as \(\beta_g\) and in batch 2 as \(\beta_g+\delta_{2g}\); the batch-3 condition effect \(\beta_g+\delta_{3g}\) is not estimable. This illustrates why the useful question is not merely whether the whole design matrix has full rank, but which particular effects or contrasts are estimable.

Assumptions, Diagnostics, and Alternatives

The interaction model describes conditional means. For the linear model as written, it assumes that the expected response is represented by the stated batch, condition, and interaction terms, with errors having conditional mean zero. Standard least-squares standard errors additionally require an appropriate variance model; conventional independent, homoskedastic errors are often used for basic inference. Exact small-sample \(t\)- or \(F\)-test calibration additionally relies on normally distributed errors. These assumptions should not be transferred uncritically to raw single-cell counts: the response scale and error model must suit the data and the analysis.

In single-cell studies, cells from the same biological sample are not generally independent experimental replicates. Treating every cell as an independent replicate can understate uncertainty. The experimental unit and dependence structure must therefore be considered when making inferential claims; a cell-level interaction coefficient alone does not solve that issue.

Useful checks include tabulating the number of observations in each batch-condition combination, inspecting the design matrix rank, and examining fitted means and residual patterns by batch and condition. Empty combinations warn of non-estimable effects. Very small counts in some combinations may leave effects technically estimable but imprecise. Residual trends, unequal spread, or outlying combinations can indicate that the chosen mean or variance model is inadequate. A large fitted interaction can also be driven by a small or unusual group, so it should be interpreted alongside the data supporting each cell mean.

The main alternative is an additive model, which omits all \(\delta_{bg}\) terms and assumes one common condition effect across batches. It is simpler and may be more precise when that restriction is credible, but it cannot describe genuine variation in the condition effect. An interaction model is more flexible but uses more parameters and can be unstable when combinations are sparse or absent. A cell-means model estimates each observed batch-condition mean directly; with a complete design, it represents the same mean patterns as the fully interacted categorical model, though its parameterization differs. No parameterization can supply a missing comparison without an added assumption.

Common pitfall: “The interaction coefficient is not significant, so the condition effect is identical in every batch.” This conclusion is too strong. A test that does not reject zero interaction does not prove equality; it may reflect limited precision. Conversely, a coefficient that cannot be estimated because a combination is absent is not a zero interaction. Check estimability first, then interpret estimates and uncertainty on the model’s stated scale.

Check Your Understanding

Answer each question, then compare with the brief solutions below.

  1. In a two-batch model with batch 1 as reference, what does \(\delta_{2g}=0.8\) mean?
  2. Suppose the condition effects are 0.4 log-scale units in batch 1 and 1.1 in batch 2. What is the batch-2 interaction coefficient?
  3. Batch 1 contains both conditions, while batch 2 contains only the other condition. Is the batch-2 within-batch condition effect estimable under an unrestricted interaction model? Explain.
  4. Why does a nonsignificant interaction test not establish that all batch-specific condition effects are equal?

Solutions. (1) The condition difference in batch 2 is 0.8 log-scale units larger than the condition difference in batch 1. (2) \(\delta_{2g}=1.1-0.4=0.7\) log-scale units. (3) No. The reference-condition mean for batch 2 is unobserved, so its within-batch difference cannot be obtained without an additional model restriction. (4) Failure to reject can arise from low precision or limited information; it is not proof of equality.

Clinical Biostats