使用估算数据集的svydesign错误 [英] Error with svydesign using imputed data sets
问题描述
我正在使用svydesign分析估算的数据集,但出现错误.下面是代码:
I am analyzing an imputed dataset using svydesign but I am getting an error. Below is the code:
library(mitools)
library(survey)
data(nhanes)
nhanes$hyp <- as.factor(nhanes$hyp)
imp <- mice(nhanes,method=c("polyreg","pmm","logreg","pmm"), seed = 23109)
des<-svydesign(id=~1, strat=~age, data=imputationList(imp))
Error in as.data.frame.default(data, optional = TRUE) : cannot coerce class ""call"" to a data.frame
我正在按照此页面上的教程进行操作: http://r-survey.r-forge.r- project.org/survey/svymi.html
I am following the tutorial from this page: http://r-survey.r-forge.r-project.org/survey/svymi.html
如何修改代码才能使其正常工作?
how do i modify the code for it to work?
我将data=imputationList(imp)
更改为data=complete(imp,1)
,并且我能够使代码正常工作.但是,这效率不高,因为我必须对所有估算的集合执行此操作.使用imputationList
是否有麻烦?
I change data=imputationList(imp)
to data=complete(imp,1)
and i was able to make the code work. However, this is not efficient since I have to do this to all my imputed sets. Is there something worng with using imputationList
?
推荐答案
mice()
产生结果,并且imputationList
要求包含具有推算值的所有五个data.frame
的列表,但是您需要使用mice::complete
构造那五个完整的data.frame
对象
mice()
produces the results and the imputationList
requires a list of all five data.frame
with the imputed values, but you need to use mice::complete
to construct those five completed data.frame
objects
library(mitools)
library(survey)
library(mice)
data(nhanes)
nhanes$hyp <- as.factor(nhanes$hyp)
imp <- mice(nhanes,method=c("polyreg","pmm","logreg","pmm"), seed = 23109)
imp_list <- lapply( 1:5 , function( n ) complete( imp , action = n ) )
des<-svydesign(id=~1, strat=~age, data=imputationList(imp_list))
这篇关于使用估算数据集的svydesign错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!