From 30e766145d2fde97173bf591a420246072e795e3 Mon Sep 17 00:00:00 2001 From: Stef van Buuren Date: Fri, 23 Aug 2024 15:23:22 +0200 Subject: [PATCH] Sample initial levels with replacement (surprising to find this bug after 24 years) --- NEWS.md | 4 ++++ R/initialize.imp.R | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 58cbc9e8e..b94f8f621 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# mice 3.16.14 + +* Fixes a bug during initialization of factor values + # mice 3.16.13 * Adds support for the `literanger` package for `rf` imputation that is about twice as fast as `ranger` (#648). Thanks @stephematician for the contribution. diff --git a/R/initialize.imp.R b/R/initialize.imp.R index 9efb8f4d1..8f9dc75a0 100644 --- a/R/initialize.imp.R +++ b/R/initialize.imp.R @@ -18,7 +18,7 @@ initialize.imp <- function(data, m, ignore, where, blocks, visitSequence, imp[[j]][, i] <- data.init[wy, j] } else { if (is.factor(y)) { - imp[[j]][, i] <- sample(levels(y), nrow(data)) + imp[[j]][, i] <- sample(levels(y), nrow(data), replace = TRUE) } else { imp[[j]][, i] <- rnorm(nrow(data)) }