1 Introduction

A two-step approach to imputing missing data in metabolomics. Step 1 uses a random forest classifier to classify missing values as either Missing Completely at Random/Missing At Random (MCAR/MAR) or Missing Not At Random (MNAR). MCAR/MAR are combined because it is often difficult to distinguish these two missing types in metabolomics data. Step 2 imputes the missing values based on the classified missing mechanisms, using the appropriate imputation algorithms. Imputation algorithms tested and available for MCAR/MAR include Bayesian Principal Component Analysis (BPCA), Multiple Imputation No-Skip K-Nearest Neighbors (Multi_nsKNN), and Random Forest. Imputation algorithms tested and available for MNAR include nsKNN and a single imputation approach for imputation of metabolites where left-censoring is present.

2 Installation

The following code chunk depicts how to install MAI from Bioconductor

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("MAI")

3 Using MAI when your data is a data.frame or matrix

# Load the MAI package
library(MAI)
# Load the example data with missing values
data("untargeted_LCMS_data")
# Set a seed for reproducibility
## Estimating pattern of missingness involves imposing MCAR/MAR into the data
## these are done at random and as such may slightly change the results of the
## estimated parameters.
set.seed(137690)
# Impute the data using BPCA for predicted MCAR value imputation and
# use Single imputation for predicted MNAR value imputation

Results = MAI(data_miss = untargeted_LCMS_data, # The data with missing values
          MCAR_algorithm = "BPCA", # The MCAR algorithm to use
          MNAR_algorithm = "Single", # The MNAR algorithm to use
          assay_ix = 1, # If SE, designates the assay to impute
          forest_list_args = list( # random forest arguments for training
            ntree = 300,
            proximity = FALSE
        ),
          verbose = TRUE # allows console message output
        )
## Estimating pattern of missingness
## Imposing missingness
## Generating features
## Training
## Predicting
## Imputing
# Get MAI imputations
Results[["Imputed_data"]][1:5, 1:5] # show only 5x5
##          [,1]     [,2]     [,3]     [,4]     [,5]
## [1,] 12.87164 12.70516 12.11793 12.07897 11.18725
## [2,] 12.10813 12.36043 12.08463 12.07897 14.30504
## [3,] 12.10813 11.16815 12.08463 12.07897 11.79195
## [4,] 12.01395 12.28791 12.12017 12.07897 10.05397
## [5,] 11.32825 12.55314 12.23772 11.31292 12.28869
# Get the estimated mixed missingness parameters
Results[["Estimated_Params"]]
## $Alpha
## [1] 20
## 
## $Beta
## [1] 80
## 
## $Gamma
## [1] 60

These parameters estimate the ratio of MCAR/MAR to MNAR in the data. The parameters \(\alpha\) and \(\beta\) separate high, medium, and low average abundance metabolites, while the parameter \(\gamma\) is used to impose missingness in the medium and low abundance metabolites. A smaller \(\alpha\) corresponds to more MCAR/MAR being present, while larger \(\beta\) and \(\gamma\) values imply more MNAR values being present. The returned estimated parameters are then used to impose known missingness in the complete subset of the input data. Subsequently, a random forest classifier is trained to classify the known missingness in the complete subset of the input data. Once the classifier is established it is applied to the unknown missingness of the full input data to predict the missingness. Finally, the missing values are imputed using a specific algorithm, chosen by the user, according to the predicted missingness mechanism.

4 Using MAI when your data is a SummarizedExperiment (SE) class

# Load the SummarizedExperiment package
suppressMessages(
  library(SummarizedExperiment)
)

# Load the example data with missing values
data("untargeted_LCMS_data")
# Turn the data to a SummarizedExperiment
se = SummarizedExperiment(untargeted_LCMS_data)
# Set a seed for reproducibility
## Estimating pattern of missingness involves imposing MCAR/MAR into the data
## these are done at random and as such may slightly change the results of the
## estimated parameters.
set.seed(137690)
# Impute the data using BPCA for predicted MCAR value imputation and
# use Single imputation for predicted MNAR value imputation

Results = MAI(se, # The data with missing values
          MCAR_algorithm = "BPCA", # The MCAR algorithm to use
          MNAR_algorithm= "Single", # The MNAR algorithm to use
          assay_ix = 1, # If SE, designates the assay to impute
          forest_list_args = list( # random forest arguments for training
            ntree = 300,
            proximity = FALSE
        ),
          verbose = TRUE # allows console message output
        )
