【问题标题】:Predict LR with svyglm and svrepdesign使用 svyglm 和 svrepdesign 预测 LR
【发布时间】:2018-09-30 23:38:12
【问题描述】:

我正在尝试对我的调查数据拟合逻辑回归模型。

如何使用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

predict 函数中使用model2svrepdesign 对象(而不是svydesign 对象)会产生错误:

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

有没有办法让svrepdesign 对象在predict 中工作? 以及如何指定在predict 函数中使用哪个数据集?

【问题讨论】:

    标签: r logistic-regression predict survey


    【解决方案1】:

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

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-22
      • 2018-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多