2017-02-28 11 views
0

svydesign을 사용하여 귀속 된 데이터 세트를 분석 중이지만 오류가 발생합니다.귀결 된 데이터 세트를 사용하는 svydesign에서의 오류

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

내가 어떻게 그것이 작동하려면 코드를 수정 않습니다 아래 코드는?

편집 :

내가 data=imputationList(imp)data=complete(imp,1)에 변경 전 코드 작업을 할 수 있었다. 그러나 이것은 모든 귀속 된 세트에 대해이 작업을 수행해야하므로 효율적이지 않습니다. imputationList을 사용하면 문제가 있습니까?

답변

0

mice() 결과를 생산하고 imputationList은 귀속 값을 다섯 data.frame의 목록이 필요하지만, 당신은 그 다섯 개 완료 data.frame 객체를 구성하는 mice::complete를 사용할 필요가

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))