1

当我尝试比较 Stata 和 R 的结果时,我感到很困惑。我使用的是网页http://www.ats.ucla.edu/stat/stata/webbooks/logistic/chapter2/default.htm上给出的示例 首先在Stata中运行以下命令

use http://www.ats.ucla.edu/stat/stata/webbooks/logistic/apilog, clear

然后使用部分(2.2.2 A 2 by 2 Layout with Main Effects and Interaction)中给出的以下命令

generate cred_ed = cred_hl*pared_hl
logit hiqual cred_hl pared_hl cred_ed

这两个命令将产生网页上给出的结果。

然后我使用了以下 R 代码来重现相同的示例

Data<- read.csv("Book1.csv",header=T)
data.glm<-glm(hiqual~cred_hl + pared_hl + cred_hl*pared_hl,family=binomial,  data=Data)
summary(data.glm)

但结果不匹配!

R的数据文件可以从以下链接下载

https://spreadsheets.google.com/spreadsheet/ccc?key=0Ajt182RLsguldFlLQmd6Z1ZoczJCenJIdmREUkhxTFE&hl=en_US

注意:仅具有主效应的模型的结果是匹配的,但当我们包括交互作用时,它是不匹配的。

提前致谢。

4

1 回答 1

4

他们给了我同样的结果(使用 ucla 的数据)。

library(foreign)
d1 <- read.dta('http://www.ats.ucla.edu/stat/stata/webbooks/logistic/apilog.dta')
m1 <- glm(hiqual~cred_hl + pared_hl + cred_hl*pared_hl,family=binomial,  data=d1)
于 2011-08-12T23:52:33.547 回答