Inferensys

Glossary

k-nearest Neighbor Batch Effect Test (kBET)

A quantitative metric that evaluates the degree of batch mixing by comparing the local batch label distribution in a k-nearest neighbor graph to the global batch distribution, with a perfect mix yielding a chi-squared test acceptance rate near 1.0.
Technical lab environment with sensor equipment and analytical workstations.
BATCH INTEGRATION METRIC

What is k-nearest Neighbor Batch Effect Test (kBET)?

A quantitative framework for evaluating the degree of batch mixing in high-dimensional data by comparing local and global batch label distributions.

The k-nearest Neighbor Batch Effect Test (kBET) is a quantitative metric that evaluates batch mixing quality by comparing the local batch label distribution within a cell's k-nearest neighborhood to the global batch distribution. A well-mixed dataset yields a chi-squared test acceptance rate near 1.0, indicating successful batch correction.

kBET operates by constructing a k-nearest neighbor graph and performing a chi-squared test for each cell's local neighborhood, measuring whether batch labels are randomly distributed. The fraction of neighborhoods that pass this test provides a single, interpretable score, making kBET a standard for benchmarking integration algorithms like Harmony and Seurat.

BATCH MIXING QUANTIFICATION

Key Features of kBET

The k-nearest Neighbor Batch Effect Test (kBET) provides a rigorous, quantitative framework for evaluating the success of batch correction algorithms by measuring the local homogeneity of batch labels in a high-dimensional neighborhood graph.

01

Chi-Squared Based Acceptance Rate

The core metric of kBET is the acceptance rate, derived from a chi-squared test. For a random subset of cells, the algorithm identifies their k-nearest neighbors and compares the observed local batch label distribution to the expected global distribution. A well-mixed dataset yields an acceptance rate near 1.0, while a score near 0.0 indicates strong local batch clustering. This provides a single, interpretable scalar value for integration quality.

02

Local Neighborhood Sensitivity

Unlike global metrics that only compare overall distributions, kBET operates on a local graph topology. It constructs a k-nearest neighbor (kNN) graph and tests for batch label homogeneity within each cell's immediate neighborhood. This makes it exceptionally sensitive to local batch effects—pockets of cells from the same batch that remain clustered together—which global distribution comparisons like PCA visualization might miss.

03

Null Hypothesis Framework

kBET is grounded in formal statistical testing. The null hypothesis states that the batch labels within any local neighborhood are drawn from the same multinomial distribution as the global batch proportions. A rejection of this null hypothesis for a high proportion of neighborhoods indicates incomplete mixing. This framework allows users to set a significance level (alpha) to control the stringency of the mixing assessment.

04

Computational Sampling Strategy

To manage the computational complexity of testing every cell in large datasets, kBET employs a random sampling strategy. It iteratively selects a fraction of cells, computes their kNN graph, and performs the chi-squared test. The final acceptance rate is the average over these iterations. This approach provides a robust estimate of overall mixing while maintaining scalability for modern single-cell datasets containing millions of cells.

05

k-Nearest Neighbor Parameterization

The choice of k (the number of neighbors) is a critical parameter that tunes the scale of the mixing assessment. A small k tests for very fine-grained, local mixing, while a larger k evaluates mixing over broader cellular neighborhoods. The kBET framework recommends testing a range of k values to understand the multi-scale mixing properties of an integrated dataset, ensuring that correction is not just superficial.

06

Integration with Single-Cell Pipelines

kBET is a standard evaluation tool in single-cell RNA sequencing workflows. It is implemented in the kBET R package and is frequently used to benchmark integration methods like Harmony, Seurat, and scVI. A high kBET acceptance rate, combined with a high cell-type Average Silhouette Width (ASW), provides strong evidence that a batch correction method has successfully removed technical variation while preserving biological signal.

kBET EXPLAINED

Frequently Asked Questions

Clear answers to the most common technical questions about the k-nearest Neighbor Batch Effect Test, a quantitative metric for evaluating batch mixing in integrated single-cell and high-dimensional data.

The k-nearest Neighbor Batch Effect Test (kBET) is a quantitative, statistical metric that evaluates the degree of batch mixing in an integrated dataset by comparing the local batch label distribution in a k-nearest neighbor (kNN) graph to the global batch distribution. It works by selecting a random subset of cells, identifying their k nearest neighbors in a reduced-dimensional space (like PCA), and then performing a chi-squared test on the batch label distribution within that local neighborhood. If the local distribution of batch labels matches the global distribution, the null hypothesis of 'well-mixed' is accepted. The overall kBET score is the fraction of these local tests that accept the null hypothesis, with a score near 1.0 indicating perfect mixing and a score near 0.0 indicating strong batch effects.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.