This is not a direct answer to your question, and I don't have enough reputation to comment, but one thing you can do is use the Machine Learning in R package. There are many random forest learner implementations there that can use data with missing values. You can also tune the learners based on what your dataset is.
Links to the package and documentation are on the main tutorial page, here:
https://mlr-org.github.io/mlr-tutorial/release/html/index.html
Also, consider that answering your question becomes much easier if you provide a sample of your dataset.
If you need a direct answer, looping a series of RF calls on the imputed datasets might work. E.g. if you have five imputations:
res = data.frame(matrix(0,nrow=nrow(test),ncol=5)
for (i in 1:5){
data = complete(miceResult, 1)
rf.res = cforest(data,formula ~ [which formula?])
res[,i] = predict(rf.res, test)
}
Then you can pool the results by majority voting or averaging, depending on your dataset. You can also group the 5 imputations together and train the learner with the combined dataset. Both methods are suboptimal, however.
Hope this helps.
I suggest to impute in 2 steps. Impute Condition first and then impute Dependent1-3 for the subset of Condition = Yes.
# I extended your data a bit, to get more cases.
TestData <- data.frame(Condition= c(1,1,1,1,2,NA,2,2, sample(1:2, 500, 1)),
Dependent1=c(1,NA,2,3,NA,NA,NA,NA, sample(1:3, 500, 1)),
Dependent2=c(1,12,44,1,NA,NA,NA,NA, sample(1:44, 500, 1)),
Dependent3=c(NA,2,3,5,NA,NA,NA,NA, sample(1:5, 500, 1)),
UnaffiliatedQ=c(1,NA,3,2,27,NA,32,35, sample(1:35, 500, 1)))
TestData[10:25, 1:4] <- NA
TestData$Condition <- factor(TestData$Condition,
levels = c(1,2),
labels = c("Yes","No"))
library("mice")
# Step 1: Imputation of condition
imp <- mice(TestData[ , c(1, 5)], m = 1)
data_imp <- complete(imp)
TestData$Condition <- as.factor(as.character(data_imp$Condition))
TestData$UnaffiliatedQ <- as.numeric(data_imp$UnaffiliatedQ)
# Subset of TestData (Condition == Yes)
TestData_sub <- TestData[TestData$Condition == "Yes", ]
# Step 2: Imputation of Dependent1-3
imp_2 <- mice(TestData_sub, m = 1)
data_imp_2 <- complete(imp_2)
TestData$Dependent1[TestData$Condition == "Yes"] <- as.numeric(data_imp_2$Dependent1)
TestData$Dependent2[TestData$Condition == "Yes"] <- as.numeric(data_imp_2$Dependent2)
TestData$Dependent3[TestData$Condition == "Yes"] <- as.numeric(data_imp_2$Dependent3)
Best Answer
You can impute interaction terms using MICE. You must first impute the components, and then use passive imputation to derive the interaction term directly from its components. This preserves the relationship between the interaction and its components for each observation.
For more detail on how to do this, see this source: https://www.jstatsoft.org/article/view/v045i03