问题描述
我正在尝试发现我的概率的边际影响(但是,如果有人知道如何通过logit回归来做到这一点,我可以改用那个).我的因变量(我的Y)告诉我一个人可以做的4种可能的动作,并按照进取的积极性进行排序(动作1:最积极的响应,动作4最不积极的响应).我的自变量是4个变量(均为连续变量),它们告诉我系统的状态.回归的目的是查看系统状态的变化如何影响反应的选择.
I am trying to find the marginal effects of my probit (but if anyone knows how to do it with a logit regression I can use that one instead) regression. My dependent variable (my Y) tells me 4 possible actions that one can do and are ordered by aggressiveness of the move (Action1: most aggressive response, Action4 least aggressive response). My independent variables are 4 variables (all continuous) that tell me the state of the system. The goal of the regression is to see how does a change in the state of the system affect the choice of reaction.
我看过几个软件包(mlogit,erer,VGAM等),但是这两个软件包似乎都不具有边际效应函数,该函数只是为您提供每个自变量的边际效应.
I have looked at several packages (mlogit, erer, VGAM, etc) but neither package seems to have an marginal effect function that simply gives you the marginal effect of each independent variable.
我想获得类似于使用边际效应函数(例如maBina)进行二项式logit/probit回归的结果.例如,如果我使用glm运行简单的logit/probit回归,则会得到:
I would like to get something similar to what you can get for a binomial logit/probit regression using a marginal effect function such as maBina. For example, if I were to run a simply logit/probit regression using glm I would get:
mylogit <- glm(admit ~ gre + gpa + rank, family = binomial(link = "logit"), x=TRUE, data = mydata)
> summary(mylogit)
Call:
glm(formula = admit ~ gre + gpa + rank, family = binomial(link = "logit"),
data = mydata, x = TRUE)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.6268 -0.8662 -0.6388 1.1490 2.0790
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -3.989979 1.139951 -3.500 0.000465 ***
gre 0.002264 0.001094 2.070 0.038465 *
gpa 0.804038 0.331819 2.423 0.015388 *
rank2 -0.675443 0.316490 -2.134 0.032829 *
rank3 -1.340204 0.345306 -3.881 0.000104 ***
rank4 -1.551464 0.417832 -3.713 0.000205 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
但是由于这是对数回归,因此系数不能告诉我GPA对被大学录取的可能性的边际影响.为了获得这种边际效应,因此要回答"GPA值的增加如何影响我被大学录取的可能性?"的问题),我需要运行一个单独的命令,例如maBina,我得到:
but since this is a logit regression the coefficients don't tell me the marginal effect of, say, GPA on the probability of getting admitted into college. To get such marginal effect, hence to answer the question "how does an increase in the value of GPA affect my likeliness of being accepted into college?") I need to run a separate command, such as maBina and I get:
>maBina(mylogit, x.mean = FALSE, rev.dum = TRUE, digits = 3)
Call: glm(formula = admit ~ gre + gpa + rank, family = binomial(link = "logit"),
data = mydata, x = TRUE)
Coefficients:
(Intercept) gre gpa rank2 rank3 rank4
-3.989979 0.002264 0.804038 -0.675443 -1.340204 -1.551464
Degrees of Freedom: 399 Total (i.e. Null); 394 Residual
Null Deviance: 500
Residual Deviance: 458.5 AIC: 470.5
$out
effect error t.value p.value
(Intercept) **-0.776** 0.233 -3.337 0.001
gre **0.000** 0.000 1.931 0.054
gpa **0.156** 0.069 2.263 0.024
rank2 **-0.136** 0.061 -2.221 0.027
rank3 **-0.261** 0.072 -3.614 0.000
rank4 **-0.251** 0.049 -5.106 0.000
我要的是效果"(最新表格左侧第二列,以粗体显示).
where "effect" (the 2nd column from the left in the latest table, in bold) is what I'm looking for.
推荐答案
通常,如果需要的只是系数表和标准误表,则使用summary.glm并从该对象中提取系数表.在这里:
Generally one uses summary.glm and pulls the coefficients table from that object if all you want is the table of coefficients and standard errors, which it appears is the case here:
summary(glmfit)$coefficients # or
coef( summary(glmfit))
另一方面,如果您想要的是比例或概率的预测,则使用 predict.glm
能够在测量范围内而不是在变换范围内传递预测响应.估计回归系数:
On the other hand if what you want are predictions for proportions or probabilities, then the use of predict.glm
is capable of delivering predicted responses on the measured scale rather than on the transformed scale where the regression coefficients were estimated:
?predict.glm
还有一个 effects
包,该包提供图形显示并允许指定选定的对比度.
There is also an effects
package that provides graphical displays and allows specification of selected contrasts.
install.packages("effects", dependencies=TRUE)
help(package="effects")
如果您提供一个简单的示例并说明您的意思是效果",它将澄清您的期望.
It would clarify your expectations if you presented a simple example and said what values you mean to be "effects".
因此,在澄清之后,我现在想知道您是否想要一种用于提取特定值的编程方法.如果是这样,那么它很简单:
So after clarification I now wonder if you want a programmatic method for extracting a particular value. If so then it is as simple as:
> ea$out['gpa', 'effect']
[1] 0.534 # where ea is the object created in ?maBina example
这篇关于寻找R中多项式有序概率/对数回归的边际效应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!