以下で何が起こっていますか?
#create some data
library(data.table)
library(mice)
myData = data.table(invisible.covariate=rnorm(10),
visible.covariate=rnorm(10),
category=factor(sample(1:3,10, replace=TRUE)),
treatment=sample(0:1,10, replace=TRUE))
myData[,outcome:=invisible.covariate+visible.covariate+treatment*as.integer(category)]
myData[,invisible.covariate:=NULL]
myData[treatment == 0,untreated.outcome:=outcome]
myData[treatment == 1,treated.outcome:=outcome]
#impute missing values
myPredictors = matrix(0,ncol(myData),ncol(myData))
myPredictors[5,] = c(1,1,0,0,0,0)
myPredictors[6,] = c(1,1,0,0,0,0)
myImp = mice(myData,predictorMatrix=myPredictors)
#Now look at the "complete" data
completeData = data.table(complete(myImp,0))
print(nrow(completeData[is.na(untreated.outcome)]))
マウスがすべての NA 値を正常に置き換えた場合、結果は 0 になります。しかし、そうではありません。私は何を間違っていますか?