【问题标题】:Average marginal effects (AMEs) in partial proportional odds model部分比例优势模型中的平均边际效应 (AME)
【发布时间】:2018-11-13 15:36:05
【问题描述】:

如何在偏比例优势模型 (PPOM) 中获得每个类别/阈值的平均边际效应 (AME)?

这是我在这个论坛的第一篇文章。我希望我已经听取了提出好问题的最重要的建议。

此示例数据集由一个有序结果变量 (Y1) 和三个自变量(VAR1、VAR2、VAR3)组成。

set.seed(3)
sampleData <- data.frame(id = 1:1000, Y1 = sample(c("1", "2", "3", "4"), 
    1000, replace=TRUE), Var1 = rnorm(1000, 40, 10), 
    Var2 = rnorm(1000, 60, 10), Var3 = rnorm(1000, 80, 5))

假设违反比例赔率假设,可以使用包ordinal 执行部分比例赔率模型 (PPOM),通过三个自变量(Var1、Var2、Var3)预测 Y1。

library(ordinal)  
PPOM <- clm(as.factor(Y1) ~ Var1 + Var2 + Var3, 
        nominal = ~ Var1 + Var2 + Var3, data = sampleData)

我们得到以下输出,其中包含每个类别的系数:

summary(PPOM)

formula: as.factor(Y1) ~ Var1 + Var2 + Var3
nominal: ~Var1 + Var2 + Var3
data:    sampleData

 link  threshold nobs logLik   AIC     niter max.grad cond.H 
 logit flexible  1000 -1381.17 2786.34 4(0)  2.82e-10 2.2e+07

Coefficients: (3 not defined because of singularities)
     Estimate Std. Error z value Pr(>|z|)
Var1       NA         NA      NA       NA
Var2       NA         NA      NA       NA
Var3       NA         NA      NA       NA

Threshold coefficients:
                  Estimate Std. Error z value
1|2.(Intercept)  0.4952642  1.2260010   0.404
2|3.(Intercept)  1.9790234  1.0724982   1.845
3|4.(Intercept)  2.0892425  1.2550636   1.665
1|2.Var1         0.0026194  0.0075920   0.345
2|3.Var1        -0.0077578  0.0065845  -1.178
3|4.Var1        -0.0064243  0.0075364  -0.852
1|2.Var2        -0.0001089  0.0074568  -0.015
2|3.Var2        -0.0082836  0.0063447  -1.306
3|4.Var2        -0.0073638  0.0071008  -1.037
1|2.Var3        -0.0219767  0.0140701  -1.562
2|3.Var3        -0.0157235  0.0121943  -1.289
3|4.Var3        -0.0047098  0.0141844  -0.332

我对每个类别的每个预测变量的 AME 感兴趣。通过使用margins,我只能获得所有阈值的 AME。

library(margins) 
summary(margins(PPOM))

输出:

 factor    AME     SE      z      p   lower  upper
   Var1 0.0000 0.0000 1.1365 0.2557 -0.0000 0.0001
   Var2 0.0000 0.0000 1.3056 0.1917 -0.0000 0.0001
   Var3 0.0001 0.0001 0.9990 0.3178 -0.0001 0.0002

有没有人知道如何计算每个类别的 AME?

任何帮助将不胜感激!

【问题讨论】:

标签: r


【解决方案1】:

我知道我来晚了,但我只是编写了一个简短(而且效率相当低)的程序来手动计算此类模型的平均边际效应。

部分比例赔率序数 logit/probit 的平均边际效应的计算方式与计算正常序数 logit/probit 的方式相同。以下是 Cameron 和 Trivedi 的“微观计量经济学:方法和应用”的节选。连续变量的边际效应由屏幕底部的方程给出。离散变量的边际效应为 Pr(y_i = j | x = 1 ) - Pr(y_i = j | x= 0); Pr(y_i = j) 在页面顶部的等式中给出。

我建议手动计算每组估计的 beta 的边际效应。这涉及保存由您的数据、不同的 beta 以及您计算 ME 的变量的系数组成的矩阵/向量。这也意味着您正在为每个结果和每个系数计算不同的 ME(在您的情况下,3 * 序数结果的数量)。

下面是我自己编写的一些代码。它效率不高,并且一一进行。它根据三个结果计算一个名为“snap12”的虚拟变量的 ME,这就是为什么有六个方程的原因。 “Cut1”和“Cut2”是截止点(在 ME 方程中通常称为 alpha)。 Xdat 是数据,不包括我正在为其计算 ME 的变量。 xcoef1 是第一组系数(减去 ME 变量),xcoef2 是第二组系数。 Snapcoef1 和 snapcoef2 是 ME 变量的系数。最后,pnorm 给出序数概率 ME 所需的 CDF 值。

我希望这对某人有帮助!



##for pr(v low secure)

#1st set of coefficients
p3a = ((1 - pnorm(cut2 - xdat%*%xcoef1 - snapcoef1)) - 
       (1 - pnorm(cut2 - xdat%*%xcoef1)))
#2nd set
p3b = ((1 - pnorm(cut2 - xdat%*%xcoef2 - snapcoef2)) - 
       (1 - pnorm(cut2 - xdat%*%xcoef2)))

#for pr(low sec)
#1st set
p2a = (pnorm(cut2 - xdat%*%xcoef1 - snapcoef1) - pnorm(cut1 - xdat%*%xcoef1 - snapcoef1)) - 
         (pnorm(cut2 - xdat%*%xcoef1) - pnorm(cut1 - xdat%*%xcoef1))

p2b = (pnorm(cut2 - xdat%*%xcoef2 - snapcoef2) - pnorm(cut1 - xdat%*%xcoef2 - snapcoef2)) - 
  (pnorm(cut2 - xdat%*%xcoef2) - pnorm(cut1 - xdat%*%xcoef2))

## for pr(fodo sec)

p1a = (pnorm(cut1 - xdat%*%xcoef1 - snapcoef1)) - (pnorm(cut1 - xdat%*%xcoef1))

p1b = (pnorm(cut1 - xdat%*%xcoef2 - snapcoef2)) - (pnorm(cut1 - xdat%*%xcoef2))


【讨论】:

    猜你喜欢
    • 2019-06-02
    • 2021-02-15
    • 2021-10-22
    • 1970-01-01
    • 2021-07-03
    • 2020-05-07
    • 2020-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多