Skip to content

Commit

Permalink
Add short-circuit for literanger donors
Browse files Browse the repository at this point in the history
  • Loading branch information
stephematician committed Jun 17, 2024
1 parent e38e617 commit 8c5a138
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions R/mice.impute.rf.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ mice.impute.rf <- function(y, ry, x, wy = NULL, ntree = 10,

forest <- f(xobs, xmis, yobs, ntree, ...)

# Short-circuit when using literanger interface
if (rfPackage == "literanger") return(forest)
# Sample from donors
if (nmis == 1) forest <- array(forest, dim = c(1, ntree))
apply(forest, MARGIN = 1, FUN = function(s) sample(unlist(s), 1))
Expand Down Expand Up @@ -142,9 +144,5 @@ mice.impute.rf <- function(y, ry, x, wy = NULL, ntree = 10,
fit <- do.call(
literanger::train, c(list(x = xobs, y = yobs, n_tree = ntree), dots)
)
values <- predict(
object = fit, newdata = xmis,
prediction_type = "inbag"
)$values
array(values, dim = c(nrow(xmis), 1L))
predict(object = fit, newdata = xmis, prediction_type = "inbag")$values
}

0 comments on commit 8c5a138

Please sign in to comment.