首页 文章

用老鼠的被动插补给出错误的总分

提问于
浏览
1

我正在研究一个包含374个变量的76人的大型数据集 . 我的主要结果变量是抑郁症严重问卷(PHQ-9)的抑郁症总分 . 大约有4%的数据缺失,所以我想使用估算 . 我按照Buuren,S.van,&Groothuis-Oudshoorn,K . (2011)的说明使用鼠标包 . 小鼠:R . 链式方程的多元插补在R. Journal of Statistical Software,45(3) . https://doi.org/10.18637/jss.v045.i03 . 我试图复制他们关于如何使用被动插补来生成sumscores的指令 . 但是,我得到了错误的结果 . 我无法弄清楚为什么 - 我想我已经正确地遵循了指令 .

我无法发布数据,因为它是敏感的,但我能够使用此代码复制错误,这基本上复制了我的原始代码:

library("mice")
library("lattice")
set.seed(1234)
m<-matrix(sample(c(NA, 1:10), 100, replace = T), 10)
df<-as.data.frame(m)

ini<-mice(cbind(df, sumScore=NA), max = 0, print=F)
meth<-ini$method
meth[1:4]<-""
meth[5:10]<-"pmm"
meth["sumScore"]<-"~I(rowSums(df[,5:10]))"
pred<-ini$predictorMatrix
pred[, 1:4]<-0
pred[5:10, "sumScore"]<-0
pred[1:4, "sumScore"]<-1

imp<-mice(cbind(df, sumScore=NA), predictorMatrix = pred, method =  meth)
com<-complete(imp, "long", indlude=T)

我得到以下输出:

.imp .id V1 V2 V3 V4 V5 V6 V7 V8 V9 V10  sumScore
 1    1   1  1  7  3  5  6  1  9  1 10   1   0.9224428
 2    1   2  6  5  3  2  7  3  3  9  5   9   0.6210974
 3    1   3  6  3  1  3  3  7  3  5  1   1   0.3563335
 4    1   4  6 10 NA  5  6  5  5  8  5   1   0.0711464
 5    1   5  9  3  2  1  3  1  2  3  2   1   0.7318026
 6    1   6  7  9  8  8  5  5  7  5  9   5   0.6197897

1 回答

  • 1

    你的预测矩阵搞砸了(我不确定 df 上的 rowSums 是否可以使用 - 我不这么认为,因为 df 指的是原始数据,而不是推算版本) .

    预测矩阵应如下所示:对于每一行,使用哪些变量(列)来预测此变量 . 你的矩阵看起来像这样

    > pred
             V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 sumScore
    V1        0  0  0  0  1  1  1  1  1   0        1
    V2        0  0  0  0  1  1  1  1  1   1        1
    V3        0  0  0  0  1  1  1  1  1   1        1
    V4        0  0  0  0  1  1  1  1  1   1        1
    V5        0  0  0  0  0  1  1  1  1   1        0
    V6        0  0  0  0  1  0  1  1  1   1        0
    V7        0  0  0  0  1  1  0  1  1   1        0
    V8        0  0  0  0  1  1  1  0  1   1        0
    V9        0  0  0  0  1  1  1  1  0   1        0
    V10       0  0  0  0  1  1  1  1  1   0        0
    sumScore  0  0  0  0  0  0  0  0  0   0        0
    

    当一行只包含零时,它不使用任何变量进行插补 . 这意味着没有任何变量真正用于预测 sumScore 并且最终会产生随机噪声 .

    请尝试使用此代码

    library("mice")
    library("lattice")
    set.seed(1234)
    m <- matrix(sample(c(NA, 1:10), 100, replace = TRUE), 10)
    df <- cbind(as.data.frame(m), sumScore=NA)
    
    ini<-mice(df, max = 0, print=FALSE)
    meth<-ini$method
    meth[1:4] <- ""      # Never impute for these variables
    meth[5:10]<-"pmm"    # Use pmm to impute for these
    meth["sumScore"] <- "~I(V5+V6+V7+V8+V9+V10)"
    
    pred <- ini$predictorMatrix
    pred[, 1:4] <- 0    # Never use V1-V4 for imputation (since you had the same)
    pred[1:4, "sumScore"] <- 1  # Use the sum to impute for first 4 (but no method so no point!)
    pred[paste0("V", 5:10), "sumScore"] <- 0  # Make sure that we dont impute the "wrong way"
    pred["sumScore", paste0("V", 5:10)] <- 1  # Make sure that V5 to V10 are available for sumScore
    

    这应该给你你想要的

相关问题