I am trying to perform imputation with MICE on the following dataframe.
marketValue <- c(NA, 234234, NA, 243243, NA, NA, 234523, NA, 232427, 112214)
bathrooms <- c(3,3,2,3,5,4,1,5,6,3)
garageSqFt <- c(400, 385, 454, 534, 210, NA, 342, 423, 535, NA)
totalSqFT <- c(NA, NA, 1231, 2232, 4564, 2122, 4324, 4342, 1299, 4355)
units <- c(1, 1, 1, 1, 1, 1, 1.5, NA, 2, 5)
subDivId <- c("112", "111", "111", "111", "112", "111", "112", "112", "111",
"112")
data <- data.frame(marketValue, bathrooms, garageSqFt, totalSqFT, units,
subDivId)
In the actual data frame there are about 1300 subDivId factor levels and I would like to create new data frames (each of which have rows all with the same subDivId) then impute within each data frame. My attempt
splitSubDiv <- split(data, data$subDivId)
for (neighborhood in splitSubDiv){
testData <- mice(neighborhood, m=5, maxit = 5)
impData <- complete(testData, 5)
str(impData) }
This doesn't seem to work. No imputation is being done, things are still NA. What am I doing Wrong?