From 222df2245d0fccc286741795017e2a2c81488a14 Mon Sep 17 00:00:00 2001 From: efbonneville Date: Wed, 28 Jun 2023 21:28:02 +0200 Subject: [PATCH] Pass extra arguments mice.impute.rf() to ranger::ranger() --- R/mice.impute.rf.R | 11 ++++++++--- man/mice.impute.rf.Rd | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/R/mice.impute.rf.R b/R/mice.impute.rf.R index 9fb8e317..6d695f4a 100644 --- a/R/mice.impute.rf.R +++ b/R/mice.impute.rf.R @@ -10,8 +10,8 @@ #' alternative currently implemented is the \code{randomForest} package, which #' used to be the default in mice 3.13.10 and earlier. #' @param \dots Other named arguments passed down to -#' \code{mice:::install.on.demand()}, \code{randomForest::randomForest()} and -#' \code{randomForest:::randomForest.default()}. +#' \code{mice:::install.on.demand()}, \code{randomForest::randomForest()}, +#' \code{randomForest:::randomForest.default()}, and \code{ranger::ranger()}. #' @return Vector with imputed data, same type as \code{y}, and of length #' \code{sum(wy)} #' @details @@ -106,7 +106,12 @@ mice.impute.rf <- function(y, ry, x, wy = NULL, ntree = 10, install.on.demand("ranger", ...) # Fit all trees at once - fit <- ranger::ranger(x = xobs, y = yobs, num.trees = ntree) + extra_ranger_args <- list(...) + extra_ranger_args[["type"]] <- NULL # avoids unused argument warnings + fit <- do.call( + what = ranger::ranger, + args = c(list("x" = xobs, "y" = yobs, "num.trees" = ntree), extra_ranger_args) + ) nodes <- predict( object = fit, data = rbind(xobs, xmis), diff --git a/man/mice.impute.rf.Rd b/man/mice.impute.rf.Rd index e153d1a2..47a28ea5 100644 --- a/man/mice.impute.rf.Rd +++ b/man/mice.impute.rf.Rd @@ -36,8 +36,8 @@ alternative currently implemented is the \code{randomForest} package, which used to be the default in mice 3.13.10 and earlier.} \item{\dots}{Other named arguments passed down to -\code{mice:::install.on.demand()}, \code{randomForest::randomForest()} and -\code{randomForest:::randomForest.default()}.} +\code{mice:::install.on.demand()}, \code{randomForest::randomForest()}, +\code{randomForest:::randomForest.default()}, and \code{ranger::ranger()}.} } \value{ Vector with imputed data, same type as \code{y}, and of length