log-transformation-preprocessing
Summary
Apply optional logarithmic transformation to peak intensity vectors in LC/GC-MS metabolomics data to stabilize variance and improve normality before batch correction. This preprocessing step is toggled conditionally based on data characteristics and is typically paired with Pareto scaling for robust QC-based batch effect attenuation.
When to use
Apply log transformation when peak intensity distributions are right-skewed with heteroscedastic variance (intensity-dependent noise), particularly in QC-based batch correction workflows where variance stabilization improves the effectiveness of subsequent Pareto scaling normalization. Use the log toggle parameter to enable transformation only when justified by data distribution analysis.
When NOT to use
- Input contains zero or negative intensities without pseudocount addition (log undefined for x ≤ 0).
- Data is already on log scale or has been previously log-transformed (double transformation introduces bias).
- Intensity distribution is approximately normal or left-skewed; log transformation is unnecessary and may degrade statistical power.
Inputs
- peak intensity matrix (features × samples, numeric)
- log_toggle parameter (Boolean: TRUE to apply log transformation, FALSE to skip)
- optional: QC sample indices for batch effect assessment
Outputs
- log-transformed peak intensity matrix (same dimensions as input, if log_toggle=TRUE)
- original peak intensity matrix (if log_toggle=FALSE)
How to apply
Load a peak intensity matrix (feature × sample) and determine whether log transformation is appropriate by inspecting the intensity distribution for right-skew and variance heterogeneity. If justified, apply the transformation with a log toggle parameter enabled in the bcpareto() function. The transformation is applied to the entire peak vector before Pareto scaling normalization, which divides each feature by the square root of its QC standard deviation. The log step precedes QC mean subtraction and Pareto division, ensuring that the subsequent normalization operates on log-scale intensities. Evaluate the result by checking that normalized intensities are approximately normally distributed and that batch effects (systematic intensity shifts across QC replicates) are attenuated without introducing artificial structure.
Related tools
- bcpareto (QC-based batch correction method that accepts the log-transformed peak vector and applies Pareto scaling normalization) — https://github.com/yufree/mzrtsim
- mzrtsim (R package providing bcpareto() function and simulated LC/GC-MS feature tables for testing log-transformation and batch correction workflows) — https://github.com/yufree/mzrtsim
- R (Programming language environment for implementing log transformation and batch correction functions)
Examples
# In R, load mzrtsim and apply log-transformed batch correction:
library(mzrtsim)
data(peakdata)
result <- bcpareto(peak = peakdata$intensity_matrix, qc_idx = peakdata$qc_samples, log = TRUE)
Evaluation signals
- Log-transformed intensities are approximately normally distributed (Q-Q plot or Shapiro-Wilk p > 0.05 when applicable).
- Variance is homogeneous across the intensity range (Levene's test or visual inspection of residual plot after Pareto scaling).
- QC sample replicates cluster tightly in PCA or UMAP after log transformation and Pareto normalization, indicating batch effects have been attenuated.
- Batch-corrected feature intensities show no systematic relationship between intensity magnitude and residual batch effect (independence of variance and mean).
- Comparison of feature recovery or fold-change estimates with/without log transformation shows improved consistency with known biological differences when transformation is applied.
Limitations
- Log transformation requires strictly positive intensities; zero values must be replaced with a pseudocount (e.g., half the detection limit) or the feature excluded.
- Log transformation is irreversible without reversing the exponential; downstream interpretation of feature abundances must account for this if back-transformation is desired.
- Over-transformation can occur if data are already moderately normal; unnecessary log transformation may suppress true subtle biological differences in low-abundance features.
- The choice to apply log transformation is user-specified via toggle parameter; no automated decision rule is provided, requiring domain expertise or exploratory data analysis.
Evidence
- [other] Apply optional log transformation to the peak vector if the log toggle parameter is enabled.: "Apply optional log transformation to the peak vector if the log toggle parameter is enabled."
- [other] Normalize each feature by subtracting its QC mean and dividing by the square root of its QC standard deviation (Pareto scaling).: "Normalize each feature by subtracting its QC mean and dividing by the square root of its QC standard deviation (Pareto scaling)."
- [other] bcpareto() is a QC-based batch correction method that accepts a peak vector, QC sample vector, and a log toggle parameter to apply Pareto scaling normalization.: "bcpareto() is a QC-based batch correction method that accepts a peak vector, QC sample vector, and a log toggle parameter"
- [intro] Available methods:
bccenter, bcscaling, bcpareto, bcrange, bcvast, bclevel.: "Available methods: bccenter, bcscaling, bcpareto, bcrange, bcvast, bclevel."
- [intro]
mzrtsim() generates feature tables with controlled condition and batch effects for benchmarking normalisation and batch correction methods.: "mzrtsim() generates feature tables with controlled condition and batch effects for benchmarking normalisation and batch correction methods."
1---2name: log-transformation-preprocessing3description: Use when apply log transformation when peak intensity distributions are right-skewed with heteroscedastic variance (intensity-dependent noise), particularly in QC-based batch correction workflows where variance stabilization improves the effectiveness of subsequent Pareto scaling normalization.4license: CC-BY-4.05---67# log-transformation-preprocessing89## Summary1011Apply optional logarithmic transformation to peak intensity vectors in LC/GC-MS metabolomics data to stabilize variance and improve normality before batch correction. This preprocessing step is toggled conditionally based on data characteristics and is typically paired with Pareto scaling for robust QC-based batch effect attenuation.1213## When to use1415Apply log transformation when peak intensity distributions are right-skewed with heteroscedastic variance (intensity-dependent noise), particularly in QC-based batch correction workflows where variance stabilization improves the effectiveness of subsequent Pareto scaling normalization. Use the log toggle parameter to enable transformation only when justified by data distribution analysis.1617## When NOT to use1819- Input contains zero or negative intensities without pseudocount addition (log undefined for x ≤ 0).20- Data is already on log scale or has been previously log-transformed (double transformation introduces bias).21- Intensity distribution is approximately normal or left-skewed; log transformation is unnecessary and may degrade statistical power.2223## Inputs2425- peak intensity matrix (features × samples, numeric)26- log_toggle parameter (Boolean: TRUE to apply log transformation, FALSE to skip)27- optional: QC sample indices for batch effect assessment2829## Outputs3031- log-transformed peak intensity matrix (same dimensions as input, if log_toggle=TRUE)32- original peak intensity matrix (if log_toggle=FALSE)3334## How to apply3536Load a peak intensity matrix (feature × sample) and determine whether log transformation is appropriate by inspecting the intensity distribution for right-skew and variance heterogeneity. If justified, apply the transformation with a log toggle parameter enabled in the bcpareto() function. The transformation is applied to the entire peak vector before Pareto scaling normalization, which divides each feature by the square root of its QC standard deviation. The log step precedes QC mean subtraction and Pareto division, ensuring that the subsequent normalization operates on log-scale intensities. Evaluate the result by checking that normalized intensities are approximately normally distributed and that batch effects (systematic intensity shifts across QC replicates) are attenuated without introducing artificial structure.3738## Related tools3940- **bcpareto** (QC-based batch correction method that accepts the log-transformed peak vector and applies Pareto scaling normalization) — https://github.com/yufree/mzrtsim41- **mzrtsim** (R package providing bcpareto() function and simulated LC/GC-MS feature tables for testing log-transformation and batch correction workflows) — https://github.com/yufree/mzrtsim42- **R** (Programming language environment for implementing log transformation and batch correction functions)4344## Examples4546```47# In R, load mzrtsim and apply log-transformed batch correction:48library(mzrtsim)49data(peakdata)50result <- bcpareto(peak = peakdata$intensity_matrix, qc_idx = peakdata$qc_samples, log = TRUE)51```5253## Evaluation signals5455- Log-transformed intensities are approximately normally distributed (Q-Q plot or Shapiro-Wilk p > 0.05 when applicable).56- Variance is homogeneous across the intensity range (Levene's test or visual inspection of residual plot after Pareto scaling).57- QC sample replicates cluster tightly in PCA or UMAP after log transformation and Pareto normalization, indicating batch effects have been attenuated.58- Batch-corrected feature intensities show no systematic relationship between intensity magnitude and residual batch effect (independence of variance and mean).59- Comparison of feature recovery or fold-change estimates with/without log transformation shows improved consistency with known biological differences when transformation is applied.6061## Limitations6263- Log transformation requires strictly positive intensities; zero values must be replaced with a pseudocount (e.g., half the detection limit) or the feature excluded.64- Log transformation is irreversible without reversing the exponential; downstream interpretation of feature abundances must account for this if back-transformation is desired.65- Over-transformation can occur if data are already moderately normal; unnecessary log transformation may suppress true subtle biological differences in low-abundance features.66- The choice to apply log transformation is user-specified via toggle parameter; no automated decision rule is provided, requiring domain expertise or exploratory data analysis.6768## Evidence6970- [other] Apply optional log transformation to the peak vector if the log toggle parameter is enabled.: "Apply optional log transformation to the peak vector if the log toggle parameter is enabled."71- [other] Normalize each feature by subtracting its QC mean and dividing by the square root of its QC standard deviation (Pareto scaling).: "Normalize each feature by subtracting its QC mean and dividing by the square root of its QC standard deviation (Pareto scaling)."72- [other] bcpareto() is a QC-based batch correction method that accepts a peak vector, QC sample vector, and a log toggle parameter to apply Pareto scaling normalization.: "bcpareto() is a QC-based batch correction method that accepts a peak vector, QC sample vector, and a log toggle parameter"73- [intro] Available methods: `bccenter`, `bcscaling`, `bcpareto`, `bcrange`, `bcvast`, `bclevel`.: "Available methods: `bccenter`, `bcscaling`, `bcpareto`, `bcrange`, `bcvast`, `bclevel`."74- [intro] `mzrtsim()` generates feature tables with controlled condition and batch effects for benchmarking normalisation and batch correction methods.: "`mzrtsim()` generates feature tables with controlled condition and batch effects for benchmarking normalisation and batch correction methods."