Skip to content

Commit

Permalink
Pass extra arguments mice.impute.rf() to ranger::ranger()
Browse files Browse the repository at this point in the history
  • Loading branch information
edbonneville committed Jun 28, 2023
1 parent 3f43b9a commit 222df22
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions R/mice.impute.rf.R
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions man/mice.impute.rf.Rd

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

0 comments on commit 222df22

Please sign in to comment.