## Estimating pattern of missingness
## Imposing missingness
## Generating features
## Training
## Predicting
## Imputing
# Get MAI imputations
assay(Results)[1:5, 1:5] # show only 5x5
##          [,1]     [,2]     [,3]     [,4]     [,5]
## [1,] 12.87164 12.70516 12.11793 12.07897 11.18725
## [2,] 12.10813 12.36043 12.08463 12.07897 14.30504
## [3,] 12.10813 11.16815 12.08463 12.07897 11.79195
## [4,] 12.01395 12.28791 12.12017 12.07897 10.05397
## [5,] 11.32825 12.55314 12.23772 11.31292 12.28869
# Get the estimated mixed missingness parameters
metadata(Results)[["meta_assay_1"]][["Estimated_Params"]]
## $Alpha
## [1] 20
## 
## $Beta
## [1] 80
## 
## $Gamma
## [1] 60

5 Session Information

sessionInfo()
## R Under development (unstable) (2024-10-21 r87258)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.21-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] SummarizedExperiment_1.37.0 Biobase_2.67.0             
##  [3] GenomicRanges_1.59.0        GenomeInfoDb_1.43.0        
##  [5] IRanges_2.41.0              S4Vectors_0.45.0           
##  [7] BiocGenerics_0.53.0         MatrixGenerics_1.19.0      
##  [9] matrixStats_1.4.1           caret_6.0-94               
## [11] lattice_0.22-6              ggplot2_3.5.1              
## [13] MAI_1.13.0                  BiocStyle_2.35.0           
## 
## loaded via a namespace (and not attached):
##  [1] pROC_1.18.5             rlang_1.1.4             magrittr_2.0.3         
##  [4] e1071_1.7-16            compiler_4.5.0          vctrs_0.6.5            
##  [7] reshape2_1.4.4          stringr_1.5.1           pkgconfig_2.0.3        
## [10] crayon_1.5.3            fastmap_1.2.0           XVector_0.47.0         
## [13] utf8_1.2.4              rmarkdown_2.28          prodlim_2024.06.25     
## [16] itertools_0.1-3         UCSC.utils_1.3.0        purrr_1.0.2            
## [19] xfun_0.48               randomForest_4.7-1.2    zlibbioc_1.53.0        
## [22] cachem_1.1.0            jsonlite_1.8.9          recipes_1.1.0          
## [25] DelayedArray_0.33.0     parallel_4.5.0          R6_2.5.1               
## [28] bslib_0.8.0             stringi_1.8.4           parallelly_1.38.0      
## [31] rpart_4.1.23            lubridate_1.9.3         jquerylib_0.1.4        
## [34] Rcpp_1.0.13             bookdown_0.41           iterators_1.0.14       
## [37] knitr_1.48              future.apply_1.11.3     Matrix_1.7-1           
## [40] splines_4.5.0           nnet_7.3-19             timechange_0.3.0       
## [43] tidyselect_1.2.1        abind_1.4-8             yaml_2.3.10            
## [46] timeDate_4041.110       doParallel_1.0.17       codetools_0.2-20       
## [49] doRNG_1.8.6             listenv_0.9.1           tibble_3.2.1           
## [52] plyr_1.8.9              withr_3.0.2             evaluate_1.0.1         
## [55] future_1.34.0           survival_3.7-0          proxy_0.4-27           
## [58] pillar_1.9.0            BiocManager_1.30.25     rngtools_1.5.2         
## [61] foreach_1.5.2           generics_0.1.3          munsell_0.5.1          
## [64] scales_1.3.0            globals_0.16.3          class_7.3-22           
## [67] glue_1.8.0              tools_4.5.0             data.table_1.16.2      
## [70] ModelMetrics_1.2.2.2    gower_1.0.1             grid_4.5.0             
## [73] missForest_1.5          tidyverse_2.0.0         ipred_0.9-15           
## [76] colorspace_2.1-1        nlme_3.1-166            GenomeInfoDbData_1.2.13
## [79] cli_3.6.3               fansi_1.0.6             S4Arrays_1.7.0         
## [82] lava_1.8.0              dplyr_1.1.4             pcaMethods_1.99.0      
## [85] gtable_0.3.6            sass_0.4.9              digest_0.6.37          
## [88] SparseArray_1.7.0       htmltools_0.5.8.1       lifecycle_1.0.4        
## [91] hardhat_1.4.0           httr_1.4.7              MASS_7.3-61

6 References

Appendix

Dekermanjian, J.P., Shaddox, E., Nandy, D. et al. Mechanism-aware imputation: a two-step approach in handling missing values in metabolomics. BMC Bioinformatics 23, 179 (2022). https://doi.org/10.1186/s12859-022-04659-1