【发布时间】:2021-10-15 19:14:00
【问题描述】:
我对 MICE 功能有疑问。我有一个包含缺失值的 4500 名参与者的纵向数据集。一些变量是随时间测量的(0、2、3、5 等),但存在缺失值。一些变量是 MAR,因此我试图在考虑到变量随时间变化的性质的情况下估算缺失值。
数据为长格式(我已将 dput(head) 放在下面))
数据被称为“PaParty”
structure(list(id = c(8, 8, 8, 8, 11, 11), mostid = c("M0008",
"M0008", "M0008", "M0008", "M0011", "M0011"), sex = c(1, 1, 1,
1, 0, 0), age = c(69, 69, 69, 69, 64, 64), race = c(1, 1, 1,
1, 1, 1), LeftEyeReplace = c(1, 1, 1, 1,
0, 0), Mnths_L_Replacement = c(9, 9, 9, 9, NA, NA), RightEyeReplace = c(1,
1, 1, 1, 1, 1), Mnths_R_Replacement = c(9, 9, 9, 9, 40, 40
), Time = c("0", "2", "3", "5", "0", "2"), bmi = c(26.79,
29.17, NA, NA, 26.88, 27.38), wototr = c(30, 27, NA, NA,
4, 30), wototl = c(33, 27, NA, NA, 2, 22), menr = c(1, NA,
NA, NA, 0, NA), menl = c(1, NA, NA, NA, NA, NA), KLGLeft = c(4,
NA, NA, NA, 3, 3), KLGRight = c(4, NA, NA, NA, 3, 4)), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
我试图估算的值是针对具有连续分数的变量(0-100 是范围)。
当我运行我的代码时:
Y <- c("wototr", "wototl", "bmi")
meth<-make.method(PaParty)
meth[1:length(meth)]<-""
meth[Y]<-"2l.pan"
pred<-make.predictorMatrix(PaParty)
pred[1:nrow(pred), 1:ncol(pred)]<-0
pred[Y, "id"]<-(-2)
pred[Y, "sex"]<-1
pred[Y, paste("x", 2:9, sep = "")] <- 1
pred[Y[1],Y[2]]<-1
pred[Y[2], Y[1]]<-1
pred[Y[3], Y[1:2]]<-1
imp<-mice(PaParty, meth=meth, pred=pred, m=5,
maxit = 20, seed =500, print=FALSE) completedData <- complete(imp,1)
我得到以下信息:
Error in `[<-`(`*tmp*`, Y, paste("x", 2:9, sep = ""), value = 1) :
subscript out of bounds
并且由此产生的估算数据集包含 wototr 和 wototl 的负值,这是不可能的,因为数据在 0-100 的连续范围内。即使我增加迭代次数也不会改善它。
非常感谢您在这方面的帮助,或者如果有人有其他更好的方法来估算这个纵向数据集。
【问题讨论】:
标签: r imputation r-mice longitudinal