Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用logistf对象使用错误条打印_R_Plot_Logistic Regression_Sjplot_Logistf - Fatal编程技术网

R 使用logistf对象使用错误条打印

R 使用logistf对象使用错误条打印,r,plot,logistic-regression,sjplot,logistf,R,Plot,Logistic Regression,Sjplot,Logistf,我最初使用glm软件包做了一个逻辑模型,但想纠正分离,所以我使用了logistf函数,现在我正在尝试重做我的绘图。我不确定如何使用logistf对象绘制下面这样的图。很多软件包似乎不支持它,我尝试使用sjPlot软件包的plot_model()函数,该函数为预测概率绘制一个点,但没有像自动添加glm对象那样添加错误条。我怎样才能避开这件事?是否有其他软件包可以简化此过程,或者是否有方法手动添加错误条 我希望添加错误条的绘图代码为: sjPlot::plot_model(lr3, type=&qu

我最初使用glm软件包做了一个逻辑模型,但想纠正分离,所以我使用了logistf函数,现在我正在尝试重做我的绘图。我不确定如何使用logistf对象绘制下面这样的图。很多软件包似乎不支持它,我尝试使用sjPlot软件包的plot_model()函数,该函数为预测概率绘制一个点,但没有像自动添加glm对象那样添加错误条。我怎样才能避开这件事?是否有其他软件包可以简化此过程,或者是否有方法手动添加错误条

我希望添加错误条的绘图代码为:

sjPlot::plot_model(lr3, type="int", mdrt.values = "meansd", show.values = TRUE, value.offset = .3)
我的型号lr3的输出为:

logistf(formula = foodbank_cv ~ wave + ff_country + relevel(race_grp, 
    ref = "White") + sex_cv + age_r + relevel(numchildren, 
    ref = "None") + wave * ff_hcondhas + relevel(carer, 
    ref = "Not") + sempderived + wave * cd_ff_furlough + 
    log(ff_hours) + qual + num + relevel(keyworksector, ref = "Not keyworker") + 
    ca_clinvuln_dv + freemeals + ca_blbenefits1 + log(hhincome_week), 
    data = data, firth = TRUE, family = binomial(link = "logit"))

Model fitted by Penalized ML
Coefficients:
                                                                         coef   se(coef)  lower 0.95  upper 0.95        Chisq            p method
(Intercept)                                                      -5.237542354 0.46736532 -6.23016284 -4.30807241          Inf 0.000000e+00      2
wave5                                                            -0.377956413 0.32598420 -1.07410577  0.28545651 1.232122e+00 2.669947e-01      2
wave7                                                            -0.929934987 0.40813067 -1.84652632 -0.12926473 5.260388e+00 2.181615e-02      2
ff_country2                                                      -0.118780142 0.33317501 -0.86893024  0.51197342 1.196576e-01 7.294061e-01      2
ff_country3                                                       0.393456771 0.25097814 -0.15010616  0.88210537 2.077828e+00 1.494527e-01      2
ff_country4                                                      -0.219066153 0.43493435 -1.23008781  0.57774984 2.481153e-01 6.184053e-01      2
relevel(race_grp, ref = "White")Asian or Asian British            0.882833792 0.22906054  0.39628625  1.33641305 1.183859e+01 5.801581e-04      2
relevel(race_grp, ref = "White")Black or Black British            1.759374627 0.27942672  1.16321835  2.29702048 2.678592e+01 2.272869e-07      2
relevel(race_grp, ref = "White")Mixed                             1.786978145 0.27773294  1.19285979  2.32350705 2.763841e+01 1.462461e-07      2
relevel(race_grp, ref = "White")Other                            -0.345106379 1.38712570 -5.19048868  1.62733736 6.509258e-02 7.986208e-01      2
ff_hcondhas                                                       0.691244774 0.26776923  0.14697164  1.25269746 6.228205e+00 1.257311e-02      2

Method: 1-Wald, 2-Profile penalized log-likelihood, 3-None
我用来制作饥饿和种族情节的代码。我做了一些手工编辑,使它看起来更漂亮,但这正是我理想中希望我的情节看起来的样子:

plot_model(model12, type = "pred", terms = c("race_grp"), mdrt.values = "meansd", axis.textsize = .3, wrap.labels = 5)+ theme_sjplot2() + scale_color_sjplot("simply") + ggplot2::labs(title= "Predicted probabilities of Hunger", x= "Race", y="Percentage")


我已经找到了一种解决这个问题的方法,但不是使用logistf软件包。如果将来有人想知道这个问题的答案,我建议您使用brglm包。我已经检查过了,brglm包的结果与logistf包完全相同。这就是我如何重新创建上面张贴的饥饿图:

hi2<- brglm(formula= hungry_cv~ wave + ff_country + race_grp + sex_cv + age_r + numchildren + wave*ff_hcondhas + carer + sempderived + wave*cd_ff_furlough + log(ff_hours) + qual + num + keyworksector + ca_clinvuln_dv + freemeals + ca_blbenefits1 + log(hhincome_week), data=data, family=binomial(logit), method = "brglm.fit", pl = TRUE)
racehunger<- plot_model(hi2, type = "pred", terms = c("race_grp"), mdrt.values = "meansd", axis.textsize = .3, wrap.labels = 5, show.values = TRUE)+ theme_sjplot2() + ggplot2::labs(title= "Predicted probabilities of Hunger", x= "Race", y="Percentage")
racehunger
代码的输出为:


我个人对结果非常满意。

Hi,你能提供一些样本数据+你用来生成图像的代码吗?@Slambalais Hi,谢谢你的评论,我现在也更新了,试试
brglm2
(更新,尽管我怀疑结果会有所不同)
png(file="racehunger.png", units="in", width=11, height=8.5, res=300)
print(racehunger)
dev.off()