使用svyglm和svrepdesign预测LR

时间:2018-04-20 09:31:21

标签: r logistic-regression predict survey

我正在尝试在我的调查数据中使用逻辑回归模型。

如何使用svyglm预测逻辑回归模型?

调查设计:

dhs.svy <- svydesign(id =~ HV001+couple, strata =~ HV023, 
                     weights =~ V005, fpc =~ fpc1+fpc2, data = dhs)
dhs.svy.rep <- as.svrepdesign(dhs.svy)

型号:

model1 <- svyglm(score ~ man.edu + woman.edu, design = dhs.svy, family = binomial)
model2 <- svyglm(score ~ man.edu + woman.edu, design = dhs.svy.rep, family = binomial)

predict(model1, type = "response")  #works
predict(model2, type = "response")  #does not work

model2函数中使用带有svrepdesign对象(而不是svydesign对象)的predict会出错:

  

“print.svrepstat(x)中的错误:svrepstat对象的结构不正确。”   在model1中使用svydesign predict个对象可以正常工作。

有没有办法让svrepdesign对象在predict中运行? 我如何指定在predict函数中使用哪个数据集?

1 个答案:

答案 0 :(得分:0)

我认为这是调查库中的一个错误。我已经向维护者提交了一份错误报告。这是解决方法。谢谢!

library(survey)
data(scd)

# use BRR replicate weights from Levy and Lemeshow
repweights<-2*cbind(c(1,0,1,0,1,0), c(1,0,0,1,0,1), c(0,1,1,0,0,1),
c(0,1,0,1,1,0))
scdrep<-svrepdesign(data=scd, type="BRR", repweights=repweights, combined.weights=FALSE)

# simple svrepglm object
rep.glm <- svyglm( arrests ~ alive , scdrep )

# breaks at the `print.svrepstat` call
predict( rep.glm , newdata = data.frame( alive = 1:3 ) )

# put it into an object rather than printing it to the screen..
w <- predict( rep.glm , newdata = data.frame( alive = 1:3 ) )

# override the default to get what you expect
survey:::print.svystat(w)