问题描述
一个新手问题:有谁知道如何在 R 中运行带有聚集标准误差的逻辑回归?在 Stata 中它只是 logit Y X1 X2 X3, vce(cluster Z)
,但不幸的是我还没有想出如何在 R 中进行相同的分析.提前致谢!
A newbie question: does anyone know how to run a logistic regression with clustered standard errors in R? In Stata it's just logit Y X1 X2 X3, vce(cluster Z)
, but unfortunately I haven't figured out how to do the same analysis in R. Thanks in advance!
推荐答案
您可能需要查看 rms
(回归建模策略)包.所以,lrm
是逻辑回归模型,如果 fit
是你的输出名称,你会有这样的东西:
You might want to look at the rms
(regression modelling strategies) package. So, lrm
is logistic regression model, and if fit
is the name of your output, you'd have something like this:
fit=lrm(disease ~ age + study + rcs(bmi,3), x=T, y=T, data=dataf)
fit
robcov(fit, cluster=dataf$id)
bootcov(fit,cluster=dataf$id)
您必须在模型语句中指定x=T
, y=T
.rcs
表示具有 3 节的受限三次样条.
You have to specify x=T
, y=T
in the model statement. rcs
indicates restricted cubic splines with 3 knots.
这篇关于R中具有稳健聚类标准误差的逻辑回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!