metabolomics-batch-correction-evaluation
Summary
Evaluate the efficacy of batch correction in metabolomics data by comparing PCA visualizations of uncorrected versus corrected metabolite matrices, assessing whether batch effects are removed while preserving biologically meaningful group structure.
When to use
When you have log2-transformed metabolomics data with known batch assignments and biological groupings, and you need to validate that a batch correction method (such as CordBat) has successfully removed batch-driven variation without collapsing true group differences in metabolite composition.
When NOT to use
- Input metabolite matrix is not log2-transformed or appropriately normalized before batch correction
- Batch and group assignments are missing, mismatched in length to samples, or contain undefined/inconsistent labels
- Biological group structure is absent or homogeneous (no true group effects expected); batch correction evaluation requires group-level signal to preserve
Inputs
- log2-transformed metabolite abundance matrix (rows=samples, columns=metabolites)
- batch assignment vector (matching sample order)
- group assignment vector (matching sample order)
- reference batch label (string)
Outputs
- PCA score data frame for uncorrected data (PC1, PC2, batch, group metadata)
- PCA score data frame for corrected data (PC1, PC2, batch, group metadata)
- ggplot2 visualization objects showing uncorrected vs. corrected PCA space colored by batch
- ggplot2 visualization objects showing uncorrected vs. corrected PCA space colored by group
How to apply
Perform PCA with scaling (scale=TRUE) on the original metabolite matrix and record the PC1/PC2 scores and variance explained. Log2-transform the metabolite matrix, apply CordBat batch correction with appropriate batch vector, group vector, and reference batch specification, then back-transform the corrected matrix (2^corrected_mat). Re-perform PCA on the back-transformed data with scaling and compare PC1/PC2 scores, variance explained, and sample clustering patterns between the two projections. Visualize both PCA spaces side-by-side with ggplot2, coloring points by batch to assess batch mixing and by group to verify group separation is retained. Success is indicated by reduced within-batch variance and improved between-group separation after correction.
Related tools
- CordBat (Applies concordance-based batch effect correction to log2-transformed metabolite matrices with specified batch, group, and reference batch parameters to produce corrected matrix fit$X.cor) — https://github.com/BorchLab/CordBat
- prcomp (Performs scaled principal component analysis on both uncorrected and back-transformed corrected metabolite data to generate comparable PCA score projections for evaluation)
- ggplot2 (Creates side-by-side PCA scatter plots colored by batch and group to visualize the separation and clustering patterns in uncorrected versus corrected metabolomics data)
- dplyr (Combines PCA scores with batch and group metadata into tidy data frames for visualization and downstream comparison)
Examples
fit <- CordBat(X = as.matrix(log2(cordbat_example[, met_cols])), batch = batch_vec, group = group_vec, ref.batch = 'Ref', grouping = FALSE); pca_uncor <- prcomp(cordbat_example[, metabolite_cols], scale. = TRUE); pca_cor <- prcomp(2^fit$X.cor, scale. = TRUE); ggplot(data.frame(pca_uncor$x, batch=batch_vec), aes(x=PC1, y=PC2, color=batch)) + geom_point()
Evaluation signals
- PCA plot colored by batch shows reduced spatial clustering of same-batch samples after correction (batch effects diminished), whereas uncorrected plot shows clear batch-driven separation
- PCA plot colored by group retains or improves group-level separation after correction; group centroids should not collapse or shift adversely
- Within-batch variance (distance among samples labeled with the same batch) decreases after correction; between-group variance (distance among samples in different groups) is maintained or increases
- PC1 and PC2 loadings and variance explained per component show qualitatively different structure between uncorrected and corrected space, with corrected space exhibiting reduced batch-driven PC structure
- No systematic clustering of corrected samples by batch remains visible in the corrected PCA plot, while corrected samples retain identifiable grouping by biological group label
Limitations
- Evaluation is limited to 2D PCA visualization; higher-dimensional batch structure or non-linear batch effects may not be fully apparent in PC1/PC2 space alone
- CordBat correction assumes multiplicative batch effects in log2-space; if batch effects are additive or non-linear in the original scale, correction efficacy may be compromised
- PCA evaluation assumes group signal is sufficiently strong relative to residual noise after correction; weak or subtle group effects may be masked or lost
- Visualization quality depends on having sufficient biological replicates and batch replicates; sparse designs may yield unreliable or misleading PCA patterns
Evidence
- [other] CordBat processes log2-transformed metabolite matrices by applying batch and group corrections, producing a corrected matrix (fit$X.cor) that can be back-transformed and re-projected via PCA: "CordBat processes log2-transformed metabolite matrices by applying batch and group corrections, producing a corrected matrix (fit$X.cor) that can be back-transformed and re-projected via PCA (prcomp"
- [other] Create a data frame combining PCA scores (PC1, PC2) with batch and group metadata, then plot with ggplot2 colored by batch and group to visualize uncorrected data structure.: "Create a data frame combining PCA scores (PC1, PC2) with batch and group metadata, then plot with ggplot2 colored by batch and group to visualize uncorrected data structure."
- [methods] The batch effect is applied as a multiplicative factor to the baseline metabolite values: "The batch effect is applied as a multiplicative factor to the baseline metabolite values"
- [readme] Concordance-Based Batch Effect Correction for Large-Scale Metabolomics: "Concordance-Based Batch Effect Correction for Large-Scale Metabolomics"
- [methods] pca_res <- prcomp(cordbat_example[, metabolite_cols], scale. = TRUE): "pca_res <- prcomp(cordbat_example[, metabolite_cols], scale. = TRUE)"
- [methods] new_pca_res <- prcomp(2^corrected_mat, scale. = TRUE): "new_pca_res <- prcomp(2^corrected_mat, scale. = TRUE)"
1---2name: metabolomics-batch-correction-evaluation3description: Use when when you have log2-transformed metabolomics data with known batch assignments and biological groupings, and you need to validate that a batch correction method (such as CordBat) has successfully removed batch-driven variation without collapsing true group differences in metabolite.4license: CC-BY-4.05---67# metabolomics-batch-correction-evaluation89## Summary1011Evaluate the efficacy of batch correction in metabolomics data by comparing PCA visualizations of uncorrected versus corrected metabolite matrices, assessing whether batch effects are removed while preserving biologically meaningful group structure.1213## When to use1415When you have log2-transformed metabolomics data with known batch assignments and biological groupings, and you need to validate that a batch correction method (such as CordBat) has successfully removed batch-driven variation without collapsing true group differences in metabolite composition.1617## When NOT to use1819- Input metabolite matrix is not log2-transformed or appropriately normalized before batch correction20- Batch and group assignments are missing, mismatched in length to samples, or contain undefined/inconsistent labels21- Biological group structure is absent or homogeneous (no true group effects expected); batch correction evaluation requires group-level signal to preserve2223## Inputs2425- log2-transformed metabolite abundance matrix (rows=samples, columns=metabolites)26- batch assignment vector (matching sample order)27- group assignment vector (matching sample order)28- reference batch label (string)2930## Outputs3132- PCA score data frame for uncorrected data (PC1, PC2, batch, group metadata)33- PCA score data frame for corrected data (PC1, PC2, batch, group metadata)34- ggplot2 visualization objects showing uncorrected vs. corrected PCA space colored by batch35- ggplot2 visualization objects showing uncorrected vs. corrected PCA space colored by group3637## How to apply3839Perform PCA with scaling (scale=TRUE) on the original metabolite matrix and record the PC1/PC2 scores and variance explained. Log2-transform the metabolite matrix, apply CordBat batch correction with appropriate batch vector, group vector, and reference batch specification, then back-transform the corrected matrix (2^corrected_mat). Re-perform PCA on the back-transformed data with scaling and compare PC1/PC2 scores, variance explained, and sample clustering patterns between the two projections. Visualize both PCA spaces side-by-side with ggplot2, coloring points by batch to assess batch mixing and by group to verify group separation is retained. Success is indicated by reduced within-batch variance and improved between-group separation after correction.4041## Related tools4243- **CordBat** (Applies concordance-based batch effect correction to log2-transformed metabolite matrices with specified batch, group, and reference batch parameters to produce corrected matrix fit$X.cor) — https://github.com/BorchLab/CordBat44- **prcomp** (Performs scaled principal component analysis on both uncorrected and back-transformed corrected metabolite data to generate comparable PCA score projections for evaluation)45- **ggplot2** (Creates side-by-side PCA scatter plots colored by batch and group to visualize the separation and clustering patterns in uncorrected versus corrected metabolomics data)46- **dplyr** (Combines PCA scores with batch and group metadata into tidy data frames for visualization and downstream comparison)4748## Examples4950```51fit <- CordBat(X = as.matrix(log2(cordbat_example[, met_cols])), batch = batch_vec, group = group_vec, ref.batch = 'Ref', grouping = FALSE); pca_uncor <- prcomp(cordbat_example[, metabolite_cols], scale. = TRUE); pca_cor <- prcomp(2^fit$X.cor, scale. = TRUE); ggplot(data.frame(pca_uncor$x, batch=batch_vec), aes(x=PC1, y=PC2, color=batch)) + geom_point()52```5354## Evaluation signals5556- PCA plot colored by batch shows reduced spatial clustering of same-batch samples after correction (batch effects diminished), whereas uncorrected plot shows clear batch-driven separation57- PCA plot colored by group retains or improves group-level separation after correction; group centroids should not collapse or shift adversely58- Within-batch variance (distance among samples labeled with the same batch) decreases after correction; between-group variance (distance among samples in different groups) is maintained or increases59- PC1 and PC2 loadings and variance explained per component show qualitatively different structure between uncorrected and corrected space, with corrected space exhibiting reduced batch-driven PC structure60- No systematic clustering of corrected samples by batch remains visible in the corrected PCA plot, while corrected samples retain identifiable grouping by biological group label6162## Limitations6364- Evaluation is limited to 2D PCA visualization; higher-dimensional batch structure or non-linear batch effects may not be fully apparent in PC1/PC2 space alone65- CordBat correction assumes multiplicative batch effects in log2-space; if batch effects are additive or non-linear in the original scale, correction efficacy may be compromised66- PCA evaluation assumes group signal is sufficiently strong relative to residual noise after correction; weak or subtle group effects may be masked or lost67- Visualization quality depends on having sufficient biological replicates and batch replicates; sparse designs may yield unreliable or misleading PCA patterns6869## Evidence7071- [other] CordBat processes log2-transformed metabolite matrices by applying batch and group corrections, producing a corrected matrix (fit$X.cor) that can be back-transformed and re-projected via PCA: "CordBat processes log2-transformed metabolite matrices by applying batch and group corrections, producing a corrected matrix (fit$X.cor) that can be back-transformed and re-projected via PCA (prcomp"72- [other] Create a data frame combining PCA scores (PC1, PC2) with batch and group metadata, then plot with ggplot2 colored by batch and group to visualize uncorrected data structure.: "Create a data frame combining PCA scores (PC1, PC2) with batch and group metadata, then plot with ggplot2 colored by batch and group to visualize uncorrected data structure."73- [methods] The batch effect is applied as a multiplicative factor to the baseline metabolite values: "The batch effect is applied as a multiplicative factor to the baseline metabolite values"74- [readme] Concordance-Based Batch Effect Correction for Large-Scale Metabolomics: "Concordance-Based Batch Effect Correction for Large-Scale Metabolomics"75- [methods] pca_res <- prcomp(cordbat_example[, metabolite_cols], scale. = TRUE): "pca_res <- prcomp(cordbat_example[, metabolite_cols], scale. = TRUE)"76- [methods] new_pca_res <- prcomp(2^corrected_mat, scale. = TRUE): "new_pca_res <- prcomp(2^corrected_mat, scale. = TRUE)"