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.
Glossary
k-nearest Neighbor Batch Effect Test (kBET)

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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
kBET is a critical diagnostic tool within a larger ecosystem of batch correction algorithms and evaluation metrics. Understanding these related concepts is essential for designing robust multi-batch experimental workflows.
Batch Effect
A systematic non-biological source of variation introduced across different experimental batches. These technical artifacts arise from differences in processing dates, reagents, technicians, or instrumentation.
- Can confound true biological signals if not addressed
- The primary target that kBET is designed to detect
- Often visualized as distinct clustering by batch in PCA plots
Local Inverse Simpson's Index (LISI)
A complementary diversity score computed for each cell's local neighborhood. iLISI quantifies the effective number of different batches present, while cLISI measures cell-type diversity.
- A high iLISI score indicates good batch mixing
- Often used alongside kBET for multi-faceted evaluation
- Provides a continuous, per-cell metric rather than a global acceptance rate
Average Silhouette Width (ASW)
A metric evaluating batch correction by measuring the cohesion of cell-type clusters against the separation of batch labels. Successful integration yields a high cell-type ASW and a low batch ASW.
- Batch ASW near 0 indicates perfect mixing
- Cell-type ASW near 1 indicates preserved biology
- Sensitive to overcorrection artifacts
Mutual Nearest Neighbors (MNN)
A batch correction method that identifies pairs of cells from different batches that are mutual nearest neighbors in high-dimensional expression space. These MNN pairs define a correction vector used to align batches.
- Foundational concept behind many integration algorithms
- Assumes at least partially overlapping cell populations
- kBET can detect residual batch structure after MNN correction
Overcorrection Assessment
The critical process of evaluating whether a batch correction method has removed true biological variation alongside technical noise. Measured by the preservation of known cell-type clusters and the variance explained by biological covariates.
- kBET acceptance rate near 1.0 may indicate overcorrection
- Must be balanced with biological preservation metrics
- Requires ground-truth labels or positive control genes

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us