Skip to content

Commit

Permalink
add randomforest
Browse files Browse the repository at this point in the history
  • Loading branch information
elena-krismer committed Sep 24, 2024
1 parent 645ce60 commit 3feb11f
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions R/impute.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 }},
Expand Down

0 comments on commit 3feb11f

Please sign in to comment.