首页 文章

即使列中的数据相同,MICE也会进行估算

提问于
浏览
0

即使列中的所有值都相同,是否可以使用MICE包进行插补?那么它只会用这个数字来估算 .

例:

test<-data.frame(var1=c(2.3,2.3,2.3,2.3,2.3,NA),var2=c(5.3,5.6,5.9,6.4,4.5,NA))
miceImp<-mice(test)
testImp<-complete(miceImp)

仅限于var2 . 我想用2.3替换var1中的NA .

1 回答

  • 1

    您可以使用被动插补 . 有关完整说明,请参见this article第25页的第3.4节 . 应用于常量变量时,此处的目标是将任何常量变量 x 的插补方法设置为 x 的常量值 . 如果 x 的常量值为 y ,则 x 的插补方法应为 "~I(y)" .

    test = data.frame(
      var1=c(2.3,2.3,2.3,2.3,2.3,NA,2.3), 
      var2=c(5.3,5.6,5.9,6.4,4.5,5.1,NA), 
      var3=c(NA,1:6))
    cVars = which(sapply(test,sd,na.rm=T)==0) #determine which vars are constant (props to SimonG)
    allMeans = colMeans(test,na.rm=T) #get the column means
    miceImp.ini = mice(test,maxit=0,print=F) #initial mids object with no imputations
    meth = miceImp.ini$method #extract the imputation method vector
    meth[cVars] = paste0("~I(",allMeans[cVars],")") #set the imputation method to be a constant (the current column mean)
    miceImp = mice(test,method=meth) #run the imputation with the user defined imputation methods
    testImp = complete(miceImp) #extract an imputedly complete dataset
    View(testImp) #take a look at it
    

    总而言之,常量值在统计中往往不是很有用,因此在插补之前删除任何常量变量可能更有效(因为插补是一个非常昂贵的过程) .

相关问题