Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Cross-Tabulations as Confounding Diagnostics

Batch Effects Confounded With Biological Condition · Tutorial 138 of 700

Cross-Tabulations as Confounding Diagnostics

Use batch-by-condition counts and heatmaps to find design gaps and imbalances before interpreting batch-adjusted comparisons.

Advanced 12 min read

What You'll Learn

  • Build a batch-by-condition table using independent biological samples as the primary counts.
  • Distinguish an empty batch-condition cell from a cell containing few samples or few sequenced cells.
  • Use row and column proportions to reveal imbalance that marginal totals may conceal.
  • Interpret heatmaps without confusing visual patterns with formal tests or proof of confounding.
  • Relate differing batch compositions to crude condition means, including cases where contributions cancel.
  • Recognize when a table flags unsupported comparisons but cannot establish model-based estimability by itself.

Why Cross-Tabulate Batch and Condition?

A single-cell study may contain many measured cells but relatively few independent biological samples. Before comparing conditions or adjusting for batch, it is therefore useful to ask a simple design question: which batches contain samples from which conditions, and how many independent samples are in each combination? A batch-by-condition table makes this allocation visible. It can reveal an empty combination, sparse replication, or an imbalance that is obscured by overall totals.

The table is a diagnostic, not a correction method or a test of whether batch effects exist. It describes the observed allocation of samples. It does not show that a condition difference is caused by batch, nor does it establish that a desired adjusted contrast is estimable under a particular model. Those conclusions require assumptions and model-based checks.

Definition: Let \(n_{bk}\) be the number of independent biological samples observed in batch \(b\) and condition \(k\). The batch-by-condition cross-tabulation is the array of counts \(n_{bk}\), with batches as rows and conditions as columns. A cell is empty when \(n_{bk}=0\); it is sparse when it contains few independent samples relative to the design needs.

In most biological studies, the sample or experimental unit—not each sequenced cell—is the unit of replication for comparing conditions. A table of cell counts can be useful for describing sequencing yield, but it must not be substituted for a table of biological sample counts. For example, one donor contributing 2,000 cells is still one donor, not 2,000 independent condition replicates.

Constructing and Reading the Table

First define the batch categories and condition categories used in the analysis. Then count the independent samples in every combination, including combinations with zero observations. Add row totals, which summarize the number of samples in each batch, and column totals, which summarize the number in each condition. These margins give context, but they are not enough: two studies can have identical margins and very different allocations among the interior cells.

Consider the following hypothetical sample counts. Each entry is the number of biological samples, not the number of cells.

BatchControlTreatedBatch total
A808
B268
C077
D549
Condition total151732

The margins show 15 control and 17 treated samples, which may look reasonably balanced overall. The interior reveals a different picture: batch A has controls only, batch C has treated samples only, and both conditions occur in batches B and D. A raw comparison of all controls with all treated samples consequently compares different mixtures of batches. B and D provide within-batch condition comparisons in this table; A and C do not.

A useful set of summaries is the within-batch condition proportion and the within-condition batch proportion. For example, in batch B, the treated proportion is \(6/8=0.75\). Among treated samples, the batch B proportion is \(6/17\approx0.353\). These answer different questions: the first describes condition allocation within a batch, while the second describes how a condition's samples are distributed across batches. Neither should replace the count table, since a proportion can look large when its denominator is small.

Worked Example: Finding Imbalance Behind Similar Margins

Suppose two hypothetical studies each have 12 control samples, 12 treated samples, and two batches of 12 samples each. Study 1 has 6 controls and 6 treated samples in each batch. Study 2 has 10 controls and 2 treated samples in batch A, and 2 controls and 10 treated samples in batch B. Compare their allocations.

For Study 1, the treated fraction is \(6/12=0.50\) in each batch. The condition composition is identical across batches.

For Study 2, the treated fraction is \(2/12\approx0.167\) in batch A and \(10/12\approx0.833\) in batch B. The totals remain 12 per condition and 12 per batch, but condition is strongly imbalanced across batches.

Thus, matching row and column totals do not imply matching designs. The interior counts identify whether comparisons can be made within the same batch and how heavily the crude condition groups draw on different batches. The table signals a potential confounding problem; it does not quantify a gene-specific batch effect.

Empty Cells, Sparse Cells, and Support

An empty cell means that the study observed no independent samples for one batch-condition combination. It is not an observed zero expression value, and it does not mean that the missing combination has a known biological outcome. A sparse cell has some observations but little replication, so estimates based on it may be imprecise and sensitive to individual samples.

