[英]Individual AUC after multiple imputation using MICE
I have a question about calculating an AUC for every individual in a dataset, after imputation using MICE.我有一个关于在使用 MICE 进行插补后为数据集中的每个人计算 AUC 的问题。
I know how I can do it in a complete cases dataset.我知道如何在完整的案例数据集中做到这一点。 I have done it as follows:
我做了如下:
id <- c(1,2,3,4,5,6,7,8,9,10)
measure_1 <- c(60,80,90,55,60,61,77,67,88,90)
measure_2 <- c(55,88,88,55,70,61,80,66,65,92)
measure_3 <- c(62,88,85,56,68,62,89,62,70,99)
measure_4 <- c(62,90,83,54,65,62,91,59,67,96)
dat <- data.frame(id, measure_1, measure_2, measure_3, measure_4)
dat
x <- c(0,7,14,21) # number of days
library(Bolstad2)
f <- function(a){
Patient <- dat[a,]
vector_patient <- c(Patient[2:5])
AUCpatient <- sintegral(x,vector_patient)$int
return(AUCpatient)
}
vector <- c(1:10)
listAUC <- lapply(vector, f)
vector_AUC <- unlist(listAUC, use.names=FALSE)
vector_AUC
This gave me a vector with all the AUCs for all patients.这给了我一个包含所有患者所有 AUC 的向量。 This vector can be added to my dataset if I want to.
如果我愿意,可以将此向量添加到我的数据集中。
But now I have a problem: I have missings in my dataset.但现在我有一个问题:我的数据集中有缺失。 My dataset can be obtained using the following code:
我的数据集可以使用以下代码获得:
id <- c(1,2,3,4,5,6,7,8,9,10)
measure1 <- c(60,NA,90,55,60,61,77,67,88,90)
measure2 <- c(55,NA,NA,55,70,NA,80,66,65,92)
measure3 <- c(62,88,85,NA,68,62,89,62,70,99)
measure4 <- c(62,90,83,54,NA,62,NA,59,67,96)
datmis <- data.frame(id, measure1, measure2, measure3, measure4)
datmis
I want to impute this dataset using MICE.我想使用 MICE 来估算这个数据集。
library(mice)
imp <- mice(datmis, maxit = 0)
meth <- imp$method
pred <- imp$predictorMatrix
imp <- mice(datmis, method = meth, predictorMatrix = pred, seed = 2018, maxit = 10, m = 5)
So now I have everything imputed.所以现在我已经估算了一切。 I want to create the AUCs for every individual, in every imputed dataset.
我想在每个估算数据集中为每个人创建 AUC。 Then I want to pool the results, resulting in one single AUC for every individual.
然后我想合并结果,为每个人生成一个 AUC。 However, using the formula create in the previous example does not work anymore.
但是,使用前面示例中的公式 create 不再起作用。 Is there someone who can help me out?
有人可以帮助我吗?
Here's one way to do it.这是一种方法。 After you run your imputation you can
在你运行你的插补之后,你可以
The first 2 points are covered with the code below前 2 点被下面的代码覆盖
x <- c(0,7,14,21) # number of days
library("tidyverse")
library("MESS")
res <- lapply(1:5, function(i) {
complete(imp, i) %>%
group_by(id) %>%
mutate(AUC=MESS::auc(x, c(measure1, measure2, measure3, measure4)))})
I'm using the auc
function from the MESS
since that is rather fast and flexible but you could replace it with your version.我正在使用
MESS
的auc
函数,因为它相当快速和灵活,但您可以将其替换为您的版本。
This produces a list of 5 data frames that can be used for pooling the estimates (part 3 from the list above).这会生成一个包含 5 个数据框的列表,可用于合并估计值(上面列表中的第 3 部分)。
library("mitools")
with(imputationList(res), lm(AUC ~ 1)) %>% pool() %>% summary()
This produces这产生
estimate std.error statistic df p.value
(Intercept) 1512.77 81.62359 18.53349 7.389246 1.829668e-07
One more comment regarding the imputation: Are you sure you want to predict the measures using id
as a numeric variable.关于插补的另一条评论:您确定要使用
id
作为数字变量来预测度量吗? That produces a regression-like predictor for the missing variables which seems rather unrealistic.这为缺失的变量产生了一个类似回归的预测器,这似乎很不切实际。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.