MAI 1.10.0
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.
The following code chunk depicts how to install MAI from Bioconductor
# 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
## [,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
## $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.
# 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
## [,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
## R version 4.4.0 beta (2024-04-15 r86425)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.4 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.19-bioc/R/lib/libRblas.so
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [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.34.0 Biobase_2.64.0
## [3] GenomicRanges_1.56.0 GenomeInfoDb_1.40.0
## [5] IRanges_2.38.0 S4Vectors_0.42.0
## [7] BiocGenerics_0.50.0 MatrixGenerics_1.16.0
## [9] matrixStats_1.3.0 caret_6.0-94
## [11] lattice_0.22-6 ggplot2_3.5.1
## [13] MAI_1.10.0 BiocStyle_2.32.0
##
## loaded via a namespace (and not attached):
## [1] pROC_1.18.5 rlang_1.1.3 magrittr_2.0.3
## [4] e1071_1.7-14 compiler_4.4.0 vctrs_0.6.5
## [7] reshape2_1.4.4 stringr_1.5.1 pkgconfig_2.0.3
## [10] crayon_1.5.2 fastmap_1.1.1 XVector_0.44.0
## [13] utf8_1.2.4 rmarkdown_2.26 prodlim_2023.08.28
## [16] itertools_0.1-3 UCSC.utils_1.0.0 purrr_1.0.2
## [19] xfun_0.43 randomForest_4.7-1.1 zlibbioc_1.50.0
## [22] cachem_1.0.8 jsonlite_1.8.8 recipes_1.0.10
## [25] DelayedArray_0.30.0 parallel_4.4.0 R6_2.5.1
## [28] bslib_0.7.0 stringi_1.8.3 parallelly_1.37.1
## [31] rpart_4.1.23 lubridate_1.9.3 jquerylib_0.1.4
## [34] Rcpp_1.0.12 bookdown_0.39 iterators_1.0.14
## [37] knitr_1.46 future.apply_1.11.2 Matrix_1.7-0
## [40] splines_4.4.0 nnet_7.3-19 timechange_0.3.0
## [43] tidyselect_1.2.1 abind_1.4-5 yaml_2.3.8
## [46] timeDate_4032.109 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.0 evaluate_0.23
## [55] future_1.33.2 survival_3.6-4 proxy_0.4-27
## [58] pillar_1.9.0 BiocManager_1.30.22 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.7.0 tools_4.4.0 data.table_1.15.4
## [70] ModelMetrics_1.2.2.2 gower_1.0.1 grid_4.4.0
## [73] missForest_1.5 tidyverse_2.0.0 ipred_0.9-14
## [76] colorspace_2.1-0 nlme_3.1-164 GenomeInfoDbData_1.2.12
## [79] cli_3.6.2 fansi_1.0.6 S4Arrays_1.4.0
## [82] lava_1.8.0 dplyr_1.1.4 pcaMethods_1.96.0
## [85] gtable_0.3.5 sass_0.4.9 digest_0.6.35
## [88] SparseArray_1.4.0 htmltools_0.5.8.1 lifecycle_1.0.4
## [91] hardhat_1.3.1 httr_1.4.7 MASS_7.3-60.2
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