Skip to content

Commit

Permalink
Merge pull request #1 from michbur/main
Browse files Browse the repository at this point in the history
  • Loading branch information
KrystynaGrzesiak authored Mar 3, 2023
2 parents 13ec889 + 2fe3f1c commit a6c161b
Show file tree
Hide file tree
Showing 8 changed files with 1,376 additions and 8 deletions.
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Author: c(
role = c("cre", "ctb")),
person("Dominik Nowakowski",
email = "[email protected]",
comment = c(ORCID = ""),
comment = c(ORCID = "0000-0002-3515-4320"),
role = c("cre", "ctb")),
person("Jaroslaw", "Chilimoniuk",
email = "[email protected]",
Expand Down Expand Up @@ -42,6 +42,8 @@ Imports:
Hmisc,
impute,
imputeLCMD,
MAI,
MetabImpute,
methods,
mi,
mice,
Expand All @@ -52,7 +54,8 @@ Imports:
shiny,
softImpute,
stats,
utils
utils,
VIM
Suggests:
knitr,
testthat,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(impute_KNNEuc)
export(impute_MetabImpute)
export(impute_PEMM)
export(impute_amelia)
export(impute_areg)
Expand All @@ -19,12 +21,14 @@ export(impute_missmda_reg)
export(impute_mle)
export(impute_nipals)
export(impute_nlpca)
export(impute_nsKNN)
export(impute_ppca)
export(impute_qrilc)
export(impute_random)
export(impute_softimpute)
export(impute_svd)
export(impute_twlsa)
export(impute_vim_knn)
export(impute_zero)
export(imputomics_gui)
importFrom(graphics,par)
Expand Down
100 changes: 100 additions & 0 deletions R/imputing.R
Original file line number Diff line number Diff line change
Expand Up @@ -711,3 +711,103 @@ impute_gsimp <- function(missing_data_set) {
imputed <- GS_impute_clean(missing_data_set, initial = "lsym", imp_model='glmnet_pred')
imputed[["data_imp"]]
}

#' \strong{kNN} imputation.
#'
#' K Nearest Neighbors.
#'
#' A function to replace \code{NA} in the data frame by [VIM::kNN()].
#'
#' @template param_missing_ds
#' @returns A \code{data.frame} with imputed values by [VIM::kNN()].
#' @export
#' @seealso [VIM::kNN()]
#' @examples
#' \dontrun{
#' idf <- data.frame(values1 = rep(c(11, 22, NA, 44, NA), 10),
#' values2 = rep(c(21, 32, 48, NA, 59), 10),
#' values3 = rep(c(37, NA, 33, 44, 32), 10))
#' impute_vim_knn(idf)
#' }
#'
impute_vim_knn <- function(missing_data_set) {
imputed <- VIM::kNN(missing_data_set, k = 10)[,1:ncol(missing_data_set)]
data.frame(imputed)
}

#' \strong{MetabImpute} imputation.
#'
#' A function to replace \code{NA} in the data frame by [MetabImpute::Impute()] or [MetabImpute::imputeMulti()].
#'
#' @template param_missing_ds
#' @param method Imputation method for mice. One or vector of RF, BPCA, QRILC,
#' GSIMP, RHM, RMEAN, RMEDIAN, RMIN, RZERO, RRF, RGSIMP, RQRILC, RBPCA, min,
#' halfmin, mean, median, zero
#' @returns A \code{data.frame} with imputed values by [MetabImpute::Impute()] or [MetabImpute::imputeMulti()].
#' @export
#' @seealso [MetabImpute::Impute()], [MetabImpute::imputeMulti()]]
#' @examples
#' \dontrun{
#' idf <- runif(100)
#' idf[sample(1L:100, round(4, 0))] <- NA
#' idf <- data.frame(matrix(idf, nrow = 10))
#' impute_MetabImpute(idf, method = "median")
#' impute_MetabImpute(idf, method = c("median", "RF"))
#' }
#'
impute_MetabImpute <- function(missing_data_set, method) {
if(length(method) > 1){
imputed <- MetabImpute::imputeMulti(data = missing_data_set,
methods = method, reps = 5, local = TRUE)
imputed
}else{
imputed <- MetabImpute::Impute(data = missing_data_set, method = method,
reps = 5, local = TRUE)
data.frame(imputed)
}
}

#' \strong{MA} imputation.
#'
#' Mechanism-Aware imputation
#'
#' A function to replace \code{NA} in the data frame by [MAI::MAI()].
#'
#' @template param_missing_ds
#' @returns A \code{data.frame} with imputed values by [MAI::MAI()].
#' @export
#' @seealso [MAI::MAI()]
#' @examples
#' \dontrun{
#' idf <- matrix(rnorm(10000), ncol = 50)
#' idf[runif(10000) < 0.1] <- NA
#' impute_nsKNN(idf)
#' }
#'
impute_nsKNN <- function(missing_data_set) {
imputed <- MAI::MAI(missing_data_set, MCAR_algorithm = 'Multi_nsKNN',
MNAR_algorithm = 'nsKNN')
data.frame(imputed[["Imputed_data"]])
}

#' \strong{kNN-Euclidean} imputation.
#'
#' A function to replace \code{NA} in the data frame based on
#' \emph{Jasmit S. Shah (https://doi.org/10.1186/s12859-017-1547-6)}.
#'
#' @template param_missing_ds
#' @returns A \code{data.frame} with imputed values by kNN-Euclidean imputation.
#' @export
#' @seealso \emph{Jasmit S. Shah (https://doi.org/10.1186/s12859-017-1547-6)}
#' @examples
#' \dontrun{
#' idf <- matrix(rnorm(10000), ncol = 50)
#' idf[runif(10000) < 0.1] <- NA
#' impute_KNNEuc(idf)
#' }
#'
impute_KNNEuc <- function(missing_data_set) {
imputed <- KNNEuc(as.matrix(missing_data_set), k = ceiling(nrow(missing_data_set)*0.05) + 1,
rm.na = TRUE, rm.nan = TRUE, rm.inf = TRUE)
data.frame(imputed)
}
29 changes: 29 additions & 0 deletions man/impute_KNNEuc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/impute_MetabImpute.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions man/impute_nsKNN.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions man/impute_vim_knn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a6c161b

Please sign in to comment.