我需要使用R修复逻辑回归模型。这是Stata代码:
melogit num, binomial(varsum)
我在R中尝试代码但结果却不同。这是我在R的代码。
summary(glm(cbind(num,nonum) ~ -1 + varsum, family = binomial("logit")))
Stata的输出
Logistic regression Number of obs = 18
Binomial variable: vsum
Wald chi2(0) = .
Log likelihood = -26.242541 Prob > chi2 = .
------------------------------------------------------------------------------
num | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | -1.170071 .2202982 -5.31 0.000 -1.601848 -.7382947
------------------------------------------------------------------------------
来自R
Call:
glm(formula = cbind(num, nonum) ~ vsum - 1, family = binomial("logit"))
Deviance Residuals:
Min 1Q Median 3Q Max
-13.5137 -3.9972 -0.7592 2.8821 10.7677
Coefficients:
Estimate Std. Error z value Pr(>|z|)
vsum -0.82854 0.03839 -21.58 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 3198.67 on 18 degrees of freedom
Residual deviance: 673.14 on 17 degrees of freedom
AIC: 704.92
Number of Fisher Scoring iterations: 7
这些是数据:
num = c(0,1,2,0,5,1,1,1,1,1,0,0,3,6,0,0,1,4)
nonum = c(116,43,206,130,146,97,173,73,96,112,66,70,185,181,118,252,344,60)
varsum = c(3,4,11,7,11,5,4,3,20,3,7,1,8,17,0,1,4,5)
答案 0 :(得分:2)
你适合两种不同的模型。
首先,melogit
定义了一个多级混合效应逻辑回归模型,而glm(..., family = binomial("logit"))
符合一个简单的逻辑回归模型。
我不熟悉Stata,但快速搜索表明,可以使用glm
结合link(logit) family(binomial) robust
选项估算具有比例数据的等效逻辑回归模型。