Utilizing Mechanism-Aware Imputation (MAI)

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.

Installation

The following code chunk depicts how to install MAI from Bioconductor

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

BiocManager::install("MAI")

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 α and β separate high, medium, and low average abundance metabolites, while the parameter γ is used to impose missingness in the medium and low abundance metabolites. A smaller α corresponds to more MCAR/MAR being present, while larger β and γ 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.

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

Session Information

sessionInfo()
## R version 4.4.2 (2024-10-31)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        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: Etc/UTC
## 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.1        GenomeInfoDb_1.43.2        
##  [5] IRanges_2.41.1              S4Vectors_0.45.2           
##  [7] BiocGenerics_0.53.3         generics_0.1.3             
##  [9] MatrixGenerics_1.19.0       matrixStats_1.4.1          
## [11] caret_6.0-94                lattice_0.22-6             
## [13] ggplot2_3.5.1               MAI_1.13.0                 
## [15] 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.4.2          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.29          prodlim_2024.06.25     
## [16] itertools_0.1-3         UCSC.utils_1.3.0        purrr_1.0.2            
## [19] xfun_0.49               randomForest_4.7-1.2    zlibbioc_1.52.0        
## [22] cachem_1.1.0            jsonlite_1.8.9          recipes_1.1.0          
## [25] DelayedArray_0.33.2     parallel_4.4.2          R6_2.5.1               
## [28] bslib_0.8.0             stringi_1.8.4           parallelly_1.39.0      
## [31] rpart_4.1.23            lubridate_1.9.3         jquerylib_0.1.4        
## [34] Rcpp_1.0.13-1           iterators_1.0.14        knitr_1.49             
## [37] future.apply_1.11.3     Matrix_1.7-1            splines_4.4.2          
## [40] nnet_7.3-19             timechange_0.3.0        tidyselect_1.2.1       
## [43] abind_1.4-8             yaml_2.3.10             timeDate_4041.110      
## [46] doParallel_1.0.17       codetools_0.2-20        doRNG_1.8.6            
## [49] listenv_0.9.1           tibble_3.2.1            plyr_1.8.9             
## [52] withr_3.0.2             evaluate_1.0.1          future_1.34.0          
## [55] survival_3.7-0          proxy_0.4-27            pillar_1.9.0           
## [58] BiocManager_1.30.25     rngtools_1.5.2          foreach_1.5.2          
## [61] munsell_0.5.1           scales_1.3.0            globals_0.16.3         
## [64] class_7.3-22            glue_1.8.0              maketools_1.3.1        
## [67] tools_4.4.2             sys_3.4.3               data.table_1.16.2      
## [70] ModelMetrics_1.2.2.2    gower_1.0.1             buildtools_1.0.0       
## [73] grid_4.4.2              missForest_1.5          tidyverse_2.0.0        
## [76] ipred_0.9-15            colorspace_2.1-1        nlme_3.1-166           
## [79] GenomeInfoDbData_1.2.13 cli_3.6.3               fansi_1.0.6            
## [82] S4Arrays_1.7.1          lava_1.8.0              dplyr_1.1.4            
## [85] pcaMethods_1.99.0       gtable_0.3.6            sass_0.4.9             
## [88] digest_0.6.37           SparseArray_1.7.2       htmltools_0.5.8.1      
## [91] lifecycle_1.0.4         hardhat_1.4.0           httr_1.4.7             
## [94] MASS_7.3-61

References

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