Stata的xtlogit(fe,re)等效于R? [英] Stata's xtlogit (fe, re) equivalent in R?

查看:517
本文介绍了Stata的xtlogit(fe,re)等效于R?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Stata允许通过 xtlogit 进行逻辑回归的固定效应和随机效应规范fe和 xtlogit 相应地重新命令.我想知道R中这些规范的等效命令是什么.

Stata allows for fixed effects and random effects specification of the logistic regression through the xtlogit fe and xtlogit re commands accordingly. I was wondering what are the equivalent commands for these specifications in R.

我知道的唯一类似的规范是混合效应逻辑回归

The only similar specification I am aware of is the mixed effects logistic regression

mymixedlogit <- glmer(y ~ x1 + x2 +  x3 + (1 | x4), data = d, family = binomial)

但是我不确定这是否映射到上述任何命令.

but I am not sure whether this maps to any of the aforementioned commands.

推荐答案

glmer命令用于快速拟合具有不同截距和斜率的逻辑回归模型(或等效地具有固定和随机效应的混合模型)

The glmer command is used to quickly fit logistic regression models with varying intercepts and varying slopes (or, equivalently, a mixed model with fixed and random effects).

要在R中适应变化截距的多级逻辑回归模型(即随机效应逻辑回归模型),可以使用内置的"mtcars"数据集运行以下命令:

To fit a varying intercept multilevel logistic regression model in R (that is, a random effects logistic regression model), you can run the following using the in-built "mtcars" data set:

data(mtcars)
head(mtcars)
m <- glmer(mtcars$am ~ 1 + mtcars$wt + (1|mtcars$gear), family="binomial")
summary(m)   

# and you can examine the fixed and random effects
fixef(m); ranef(m)

要在Stata中适应截距变化的斜率模型,您当然可以使用xtlogit命令(在Stata中使用类似但不完全相同的内置自动"数据集):

To fit a varying-intercept slope model in Stata, you of course use the xtlogit command (using the similar but not identical in-built "auto" data set in Stata):

sysuse auto
xtset gear_ratio
xtlogit foreign weight, re

我要补充一点,我发现对固定"效果和随机"效果的整个引用是模棱两可的,我更喜欢指的是模型本身的结构(例如,截距是否变化?是吗?模型是否嵌套在2个或更多级别中?这些级别是否交叉分类?).对于类似的观点,请参见安德鲁·盖尔曼(Andrew Gelman)关于固定"效果与随机"效果的想法 .

I'll add that I find the entire reference to "fixed" versus "random" effects ambiguous, and I prefer to refer to the structure of the model itself (e.g., are the intercepts varying? which slopes are varying, if any? is the model nested in 2 levels or more? are the levels cross-classified or not?). For a similar view, see Andrew Gelman's thoughts on "fixed" versus "random" effects.

更新:Ben Bolker在下面的出色评论指出,在R中,当使用predict命令而不是美元符号来使用data=mtcars选项时,它更具信息性:

Update: Ben Bolker's excellent comment below points out that in R it's more informative when using predict commands to use the data=mtcars option instead of, say, the dollar notation:

data(mtcars)
m1 <- glmer(mtcars$am ~ 1 + mtcars$wt + (1|mtcars$gear), family="binomial")
m2 <- glmer(am ~ 1 + wt + (1|gear), family="binomial", data=mtcars)
p1 <- predict(m1); p2 <- predict(m2)
names(p1) # not that informative...
names(p2) # very informative!

这篇关于Stata的xtlogit(fe,re)等效于R?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