diff --git a/R/impute.R b/R/impute.R index 5bfd7393..3ecf60bf 100644 --- a/R/impute.R +++ b/R/impute.R @@ -100,10 +100,48 @@ impute <- function(data, comparison = comparison, missingness = missingness, noise = NULL, - method = "ludovic", + method = c("ludovic", "randomforest"), skip_log2_transform_error = FALSE, - retain_columns = NULL) { + retain_columns = NULL, + ...) { noise_missing <- missing(noise) # check if argument noise was provided or not + + if (method == "randomforest"){ + data_wide <- data %>% + tidyr::pivot_wider( + id_cols=sample, + names_from =grouping, + values_from = intensity_log2) %>% + dplyr::select(sample) + + data_wide <- data.frame(lapply(data_wide, function(x) as.numeric(as.character(x)))) + data_imputed_rf <- missForest(data_wide, ...) + + data_imputed <-data_imputed_rf$ximp + data_imputed[sample] <- data %>% + tidyr::pivot_wider( + id_cols = sample, + names_from = grouping, + values_from = intensity_log2) %>% + dplyr::pull(sample) + + data_imputed <- data_imputed %>% + as.data.frame() %>% + tidyr::pivot_longer( + cols = -sample, + names_to = grouping, + values_to = intensity_log2 + ) + + result <- data_imputed %>% + left_join( + synthetic_data %>% + dplyr::select(sample, retain_columns) %>% + distinct(), + by = sample + ) + return(result) + } result <- data %>% dplyr::distinct( {{ sample }},