If a condition occurs in only one batch, the table immediately shows that its observed samples cannot be compared with the other condition within that batch. If two conditions both occur in at least one common batch, a within-batch comparison is represented in the data for those batches. However, this does not automatically establish that a particular overall condition contrast is estimable: the answer depends on the model, its parameterization, and any interaction terms. Cross-tabulation is an initial support diagnostic, not a substitute for the design-matrix audit or estimability analysis.

The distinction between sample counts and cell counts matters especially when sequencing depth differs. A batch-condition combination might contain several biological samples but very different numbers of cells per sample. A second table of cell yields can describe that imbalance, but a large cell count does not repair a lack of biological replication. Conversely, a small cell yield may limit cell-level precision even when the number of biological samples is adequate.

Worked Example: Separating Sample Support From Cell Yield

In a hypothetical experiment, batch X has three control donors and three treated donors. The control donors contribute 500, 600, and 700 cells; the treated donors contribute 100, 1,000, and 1,100 cells. Batch Y has no control donors and four treated donors, each contributing about 800 cells. What does the cross-tabulation establish?

At the biological-sample level, batch X supports a within-batch comparison: it contains three independent samples in each condition. Batch Y has an empty control cell, so it supplies no within-batch control-versus-treated comparison. The table does not show that the treated effect is identical across X and Y, nor that an across-batch condition contrast is supported under every model.

The cell-yield totals for batch X are \(500+600+700=1{,}800\) control cells and \(100+1{,}000+1{,}100=2{,}200\) treated cells. These totals show unequal yield and substantial variation across treated donors, but they do not change the sample counts of three and three. Reporting only 1,800 and 2,200 could make the biological replication look much larger than it is.

Heatmaps: A Visual Companion to the Counts

A heatmap encodes each table entry by color intensity. A count heatmap can make empty and unusually large cells easy to spot, particularly when there are many batches or conditions. The numeric values should remain available—through labels, a neighboring table, or both—because color alone is imprecise and depends on the chosen scale.

The scale and normalization must match the question. A heatmap of raw sample counts emphasizes absolute replication. A heatmap of row proportions emphasizes the condition mix within each batch, while a heatmap of column proportions emphasizes how each condition is distributed across batches. These proportion heatmaps can reveal patterns hidden by different row or column totals, but may visually exaggerate a proportion based on a very small denominator. State which denominator was used and inspect the counts alongside the colors.

Use a sequential color scale for nonnegative counts or proportions, with a clearly distinguishable color for zero if possible. Avoid interpreting a color gradient as a significance scale: a heatmap of allocation is descriptive, and its color does not encode a p-value. If batches or conditions are reordered, preserve and report the labels so the display cannot imply a different allocation.

Worked Example: Choosing the Heatmap Scale

A hypothetical study has four batches, each with 20 samples. In batches A and B, the control/treated counts are 18/2 and 16/4. In batches C and D, they are 4/16 and 2/18. How should raw-count and row-proportion heatmaps be read?

The row proportions for treated samples are \(2/20=0.10\), \(4/20=0.20\), \(16/20=0.80\), and \(18/20=0.90\). A raw-count heatmap and a row-proportion heatmap both show the condition shift here because each batch has the same total. The proportion display states the pattern directly: treated representation rises from 10% in A to 90% in D.

If batch totals were instead 2, 20, 200, and 10, raw counts would combine allocation and batch size. Row proportions would isolate the condition mix, but the 1-of-2 entry could be visually similar to 100-of-200 despite very different precision. Therefore, show or retain the denominators. Neither display alone establishes a biological effect or a statistical test result.

Why Composition Can Affect a Crude Difference

A table helps explain one route by which a crude, unadjusted condition difference can combine condition effects with differences in batch composition. To see the point, suppose the expected outcome in batch \(b\) under control is \(\mu_b\), and under condition 1 it is \(\mu_b+\tau_b\). Let \(w_{kb}\) be the proportion of condition \(k\)'s samples drawn from batch \(b\), so each set of weights sums to one. This additive mean representation is an illustration; it assumes the stated batch-specific means are meaningful and does not make unobserved combinations empirically observed.

The difference between the two marginal expected means is obtained by weighting each batch mean according to its condition composition:

$$ \sum_b w_{1b}(\mu_b+\tau_b)-\sum_b w_{0b}\mu_b = \sum_b w_{1b}\tau_b+\sum_b(w_{1b}-w_{0b})\mu_b. $$

The first term averages condition effects using condition 1's batch weights. The second is a composition term involving differences in batch weights and baseline means. It can be nonzero when conditions have different batch compositions and baseline means differ, but with three or more batches the contributions can cancel. For exactly two batches, the term is guaranteed nonzero when both the compositions and baseline means differ: writing \(d=w_{11}-w_{01}\), it equals \(d(\mu_1-\mu_2)\).

