我正在尝试在我的调查数据中使用逻辑回归模型。
如何使用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
函数中使用哪个数据集?
答案 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)