Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Diagnosing Confounding in Study Scenarios in Single-Cell Data

Batch Effects Confounded With Biological Condition · Tutorial 151 of 700

Diagnosing Confounding in Study Scenarios in Single-Cell Data

Use condition overlap and model-matrix rank to determine which biological condition contrasts a single-cell study layout can support.

Advanced 12 min read

What You'll Learn

  • Distinguish identifiability of condition contrasts from the amount of data collected.
  • Translate observed batch-condition combinations into a connectivity graph.
  • Use design-matrix rank and null directions to diagnose confounding.
  • Classify layouts as identifiable, partially identifiable, or non-identifiable.
  • Recognize what these classifications do and do not establish about a study.

Why Study Layouts Need an Identifiability Check

A single-cell experiment may contain thousands of cells yet provide no data that distinguish a condition effect from a batch effect. The key question is not how many expression measurements were collected, but which biological conditions were observed in which batches. If a condition occurs only in one batch and a comparison condition only in another, their effects may be inseparable in the model.

This tutorial classifies study layouts according to whether the condition contrasts of interest can be separated from batch effects. The classification is a property of the observed layout and the stated model. It does not by itself establish that the model is biologically adequate, that an effect is large, or that an estimate is precise.

Definition: A condition contrast is identifiable under a model if distinct values of that contrast cannot produce exactly the same model-predicted means for all observations in the study layout. A layout is identifiable for condition effects if all requested condition contrasts are identifiable, partially identifiable if some but not all are identifiable, and non-identifiable for condition effects if none of the requested contrasts is identifiable.

Model and Layout Representation

Consider one gene measured in biological samples indexed by \(s\). Let \(c(s)\) and \(b(s)\) denote the condition and batch for sample \(s\). An additive model for the expected expression on a chosen analysis scale is

$$ E(Y_s)=\mu+\tau_{c(s)}+\gamma_{b(s)}. $$

Here \(\mu\) is a baseline mean, \(\tau_c\) is the condition effect, and \(\gamma_b\) is the batch effect. For example, choose reference levels \(C_0\) and \(B_0\), and set \(\tau_{C_0}=0\) and \(\gamma_{B_0}=0\). Then the coefficients represent differences from those references. The same rank reasoning applies to the linear predictor of a generalized linear model; it does not require expression to be normally distributed.

The additive model assumes that the batch contribution does not depend on condition: it has no condition-by-batch interaction. It also assumes that the listed batch and condition labels represent the relevant design factors. Identifiability is assessed conditional on those assumptions. A design can be identifiable in this model and still be misleading if, for example, the batch effect differs by condition.

For a layout check, make a cross-tabulation of the observed batch-condition combinations. Represent each batch and each condition as a node in a bipartite graph, with an edge between a batch and a condition whenever at least one biological sample was observed in that combination. An empty cell in the table means there is no such edge. The number of cells in a sample does not add a new edge.

Key result: Under the additive batch-plus-condition model, condition contrasts between levels in the same connected component of the batch-condition graph are identifiable. Contrasts between condition levels in different components are not. If all observed condition levels are in one component, all their pairwise contrasts are identifiable under this model.

Why Connectivity and Rank Give the Same Diagnosis

A brief derivation explains why the graph is useful. First use one indicator column for each condition and one for each batch. For every sample, the row of the design matrix has a 1 in its condition column and a 1 in its batch column, with 0s elsewhere. The fitted mean is the sum of the two corresponding effects.

Suppose a change in coefficients leaves every fitted mean unchanged. Write the change in the effect for condition \(c\) as \(a_c\) and the change for batch \(b\) as \(d_b\). For every observed batch-condition pair, unchanged fitted means require

$$ a_c+d_b=0. $$

Along any edge, the condition and batch changes must therefore be opposite. Moving along a path in the graph determines all coefficient changes in that connected component from one free shift. Conversely, shifting every condition effect in a component by the same amount and every batch effect there by its negative leaves all fitted means unchanged. Thus each connected component contributes one such coefficient redundancy.

