← All notes

Statistical note

Batch effects and harmonization

Separate biological differences from acquisition-day, instrument, staining, or processing shifts without erasing real biology.

6 min read

How do acquisition, segmentation, hierarchy, and measurement error affect the biological conclusion drawn from images? This note turns that question into a practical analysis workflow.

Conceptual guide to Batch effects and harmonization

Core idea

Separate biological differences from acquisition-day, instrument, staining, or processing shifts without erasing real biology. The method is useful only when its target, data-generating assumptions, and unit of analysis match the scientific question.

Yij=μ+βbatch(j)+τi+ϵijY_{ij}=\mu+\beta_{batch(j)}+\tau_i+\epsilon_{ij}

The equation is a compact statement of the target; it is not a substitute for checking design and data quality. State what each observation represents, how it entered the sample, and which sources of dependence remain.

Practical workflow

  1. Write the scientific question and estimand in one sentence.
  2. Identify biological units, technical replicates, nesting, repeated measurements, and exclusions.
  3. Visualise raw observations and group structure before fitting the method.
  4. Check assumptions using design knowledge, diagnostic plots, and sensitivity analyses.
  5. Report the estimate, uncertainty, effect magnitude, sample sizes at every level, and limitations.
import numpy as np

# Aggregate cells within fields, then fields within biological replicates.
cell_measurements = np.array([[4.1, 4.3, 4.0], [5.2, 5.0, 5.1]])
field_means = cell_measurements.mean(axis=1)
print({'field_means': field_means, 'grand_mean': field_means.mean()})

Interpretation and failure modes

Do not read a software output as an automatic scientific conclusion. Ask whether dependence was modeled, whether preprocessing used information from validation data, whether missingness or selection is informative, and whether the reported uncertainty covers every level of sampling. Prefer estimates and intervals to threshold-only language.

Microscopy case study

Include shared controls across imaging days and preserve batch grouping during validation to expose deployment shift.

Connections

Use the tags above to continue to notes on design, assumptions, uncertainty, diagnostics, and complementary methods. A robust analysis normally combines several concepts rather than selecting one test in isolation.