For a cancellation example with three batches, take baseline means \(0,1,2\), control weights \((0.3,0.4,0.3)\), and condition 1 weights \((0.4,0.2,0.4)\). The weights differ, but the composition term is \(0.1(0)-0.2(1)+0.1(2)=0\). Thus differing compositions and differing baseline means do not guarantee a nonzero composition term with three or more batches.

Worked Example: Calculating a Composition Contribution

Use the three-batch weights above and suppose, hypothetically, that the condition effect is a constant \(\tau_b=2\) outcome units in every batch. The condition 1 weighted mean is based on batch means \(2,3,4\), giving \(0.4(2)+0.2(3)+0.4(4)=0.8+0.6+1.6=3.0\). The control weighted mean is \(0.3(0)+0.4(1)+0.3(2)=1.0\). The marginal difference is \(3.0-1.0=2.0\) outcome units.

The decomposition gives the same result: the condition-effect term is \(0.4(2)+0.2(2)+0.4(2)=2.0\), and the composition term is \(0\). The calculation demonstrates that different batch proportions need not create a nonzero composition contribution when contributions cancel. It does not justify imputing missing batch-condition outcomes in a real study; the assumed means for unobserved combinations may not be identifiable from the table.

Assumptions, Diagnostics, and Alternatives

A cross-tabulation itself is descriptive and does not require a probability model. Its interpretation does require accurate batch and condition labels, a clearly defined counting unit, and inclusion of all relevant combinations. For inferential use of the counts or outcome data, additional assumptions may be needed—for example, independence across biological samples and an appropriate model for repeated or paired observations. Do not treat cells from the same donor as independent biological replicates merely because they appear as separate rows in a cell-level dataset.

Useful checks include verifying that the row and column sums equal the number of samples included; checking that zeroes are genuine absences rather than missing records; inspecting the number of biological replicates in each nonempty cell; and comparing raw counts with within-row or within-column proportions. If samples are paired, nested, or repeated within donor, a simple table may omit important structure and should be supplemented with the relevant sample identifiers and design information.

Several displays answer related but distinct questions:

ApproachWhat it revealsWhat it does not establish
Count cross-tabulationObserved sample counts and empty or sparse combinationsWhether a model-based contrast is estimable or a batch effect exists
Row- or column-proportion tableCondition mix within batches or batch mix within conditionsReplication adequacy without the denominators
HeatmapVisual allocation patterns across many combinationsNumerical precision, statistical significance, or causation
Design-matrix or model auditRank, estimability, and implications under a specified modelWhether the model assumptions are scientifically credible by itself

A common mistake is to see similar overall condition totals and conclude that batch is balanced. The correction is to inspect every interior count and, where useful, within-batch proportions: balanced margins can coexist with strong imbalance or empty combinations. A related mistake is to interpret a heatmap with no obvious empty cell as proof that a comparison is well supported. Nonzero counts may still be sparse, and the relevant estimability depends on the chosen model and contrast.

Cross-tabulations matter because they are fast, transparent diagnostics that can expose design limitations before normalization, integration, or differential expression analysis. Their limitation is equally important: they summarize allocation, not expression outcomes or causal effects. Use them to identify questions that need further model-based investigation, and report the counting unit and denominator so readers can interpret the display correctly.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A study has 20 control and 20 treated samples overall, but all controls are in batch A and all treated samples are in batch B. What does the cross-tabulation show, and what can it not establish?
  2. In a batch with 2 control and 8 treated biological samples, what is the treated proportion? Why should the count be shown with the proportion?
  3. Why is a table containing 5,000 cells from one donor not equivalent to a table containing 5,000 independent biological samples?
  4. With three batches, can different condition weights and different baseline means yield a zero composition term? Give the arithmetic example from this tutorial.

Solutions. (1) The table has an empty control cell in B and an empty treated cell in A, so no within-batch condition comparison is observed. It flags complete allocation overlap with batch, but alone does not determine effects or prove a particular model contrast's properties. (2) The treated proportion is \(8/(2+8)=0.80\). The denominator matters because 8 of 10 and 80 of 100 have the same proportion but different sample support. (3) Cells from one donor are clustered observations from one biological sample, not independent biological replicates; cell count does not supply donor-level replication. (4) Yes. With baseline means \((0,1,2)\), control weights \((0.3,0.4,0.3)\), and condition 1 weights \((0.4,0.2,0.4)\), the term is \(0.1(0)-0.2(1)+0.1(2)=0\), despite differing weights and baseline means.

Clinical Biostats