Why Compare Feature Distributions?
A batch adjustment is intended to reduce technical differences between batches while preserving variation relevant to the scientific question. A practical diagnostic is to compare the distribution of each feature across batches both before and after adjustment. Such comparisons can reveal a residual location offset, a difference in spread, or a more complex shape difference that a single average would miss.
The comparison is feature-specific: a feature measured in two batches is examined across the subjects in each batch. It is not enough to compare one overall distribution per assay or to inspect only a multivariate summary. A correction can make one feature’s batch distributions more similar while leaving another feature’s distributions different.
For a feature, useful summaries include the batch-specific sample size, mean, median, standard deviation, and interquartile range (IQR). Boxplots display medians, quartiles, and potential extreme values compactly; density plots display estimated distribution shapes. The different summaries answer different questions. Means and medians describe location, standard deviations and IQRs describe spread, and plots can expose skewness, multiple modes, or tails.
Comparisons require a meaningful common measurement scale within a feature. When comparing before with after, use the same subjects and clearly identify the values as unadjusted or adjusted. Across different features, units and scales may differ; a difference of one unit in one feature need not be comparable to a difference of one unit in another.
What Similarity Does—and Does Not—Mean
If batches differ mainly by a technical additive offset, their distributions may have similar shapes and spreads but different centers. A residual shift in the medians or means after adjustment is evidence of a remaining location difference. If centers are similar but the IQRs or standard deviations differ, the remaining discrepancy is primarily in scale. Differences in skewness, tails, or modality indicate shape differences that neither location nor scale summaries fully capture.
The expected degree of similarity depends on the data and the scientific design. If batches contain comparable subject populations and the adjustment is intended to remove batch-associated distributional differences, substantial residual differences deserve investigation. But if biological composition differs across batches, marginal distributions can differ for biological as well as technical reasons. For example, a feature may be higher in a batch because that batch contains more subjects from a biological subgroup. Making the marginal distributions identical could then remove meaningful variation. Distributional similarity is therefore not a universal target independent of study design.
Location and Scale Summaries
Let \(n_b\) be the number of observed subjects in batch \(b\) for a feature. Its batch-specific sample mean is the sum of the measured values divided by \(n_b\); its sample median is the middle value (or the average of the two middle values for an even sample size). The IQR is the third quartile minus the first quartile. The sample standard deviation \(s_b\) measures spread around the sample mean using the squared deviations and denominator \(n_b-1\).
For before-and-after assessment, calculate these summaries separately for each batch at each stage. Report changes in context and in the feature’s units. For example, a post-adjustment difference of 0.8 units in the batch medians is a residual location difference of 0.8 feature units; it is not automatically a practically important difference without reference to the feature and its scale.
The boxplot is a compact view of location and spread. A boxplot whose median lines differ but whose box widths are similar suggests a location shift with roughly similar central spread. Similar medians with substantially different box widths suggest a scale difference. Density plots add shape information, although their appearance depends on the smoothing bandwidth and can be unstable when sample sizes are small.
Why Pooled Summaries Can Mislead
A pooled standard deviation can be large because values vary within batches, because batch means differ, or both. The following finite-sample identity makes this distinction explicit. Let \(N=\sum_b n_b\), let \(\bar{x}\) be the overall sample mean, and let \(\bar{x}_b\) be the mean in batch \(b\). The sum of squared deviations can be decomposed by writing each deviation as \((x_{ib}-\bar{x}_b)+(\bar{x}_b-\bar{x})\). The cross-product sums to zero within each batch because \(\sum_i(x_{ib}-\bar{x}_b)=0\). Thus:
The first term is within-batch variation; the second is between-batch variation due to different batch means. Dividing by \(N-1\) gives the pooled sample variance. This identity does not assume normality or equal batch sizes. It explains why a feature can have a wide pooled distribution even when each batch has modest within-batch spread: separated batch centers contribute to the total.
Worked Example: A Residual Additive Offset
Consider a hypothetical feature measured in arbitrary units in two batches, with five subjects per batch. Before adjustment, Batch A has values \(8,9,10,11,12\), and Batch B has values \(12,13,14,15,16\). Suppose the adjusted Batch B values are \(8,9,10,11,12\), while Batch A is unchanged.
Before adjustment, the means are \(\bar{x}_A=(8+9+10+11+12)/5=50/5=10\) units and \(\bar{x}_B=(12+13+14+15+16)/5=70/5=14\) units. The mean difference is \(14-10=4\) units. The medians are 10 and 14 units, so the median difference is also 4 units.
Using the median-of-halves convention for these five ordered values, Batch A has \(Q_1=9\), median \(10\), and \(Q_3=11\), so its IQR is \(11-9=2\) units. Batch B has quartiles 13 and 15, so its IQR is \(15-13=2\) units. The distributions have the same observed shape and spread, but Batch B is shifted upward by 4 units. A boxplot would show equal-height boxes at different centers; density curves would have similar shapes separated horizontally.
After adjustment, both batches have mean and median 10 units and IQR 2 units. The observed batch location difference has been removed in this example, while the spreads remain equal. This is evidence of distributional alignment for this feature in these hypothetical data; it does not establish that the adjustment preserved every biological relationship.
Worked Example: A Scale Difference Hidden by Equal Means
Suppose hypothetical values for a feature are \(8,9,10,11,12\) in Batch A and \(6,8,10,12,14\) in Batch B. Both means equal 10 units, and both medians equal 10 units. A comparison based only on means or medians would miss the difference in spread.
For Batch A, the squared deviations from 10 are \(4,1,0,1,4\), which sum to 10. Therefore \(s_A=\sqrt{10/(5-1)}=\sqrt{2.5}=1.581\) units. For Batch B, the squared deviations are \(16,4,0,4,16\), which sum to 40. Therefore \(s_B=\sqrt{40/4}=\sqrt{10}=3.162\) units. Batch B’s sample standard deviation is twice Batch A’s.
The quartiles using the median-of-halves convention are \(Q_{1A}=9\), \(Q_{3A}=11\), and \(Q_{1B}=8\), \(Q_{3B}=12\). Thus the IQRs are 2 and 4 units, respectively. The boxplot and density plot should both indicate a wider distribution in Batch B, despite identical centers. After adjustment, if the two observed sets were both \(8,9,10,11,12\), their summaries would match; whether that change is appropriate would still depend on whether the original spread difference was technical or biologically meaningful.
A Practical Diagnostic Sequence
A consistent sequence makes comparisons interpretable and reduces the risk of relying on an attractive but incomplete plot.
For each feature, identify the batches, the subjects included, and whether values are before or after adjustment. Check that comparisons use the intended observations.
Record sample size, median, IQR, mean, and standard deviation in the feature’s units. Large differences in sample size make plots less equally informative.
Use boxplots to compare centers and central spreads, and density plots to assess shape. Use the same axes for the before-and-after comparison of a feature.
State whether location, scale, or shape differences decreased, persisted, or appeared after adjustment. Do not infer preservation of biology from distributional alignment alone.
Check sample composition, extreme observations, missing measurements, and small batch sizes before interpreting an apparent residual difference as purely technical.
Worked Example: Quantifying a Remaining Shift
In a hypothetical post-adjustment comparison, a feature has values \(4,5,6,7,8\) in Batch A and \(5,6,7,8,9\) in Batch B. Each batch has five subjects. Both batches have the same observed spread: each has IQR \(=2\) units using the median-of-halves convention, and each has sample standard deviation \(\sqrt{10/4}=1.581\) units.
The means are \(\bar{x}_A=(4+5+6+7+8)/5=30/5=6\) units and \(\bar{x}_B=(5+6+7+8+9)/5=35/5=7\) units. The medians are also 6 and 7 units. The residual difference in means and medians is therefore \(1\) unit, with Batch B higher. The equal spreads and parallel-looking distributions indicate a remaining location offset rather than a scale difference in these data.
This comparison establishes the descriptive difference for the observed batches. It does not determine whether the offset is technical, biological, or a mixture. That interpretation requires the study design and knowledge of which biological covariates were represented in each batch.
Diagnostics, Alternatives, and Limitations
A plot or summary can mislead when there are few subjects per batch, highly unequal batch sizes, or extreme observations. Boxplots may conceal multimodality and differences in tails; density estimates can create or erase apparent modes depending on bandwidth. Always inspect sample sizes, consider plotting individual observations when feasible, and compare multiple summaries rather than treating one statistic as decisive.
Feature-wise comparisons are also not a replacement for multivariate diagnostics. They reveal marginal distributions, one feature at a time, but do not show whether the joint relationships among features changed. PCA provides a multivariate view of patterns across samples; it answers a different question and can obscure feature-specific discrepancies. Formal tests of distributional differences can quantify evidence under their assumptions, but they may detect small differences in large samples, miss relevant differences in small samples, and create a multiple-testing problem when many features are tested. A test result should not replace inspection of effect size, units, plots, and study design.
| Approach | Most informative for | Important limitation |
|---|---|---|
| Per-feature boxplots and summaries | Batch-specific location and central spread | May hide multimodality and tail differences |
| Per-feature density plots | Shape, skewness, and possible multiple modes | Sensitive to smoothing and sample size |
| Multivariate PCA diagnostics | Joint sample patterns across many features | May not identify which feature drives a pattern |
| Formal distributional tests | Evidence against a specified distributional equality null | Depend on assumptions and require attention to multiplicity and practical importance |
A further limitation is confounding between batch and biology. If a biological group occurs only in one batch, a feature’s batch distributions cannot by themselves separate a batch effect from a group effect. In that setting, apparent residual differences may reflect composition, while apparent alignment may reflect removal of real group variation. These diagnostics should be interpreted alongside the experimental design and the covariates the adjustment was intended to preserve.
Common Mistakes
- Wrong reasoning: “The post-adjustment batch means match, so the distributions match.” Correction: Equal means do not imply equal spread or shape; compare medians, IQRs, standard deviations, and plots.
- Wrong reasoning: “Every feature should have identical batch distributions after adjustment.” Correction: That is not necessarily appropriate when batch composition differs biologically or when the procedure is intended to preserve biological covariates.
- Wrong reasoning: “A remaining difference proves the correction failed.” Correction: The difference is descriptive; it may be technical, biological, or both. Interpret it in the context of design and adjustment goals.
- Wrong reasoning: “Pooled variability summarizes the batches adequately.” Correction: Pooled variation combines within-batch spread and between-batch location differences, so inspect batches separately.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- Two batches have the same median after adjustment, but their IQRs are 3 and 7 units. What type of difference remains, and which display is useful?
- For a feature, Batch A has sample mean 5 units and Batch B has sample mean 8 units before adjustment. After adjustment, both means are 6 units. What changed descriptively, and what cannot be concluded from this alone?
- Why can a pooled standard deviation be large even when each batch has modest within-batch spread?
- What is one advantage and one limitation of density plots compared with boxplots?
Solutions. (1) The centers match but the spreads differ, with Batch B having the wider central spread. Boxplots show the IQR difference; density plots can add shape information. (2) The observed difference in batch means decreased from \(8-5=3\) units to \(6-6=0\) units. This does not establish that biology was preserved or that the original difference was entirely technical. (3) The pooled variance includes both within-batch variation and between-batch variation in the batch means, as shown by the sum-of-squares decomposition. (4) A density plot can reveal skewness or multiple modes, but its shape depends on smoothing and can be unstable for small samples; a boxplot summarizes quartiles more compactly but can hide shape.