If there are \(C\) observed condition levels, \(B\) observed batches, and \(K\) connected components, the full indicator matrix has rank \(C+B-K\). Reference coding removes redundant columns but does not change the rank or which contrasts are estimable. The condition contrast \(\tau_{c_1}-\tau_{c_0}\) is unchanged by a common shift within a component, so it is identifiable when the two conditions share a component. If they lie in separate components, their relative shift can change without changing any fitted mean, so that contrast is not identifiable.

Worked Example: Identifiable Despite One Missing Combination

Suppose two batches and two conditions have this layout. Counts are numbers of biological samples, and the entries in parentheses are hypothetical sample means for one gene, in normalized expression units.

ControlTreated
Batch 14 (mean 5)4 (mean 8)
Batch 204 (mean 10)

There are three observed combinations: Batch 1-Control, Batch 1-Treated, and Batch 2-Treated. Their graph is connected because the path from Batch 1 to Treated to Batch 2 links both batches and both conditions. With reference levels Control and Batch 1, a row of the design matrix is \((1,\ I(\text{Treated}),\ I(\text{Batch 2}))\). The three distinct rows are

$$ (1,0,0),\qquad (1,1,0),\qquad (1,1,1). $$

They are linearly independent, so the rank is 3, equal to the number of coefficients. Under the additive model, the fitted coefficients from the displayed means are \(\hat\mu=5\), \(\hat\tau_{\text{Treated}}=8-5=3\) normalized expression units, and \(\hat\gamma_{\text{Batch 2}}=10-8=2\) normalized expression units. The condition contrast is identifiable even though Batch 2 has no control samples.

This conclusion relies on the additive model: the condition difference is assumed to be the same in both batches. The four samples in each observed combination provide replication, but rank alone does not guarantee a useful standard error; that also depends on sample variability and the error model.

Partial and Non-Identifiability

Worked Example: A Condition Contrast Is Identifiable, but Not All of Them

Now consider three conditions and two batches. Hypothetical sample means are shown for a gene.

ControlTreated ATreated B
Batch 15 samples (mean 4)4 samples (mean 7)0
Batch 2003 samples (mean 9)

The graph has two components: Batch 1 is connected to Control and Treated A; Batch 2 is connected only to Treated B. Therefore, the contrast between Treated A and Control is identifiable, but contrasts involving Treated B and either of the other conditions are not. The layout is partially identifiable for the set of all pairwise condition contrasts.

With Control and Batch 1 as reference levels, the design columns are intercept, Treated A, Treated B, and Batch 2. The distinct rows are

$$ (1,0,0,0),\qquad (1,1,0,0),\qquad (1,0,1,1). $$

There are four columns but only three independent rows, so the rank is 3. The first two means give \(\hat\tau_{\text{Treated A}}=7-4=3\) normalized expression units. The last mean gives only the sum \(\tau_{\text{Treated B}}+\gamma_{\text{Batch 2}}=9-4=5\) normalized expression units. To see the ambiguity directly, increasing \(\tau_{\text{Treated B}}\) by 1 and decreasing \(\gamma_{\text{Batch 2}}\) by 1 leaves every fitted mean unchanged. The data cannot determine how that sum should be divided between condition and batch.

Worked Example: Condition and Batch Are Completely Confounded

Suppose controls were measured only in Batch 1 and treated samples only in Batch 2. Each combination has three hypothetical biological samples, with respective gene-expression means of 5 and 9 normalized expression units.

ControlTreated
Batch 13 samples (mean 5)0
Batch 203 samples (mean 9)

The graph has two disconnected components, each containing a single condition and its batch. With Control and Batch 1 as references, the two distinct design rows are \((1,0,0)\) and \((1,1,1)\), for intercept, Treated, and Batch 2. The rank is 2, less than the 3 coefficients. The observed difference is \(9-5=4\) normalized expression units, but the model identifies only \(\tau_{\text{Treated}}+\gamma_{\text{Batch 2}}=4\). For any value assigned to the condition effect, a compensating batch effect produces the same fitted means. No condition contrast is identifiable from this layout under the model.

Adding more cells or more samples to these same two combinations may improve precision for their observed means, but it does not separate the condition effect from the batch effect. The missing overlap, not the total number of measurements, is the problem.

A Practical Diagnosis and Its Limits

For a scenario, classify the layout in a consistent order. Use biological samples as the rows of the design: cells from the same sample do not count as independent condition-by-batch assignments. Then inspect the observed combinations, graph connectivity, and the rank of the model matrix for the contrasts that matter.

1
List observed combinations.
Make a batch-by-condition table using biological samples. Mark zero-sample combinations as unobserved.
2
Check connected components.
Connect each observed batch to its condition. Determine which condition levels belong to the same component.
3
Check the model matrix.
Build the design for the stated model and check its rank. For specific contrasts, check their estimability rather than relying only on whether all coefficients have unique estimates.
4
State the scope of the conclusion.
Identify which condition contrasts are supported under the model, and note that identifiability does not establish precision or validity of the model assumptions.

A cross-tabulation is a quick visual diagnostic, while graph components make the pattern of overlap explicit. A rank calculation is more general: it can include additional covariates or other model terms, and it can reveal exact linear dependencies not obvious from a table. These checks are complementary. Near-dependencies require attention to numerical conditioning as well as exact rank; the earlier material on singular values and numerical near-aliasing addresses that distinction.

A corrected embedding, attractive cluster separation, or a large cell count cannot establish that a condition contrast is identifiable. Nor does an identifiable additive model prove that adjustment has recovered a causal effect. The classification concerns whether the specified model can separate its terms from the observed layout. If there are few biological samples, high variability, omitted covariates, or condition-specific batch effects, an identifiable contrast may still be uncertain or biased.

Common Mistakes

  • Counting cells as independent overlap. A million cells from treated samples in one batch do not create a control sample in that batch. Check assignments at the biological-sample level.
  • Calling a layout identifiable because the model software returns coefficients. Software may impose a constraint or drop a column. That does not make a non-identifiable contrast estimable; inspect rank and the target contrast.
  • Treating partial identifiability as total failure. In the three-condition example, Treated A versus Control is supported by within-batch overlap even though contrasts involving Treated B are not.
  • Assuming rank establishes scientific validity. Full rank addresses algebraic separation under the specified model. It does not verify the additive assumption, rule out unmeasured confounding, or guarantee informative precision.
Key takeaway: Classify a study by the condition contrasts its observed layout can separate from batch under the stated model. Use overlap and graph connectivity for an interpretable first check, then verify the model-matrix rank and the estimability of the specific contrasts.

Check Your Understanding

For each question, decide what the layout supports before reading the solution.

  1. Batch 1 contains Control and Treated samples; Batch 2 contains only Treated samples. Is the two-condition contrast identifiable under an additive model?
  2. There are three conditions: A and B occur together in Batch 1, while C occurs only in Batch 2. Which pairwise condition contrasts are identifiable?
  3. Controls occur only in Batch 1 and treated samples only in Batch 2. If each group has 20,000 cells, does that make the condition contrast identifiable?
  4. In a model with two condition levels and two batch levels, there are observed samples in three of the four possible combinations. What additional check is useful before concluding that the condition effect is identifiable?

Solutions. (1) Yes, under the additive model: the two conditions are connected through Batch 1, so their contrast is identifiable. The Batch 2 treated samples do not supply a second within-batch contrast. (2) A versus B is identifiable because both occur in Batch 1. A versus C and B versus C are not identifiable because C is in a separate graph component. (3) No. The condition and batch indicators remain aliased; the number of cells does not create the missing biological-sample combinations. (4) Check that the observed combinations connect both condition levels and both batch levels, and verify the rank and contrast estimability in the actual model matrix. With three combinations forming a connected graph, the condition contrast is identifiable under the additive model, but precision and model adequacy still require separate assessment.

Clinical Biostats