简体   繁体   English

是否可以重新调整多重插补数据集中的变量(使用鼠标创建)?

[英]Is it possible to relevel a variable within a multiply imputed dataset (created using mice)?

I have performed multiple imputation using the r mice package (m = 50, method = "pmm") on a dataset of randomised controlled trial (RCT) data.我使用 r 小鼠 package (m = 50, method = "pmm")对随机对照试验 (RCT) 数据集进行了多重插补。 I have imputed data for a continuous variable that I am using as a dependent variable in a linear regression model.我已经为我在线性回归 model 中用作因变量的连续变量估算了数据。 Prior to imputation, this variable was a factor with two levels representing the two trial arms of the RCT.在插补之前,该变量是一个具有两个水平的因子,代表 RCT 的两个试验组。 However, the mice package would not let me input factor variables into imputation so I converted it to a character using the as.character function.但是,鼠标 package 不允许我将因子变量输入到插补中,因此我使用 as.character function 将其转换为字符。

When running the regression on the imputed data, I would like the switch the reference level for the continuous variable, however am unsure how to do this.在对估算数据运行回归时,我想切换连续变量的参考水平,但是我不确定如何做到这一点。

My code for the imputation is below:我的插补代码如下:

#impute missing data for wellbeing1yr using MICE package
peermentor$intervention <- as.character(peermentor$intervention)
peermentor$injecting_status <- as.character(peermentor$injecting_status)
imputed_Data <- mice(peermentor, m=50, method = "pmm")
imputefit <- with(data = imputed_Data, expr = lm(wellbeing1yr ~ 
intervention)) 
combine <- pool(imputefit) 
summary(combine)

The two levels for the "intervention" variable are "peer mentoring" and "standard of care". “干预”变量的两个级别是“同伴指导”和“护理标准”。 I would like "standard of care" as the reference level.我想以“护理标准”作为参考水平。

First, you seem not to have specified a predictorMatrix , which means that missing values in whichever covariate in your data.frame will be predicted by all the others, which I would advise against (unless you have clear reasons to do so).首先,您似乎没有指定predictorMatrix ,这意味着data.frame中的任何协变量中的缺失值都将被所有其他人预测,我建议不要这样做(除非您有明确的理由这样做)。

Redefining the levels of your intervention variable can be done after you have completed the multiple imputation.完成多重插补后,可以重新定义干预变量的水平。 Use miceadds::mids2datlist(imputed_Data) to convert the mids object to a list of multiply imputed data sets.使用miceadds::mids2datlist(imputed_Data)mids object 转换为多重插补数据集列表。 You can use this list to make adjustments to covariates and then convert it back to a mids with miceadds::datlist2mids .您可以使用此列表对协变量进行调整,然后使用miceadds::datlist2mids将其转换回mids值。

Since you have not provided example data yet, I will show how this is done via this reprex .由于您尚未提供示例数据,因此我将展示如何通过此reprex完成此操作。

library(mice)
library(miceadds)

# multiply impute missing values
imp <- mice(nhanes, print = FALSE, seed = 123, maxit = 20, m = 10)

# convert mids to datlist
longlist <- complete(imp, 'long')

# make new factor covariate based on values of chl
longlist <- lapply(split(longlist, longlist$.imp), \(x) {
  cbind(x, chl_new = factor(ifelse(x$chl < 185, 1, ifelse(x$chl >= 185 & x$chl < 191.4, 2, 3))))
})

imp_update <- datlist2mids(longlist)

fit <- with(imp_update, lm(age ~ bmi + chl_new))
> summary(pool(fit))
         term   estimate  std.error  statistic        df     p.value
1 (Intercept)  4.2473138 1.24133838  3.4215600  9.298439 0.007254247
2         bmi -0.1115735 0.05033307 -2.2167042  8.278105 0.056377780
3    chl_new2  0.3181516 0.45055559  0.7061317 15.177053 0.490804764
4    chl_new3  0.8243235 0.46964596  1.7552020 11.276793 0.106319297

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM