R中的MICE包:被动插补

时间:2017-03-24 14:46:58

标签: r

我的目标是通过多次插补来处理缺失值,然后使用混合线性模型进行分析。

对于" BMI"我是被动插补的。 (体重指数)和" BMI类别"。 " BMI"通过身高和体重计算,然后分类为" BMI类别"。

如何归因于BMI类别'?

数据库如下所示:

 sub_eu_surf[1:5, 3:12]

    age gender smoking exercise education sbp dbp height weight      bmi
    1  41      1       1        2        18 120  80    185    107 31.26370
    2  46      1       3        2        18 130  70    182    102 30.79338
    3  46      1       3        2        18 130  70    182    102 30.79338
    4  47      1       1        2        14 130  80    178     78 24.61810
    5  47      1       1        1        14 150  80    175     85 27.75510

因为' bmi类别'不是我估算的预测因素,我决定在估算之后创造它。详情如下:
1.定义方法和预测器

ini<-mice(sub_eu_surf, maxit=0)
meth<-ini$meth
meth["bmi"]<-"~I(weight/(height/100)^2)"

pred <- ini$predictorMatrix
pred[c("pm25_global", "pm25_eu", "pm10_eu", "no2_eu"),  ]<-0 
pred[,c("bmi", "hba1c", "pm25_eu", "pm10_eu")]<-0
pred[,"tc"]<-0
pred[c("smoking", "exercise", "hdl", "glucose"), "tc"]<-1
pred[c("smoking", "exercise", "hdl", "glucose"), "ldl"]<-0
vis <- ini$vis
imp_eu<-mice(sub_eu_surf, meth=meth, pred=pred, vis=vis, seed=200, print=F, m=5, maxit=5)
long_eu<- complete(imp_eu, "long", include=TRUE)
long_eu$bmi_category<-cut(as.numeric(long_eu$bmi), breaks=c(0, 18.5, 25, 30, 72))
complete_eu<-as.mids(long_eu)

但在分析我的数据时收到错误:

    test1<-with(imp_eu, lme(sbp~pm25_global+gender+age+education+bmi_category, random=~1|centre))
    Error in eval(expr, envir, enclos) : object 'bmi_category' not found

这是怎么发生的?

1 个答案:

答案 0 :(得分:0)

您正在原始mids对象imp_eu上运行分析,而不是在修改后的complete_eu上运行。尝试:

test1<-with(complete_eu, lme(sbp~pm25_global+gender+age+education+bmi_category, random=~1|centre))
相关问题