I'm using library(mice)
to impute missing data. I want a way to tell mice
that the ID variables should be included on the imputed data set but not used for the imputations.
For instance
#making a silly data frame with missing data
library(tidyverse)
library(magrittr)
library(mice)
d1 <- data.frame(
id = str_c(
letters[1:20] %>%
rep(each = 5),
1:5 %>%
rep(times = 20)
),
v1 = runif(100),
v2 = runif(100),
v3 = runif(100)
)
d1[, -1] %<>%
map(
function(i){
i[extract(sample(1:100, 5, F))] <- NA
i
}
)
This is the returned mids
object
m1 <- d1 %>%
select(-id) %>%
mice
How can I include d1$id
as a variable in in each of the imputed data frames?