Stata+R: 一文读懂中介效应分析

2019-12-31  本文已影响0人  stata连享会

沙莎 (北京师范大学)
E-mail: shasha_1212@163.com

Stata连享会   计量专题 || 精品课程 || 简书推文 || 公众号合集

点击查看完整推文列表

连享会计量方法专题…… || https://gitee.com/arlionn/Course

背景介绍

在研究中,我们探索自变量 X 对因变量 Y 产生的影响,得到 X 和 Y 在实际或理论上的关系,进而我们试图探索两者之间关系的内部机制或原理,中介效应分析为回答这一问题提供了可能性。

在本篇推文中,我们为大家梳理出几个广泛使用的中介效应分析方法和实现程序,供大家参考。

1. 中介效应简介

中介效应:通俗来说,我们分析自变量 X 对因变量 Y 产生的影响,如果变量 X 通过影响变量 M 来影响变量 Y ,那么这个变量 M 就是中介变量。例如租客 (X) 通过中介公司 (M) 找到合适的房子 (Y),中介公司就在其中扮演了中介变量的角色,中介变量发挥的作用就称为中介效应。

2. 中介效应分析

中介效应分析是检验某一变量是否成为中介变量,发挥何种程度中介作用的重要步骤。我们先以最简单的单中介模型为例来说明中介效应分析的思路,再具体介绍三种中介效应分析方法。

假设所有变量都已经中心化 (即均值为零),可用下图来描述变量之间的关系。图中分为两个部分, 图 1(a) 是自变量 X 作用于因变量 Y ,路径系数为 c 。由于不涉及第三个变量,所以系数 c 代表了自变量作用于因变量的总效应。图 1(b) 是在控制中介变量 M 以后,自变量 x 和因变量 Y 之间的关系,其中系数 a 代表自变量作用于中介变量的效应,系数 b 表示中介变量作用于因变量的效应,两者构成图中变量间关系的间接效应,系数 c’ 代表考虑在控制中介变量后,自变量作用于因变量的效应,也就是自变量和因变量之间的直接效应。那么,图 1(b) 中的变量间总效应就应该等于直接效应加上间接效应,即总效应 = ab + c’。 将图1 (a) 和 (b) 结合起来,我们就得到了 c= ab + c’,c 为总效应,c’ 为直接效应, ab 为中介效应也称间接效应。我们做中介效应分析就是要检验 ab 效应是否存在,以及它在总效应中的占比,体现中介效应的作用程度。


image

2.1 逐步检验回归系数

\begin{array}{l} {Y=c X+e_{1}}...........................(1) \\ {M=a X+e_{2}} ..........................(2) \\ {Y=c^{\prime} X+b M+e 3}....................(3) \end{array}

2.2 系数乘积检验法

检验系数乘积是直接针对假设 H0 : ab=0 提出的检验方法,有多种计算公式,我们介绍两种常用的方法。

2.2.1 Sobel 检验

目前最常用的就是 Sobel (1982, 1988),检验统计量为 z=\hat{a} \hat{b} / s_{a b} ,其中 \hat{a}\hat{b} 分别是 a 和 b 的估计值,\hat{a} \hat{b} 的标准误为:

se(a b)=\sqrt{\hat{a}^{2} se_{b}^{2}+\hat{b}^{2} se_{a}^{2}}

se_{a} \se_{b} 分别是 \hat{a}\hat{b} 的标准误。

2.2.2 Bootstrap 检验

Bootstrap 检验的也是 H0 : ab=0,它根据标准误的理论概念,将样本容量很大的样本当作总体,进行有放回抽样 (抽样次数可以自己定),从而得到更为准确的标准误。例如,将一个容量为 500 的样本当作 Bootstrap 总体, 从中有放回地重复取样, 可以得到一个 Bootstrap 样本 (容量还是500)。对这 500 个 Bootstrap 样本,可以得到 500 个系数乘积的估计值,其全体记为 \hat{a} \hat{b},将它们按数值从小到大排序, 其中第 2.5 百分位点和第 97.5 百分位点就构成 ab 的一个置信度为 95% 的置信区间,如果这个置信区间不包含 0,则说明拒绝原假设 H0 : ab=0,系数乘积显著 (方杰,张敏强,2012;Preacher & Hayes, 2008;Preacher, Rucker, &Hayes, 2007;温忠麟,刘红云,侯杰泰,2012)

2.3 系数差异检验法

差异系数检验的是 H0:c - c’ =0,因为通常情况下,ab = c - c’,因此,乘积系数法和差异系数法的检验效力是基本上相同的,区别在于两者的标准误不同。

差异系数检验方法犯错的概率要高于系数乘积检验法 (MacKinnon et al., 2002; 温忠麟等,2004),很少使用。


连享会计量方法专题…… || https://gitee.com/arlionn/Course

3. 中介效应分析示例

接下来,我们借助 Stata 自带案例展示上述中介效应分析方法的具体操作。

3.1 调用数据并定义变量

数据基本描述:这是一组有关大型百货公司销售人员的数据,我们用来讨论经理的激励与员工工作表现之间的关系,基本假设是:经理的激励 (perceived support from managers) 可能通过影响员工的工作满意度 (job satisfaction) 而影响员工的工作表现 (job performance)。

. use "http://www.stata-press.com/data/r15/gsem_multmed"    //调用数据
(Fictional job-performance data)

. summarize    //查看数据分布

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      branch |      1500          38    21.65593          1         75
     support |      1500    .0084667    .5058316       -1.6        1.8
       satis |      1500       .0212    .6087235       -1.6          2
     perform |      1500    5.005317    .8949845    2.35022   8.084294

数据分布可以看到,我们的样本量为 1500, 其中所需使用的变量为:

3.2 多方法进行中介效应分析

接下来我们展现多种方法进行的中介效应分析程序,并分析结果。

3.2.1 逐步检验回归系数方法

逐步检验回归系数方法分为三步:

reg perform support    //分析 x 和 y 之间的关系
reg satis support      //分析 x 和 m 之间的关系
reg perform satis support     // 加入 m,看 x 和 y 之间的关系

第一步reg support peform 结果显示员工的工作表现与经理的激励显著相关,回归系数 c=0.822,可以进行下一步检验。

. reg perform support      //第一步,查看 x 与 y 之间的关系

      Source |       SS       df       MS              Number of obs =    1500
-------------+------------------------------           F(  1,  1498) =  412.00
       Model |  258.999482     1  258.999482           Prob > F      =  0.0000
    Residual |  941.695489  1498  .628635173           R-squared     =  0.2157
-------------+------------------------------           Adj R-squared =  0.2152
       Total |  1200.69497  1499  .800997312           Root MSE      =  .79287

------------------------------------------------------------------------------
     perform |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     support |   .8217557   .0404849    20.30   0.000     .7423427    .9011687
       _cons |    4.99836   .0204746   244.13   0.000     4.958198    5.038522
------------------------------------------------------------------------------

第二步reg satis perform 回归结果显示, 经理的激励显著增加员工的工作满意度,系数 a=0.229。

. reg satis support       //第二步,查看 x 与 m 之间的关系

      Source |       SS       df       MS              Number of obs =    1500
-------------+------------------------------           F(  1,  1498) =   56.23
       Model |  20.0948214     1  20.0948214           Prob > F      =  0.0000
    Residual |  535.351023  1498  .357377185           R-squared     =  0.0362
-------------+------------------------------           Adj R-squared =  0.0355
       Total |  555.445844  1499  .370544259           Root MSE      =  .59781

------------------------------------------------------------------------------
       satis |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     support |   .2288945   .0305251     7.50   0.000     .1690181    .2887709
       _cons |    .019262   .0154376     1.25   0.212    -.0110195    .0495436
------------------------------------------------------------------------------

第三步reg perform satis support 在加入工作满意度后,员工的表现和经理激励之间的显著关系没有发生变化,但是系数由第一步的 c=0.822 减小到 c’=0.616,员工的工作满意度和员工的表现之间显著相关,系数 b=0.898,说明工作满意度在经理激励和员工表现之间起到了部分中介的作用。

. reg perform satis support    //第三步:加入中介变量 m, 查看 x 与 y 之间的关系

      Source |       SS       df       MS              Number of obs =    1500
-------------+------------------------------           F(  2,  1497) = 1015.21
       Model |  691.131957     2  345.565979           Prob > F      =  0.0000
    Residual |  509.563014  1497  .340389455           R-squared     =  0.5756
-------------+------------------------------           Adj R-squared =  0.5750
       Total |  1200.69497  1499  .800997312           Root MSE      =  .58343

------------------------------------------------------------------------------
     perform |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       satis |   .8984401   .0252156    35.63   0.000     .8489785    .9479017
     support |   .6161077   .0303447    20.30   0.000      .556585    .6756303
       _cons |   4.981054    .015074   330.44   0.000     4.951486    5.010622
------------------------------------------------------------------------------

3.2.2 两步回归法 (two-step regression)

Zhao, Lynch et al. (2010) 对传统的逐步检验回归系数方法提出再次思考,但其具体的步骤方法与逐步检验回归系数方法接近,只是取消了第一步中的检验自变量 x 和因变量 y 之间的关系,分为两步:

reg satis support      //分析 x 和 m 之间的关系
reg perform satis support     // 加入 m,看 x 和 y 之间的关系

第一步reg satis perform 回归结果显示,经理的激励显著增加员工的工作满意度,系数 a=0.229。

. reg satis support       //第二步,查看 x 与 m 之间的关系

      Source |       SS       df       MS              Number of obs =    1500
-------------+------------------------------           F(  1,  1498) =   56.23
       Model |  20.0948214     1  20.0948214           Prob > F      =  0.0000
    Residual |  535.351023  1498  .357377185           R-squared     =  0.0362
-------------+------------------------------           Adj R-squared =  0.0355
       Total |  555.445844  1499  .370544259           Root MSE      =  .59781

------------------------------------------------------------------------------
       satis |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     support |   .2288945   .0305251     7.50   0.000     .1690181    .2887709
       _cons |    .019262   .0154376     1.25   0.212    -.0110195    .0495436
------------------------------------------------------------------------------

第二步reg perform satis support 回归结果和第一种方法相同:

. reg perform satis support    //第三步:加入中介变量 m, 查看 x 与 y 之间的关系

      Source |       SS       df       MS              Number of obs =    1500
-------------+------------------------------           F(  2,  1497) = 1015.21
       Model |  691.131957     2  345.565979           Prob > F      =  0.0000
    Residual |  509.563014  1497  .340389455           R-squared     =  0.5756
-------------+------------------------------           Adj R-squared =  0.5750
       Total |  1200.69497  1499  .800997312           Root MSE      =  .58343

------------------------------------------------------------------------------
     perform |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       satis |   .8984401   .0252156    35.63   0.000     .8489785    .9479017
     support |   .6161077   .0303447    20.30   0.000      .556585    .6756303
       _cons |   4.981054    .015074   330.44   0.000     4.951486    5.010622
------------------------------------------------------------------------------

3.2.3 sobel 检验

第一步:安装 segmediation 命令包 findit sgmediation

findit sgmediation

原先可通过此命令下载来自 UCLA 的 segmediation 命令包,但是这个网址取消了,可通过网络等方式获取此命令,例如:人大经济论坛 https://bbs.pinggu.org/thread-6354003-1-1.html

第二步:进行分析

sgmediation perform, mv(satis) iv(support)

命令会自动检验变量之间的关系路径,并提供中介效应在总效应中的占比和显著值。如果需要加入控制变量,sgmediation y, mv(m) iv(x) cv(c)。具体结果如下:

. sgmediation perform, mv(satis) iv(support)    //用 sobel 方法检验中介变量

Model with dv regressed on iv (path c)     //这里,Stata 自动检验经理激励和员工工作表现之间的路径,形成路径 c

      Source |       SS       df       MS              Number of obs =    1500
-------------+------------------------------           F(  1,  1498) =  412.00
       Model |  258.999482     1  258.999482           Prob > F      =  0.0000
    Residual |  941.695489  1498  .628635173           R-squared     =  0.2157
-------------+------------------------------           Adj R-squared =  0.2152
       Total |  1200.69497  1499  .800997312           Root MSE      =  .79287

------------------------------------------------------------------------------
     perform |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     support |   .8217557   .0404849    20.30   0.000     .7423427    .9011687
       _cons |    4.99836   .0204746   244.13   0.000     4.958198    5.038522
------------------------------------------------------------------------------

Model with mediator regressed on iv (path a)     //这里,Stata 检验中介变量 (工作满意度) 与自变量 (经理激励) 之间的关系,形成路劲 a

      Source |       SS       df       MS              Number of obs =    1500
-------------+------------------------------           F(  1,  1498) =   56.23
       Model |  20.0948214     1  20.0948214           Prob > F      =  0.0000
    Residual |  535.351023  1498  .357377185           R-squared     =  0.0362
-------------+------------------------------           Adj R-squared =  0.0355
       Total |  555.445844  1499  .370544259           Root MSE      =  .59781

------------------------------------------------------------------------------
       satis |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     support |   .2288945   .0305251     7.50   0.000     .1690181    .2887709
       _cons |    .019262   .0154376     1.25   0.212    -.0110195    .0495436
------------------------------------------------------------------------------

Model with dv regressed on mediator and iv (paths b and c')   //加入中介变量, Stata 再次检验经理支持对员工工作表现的影响

      Source |       SS       df       MS              Number of obs =    1500
-------------+------------------------------           F(  2,  1497) = 1015.21
       Model |  691.131957     2  345.565979           Prob > F      =  0.0000
    Residual |  509.563014  1497  .340389455           R-squared     =  0.5756
-------------+------------------------------           Adj R-squared =  0.5750
       Total |  1200.69497  1499  .800997312           Root MSE      =  .58343

------------------------------------------------------------------------------
     perform |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       satis |   .8984401   .0252156    35.63   0.000     .8489785    .9479017
     support |   .6161077   .0303447    20.30   0.000      .556585    .6756303
       _cons |   4.981054    .015074   330.44   0.000     4.951486    5.010622
------------------------------------------------------------------------------

Sobel-Goodman Mediation Tests      //进行 Sobel 检验,原假设 $H0 : ab=0$

                     Coef         Std Err     Z           P>|Z|
Sobel               .20564799    .02802571   7.338      2.172e-13    //我们需要关注这个部分的 P 值,这里的 P<0.05 则代表拒绝原假设,中介效应成立
Goodman-1 (Aroian)  .20564799    .02803628   7.335      2.216e-13
Goodman-2           .20564799    .02801514   7.341      2.127e-13

                    Coef      Std Err    Z          P>|Z|
a coefficient   =  .228894   .030525   7.49857    6.5e-14    // 这里分别提供了输入命令三个变量之间的关系路径系数
b coefficient   =   .89844   .025216   35.6304          0
Indirect effect =  .205648   .028026   7.33783    2.2e-13
  Direct effect =  .616108   .030345   20.3036          0
   Total effect =  .821756   .040485   20.2979          0

Proportion of total effect that is mediated:  .25025442      //这里 Stata 直接帮我们计算出中介效应在总效应中的占比 25.03%
Ratio of indirect to direct effect:           .3337858
Ratio of total to direct effect:              1.3337858

3.2.4 bootstrap 检验

bootstrap r(ind_eff) r(dir_eff), reps(500) :  ///
          sgmediation perform, mv(satis) iv(support)    //计算中介效应和间接效应
estat bootstrap, percentile bc      //计算置信区间

bootstrap 抽样次数可以自己设定,这里我们设定为 500。如下命令会计算变量间的直接效应 _bs_1 和间接效应 _bs_2

bootstrap r(ind_eff) r(dir_eff), reps(500) : sgmediation perform, mv(satis) iv(support) 

如果需要加入控制变量,命令为:

bootstrap r(ind_eff) r(dir_eff), reps(500) : sgmediation y, mv(m) iv(x) cv(c)

进而可以使用 estat bootstrap, percentile bc 命令计算间接效应的置信区间,根据 _bs_2 置信区间是否包含 0 判断中介效应是否成立。具体结果如下:

. bootstrap r(ind_eff) r(dir_eff), reps(500) : sgmediation perform, mv(satis) iv(support)      
// bootstrap 方法首先计算出直接效应 bs_1 和间接效应 bs_2
(running sgmediation on estimation sample)

Bootstrap replications (500)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400
..................................................   450
..................................................   500

Bootstrap results                               Number of obs      =      1500
                                                Replications       =       500

      command:  sgmediation perform, mv(satis) iv(support)
        _bs_1:  r(ind_eff)      //间接效应 = 0.206
        _bs_2:  r(dir_eff)      //直接效应 = 0.616

------------------------------------------------------------------------------
             |   Observed   Bootstrap                         Normal-based
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _bs_1 |    .205648   .0282388     7.28   0.000      .150301     .260995
       _bs_2 |   .6161077   .0305996    20.13   0.000     .5561335     .6760818
------------------------------------------------------------------------------

. estat bootstrap, percentile bc   //这里计算直接效应和间接效应的置信区间

Bootstrap results                               Number of obs      =      1500
                                                Replications       =       500

      command:  sgmediation perform, mv(satis) iv(support)
        _bs_1:  r(ind_eff)
        _bs_2:  r(dir_eff)

------------------------------------------------------------------------------
             |    Observed               Bootstrap
             |       Coef.       Bias    Std. Err.  [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _bs_1 |   .20564799  -.0008603   .02823879    .1478535   .2641403   (P)
             |                                       .1528905   .2683623  (BC)
       _bs_2 |   .61610768   .0003294   .03059962     .559106   .6745357   (P)     //我们需要关注这个地方的置信区间,很显然不包含 0 ,中介效应成立
             |                                       .5592248   .6750107  (BC)
------------------------------------------------------------------------------
(P)    percentile confidence interval
(BC)   bias-corrected confidence interval

3.2.5 结构方程方法

Stata 也可以通过结构方程 (sem) 或者广义线性回归 (gsem) 的方式检验中介效应。分为两步:

sem (perform <- satis support) (satis <- support)   //进行模型估计
estat teffects    //计算中介效应

具体结果如下:

. sem (perform <- satis support) (satis <- support)    //具体的模型估计

Endogenous variables
Observed:  perform satis
Exogenous variables
Observed:  support
Fitting target model:

Iteration 0:   log likelihood = -3779.9224  
Iteration 1:   log likelihood = -3779.9224  

Structural equation model                       Number of obs      =      1500
Estimation method  = ml
Log likelihood     = -3779.9224

-------------------------------------------------------------------------------
              |                 OIM
              |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
--------------+----------------------------------------------------------------
Structural    |
  perform <-  |
        satis |   .8984401   .0251903    35.67   0.000      .849068    .9478123
      support |   .6161077   .0303143    20.32   0.000     .5566927    .6755227
        _cons |   4.981054   .0150589   330.77   0.000     4.951539    5.010569
  ------------+----------------------------------------------------------------
  satis <-    |
      support |   .2288945   .0305047     7.50   0.000     .1691064    .2886826
        _cons |    .019262   .0154273     1.25   0.212    -.0109749    .0494989
--------------+----------------------------------------------------------------
var(e.perform)|   .3397087   .0124044                      .3162461     .364912
  var(e.satis)|   .3569007   .0130322                      .3322507    .3833795
-------------------------------------------------------------------------------
LR test of model vs. saturated: chi2(0)   =      0.00, Prob > chi2 =      .

. estat teffects     //效应分析

Direct effects    //直接效应
------------------------------------------------------------------------------
             |                 OIM
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  perform <- |
       satis |   .8984401   .0251903    35.67   0.000      .849068    .9478123
     support |   .6161077   .0303143    20.32   0.000     .5566927    .6755227
  -----------+----------------------------------------------------------------
  satis <-   |
     support |   .2288945   .0305047     7.50   0.000     .1691064    .2886826
------------------------------------------------------------------------------

Indirect effects    //间接效应
------------------------------------------------------------------------------
             |                 OIM
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  perform <- |
       satis |          0  (no path)
     support |    .205648   .0280066     7.34   0.000      .150756      .26054
  -----------+----------------------------------------------------------------
  satis <-   |
     support |          0  (no path)
------------------------------------------------------------------------------


Total effects     //总效应
------------------------------------------------------------------------------
             |                 OIM
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  perform <- |
       satis |   .8984401   .0251903    35.67   0.000      .849068    .9478123
     support |   .8217557   .0404579    20.31   0.000     .7424597    .9010516
  -----------+----------------------------------------------------------------
  satis <-   |
     support |   .2288945   .0305047     7.50   0.000     .1691064    .2886826
------------------------------------------------------------------------------

3.3 类别变量的中介效应检验

通常的中介效应模型,假设自变量、中介变量和因变量均为连续变量,对于连续变量的中介效应分析本文 3.2 中的方法均可使用。当自变量 X 为分类变量时,可以先通过生成哑变量的方法对自变量进行处理,之后的中介效应分析方法与连续变量的步骤完全相同。但是,对于因变量 Y 为分类变量或者中介变量 M 为类别变量的情况,研究中使用的相对较少,下文中我们收集了几个处理因变量 Y 或者中介变量 M 为类别变量的分析方法。

3.3.1 广义结构方程方法

对于因变量 Y 是二分类变量,中介变量 M 为连续变量的情况,可以考虑使用 gsem 模型检验中介效应。

调用数据并定义变量

数据基本描述:这是一组有关大型百货公司销售人员的数据,我们用来讨论经理的激励与员工工作表现之间的关系,基本假设是:经理的激励 (perceived support from managers) 可能通过影响员工的工作满意度 (job satisfaction) 而影响员工的工作表现 (job performance)

下文中为了举例用广义结构方程方法分析类别变量的中介效应分析,我们将因变量 Y 处理为二分类变量

. use http://www.stata-press.com/data/r15/gsem_multmed    //调用数据
(Fictional job-performance data)

. summarize    //查看数据分布

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      branch |      1500          38    21.65593          1         75
     support |      1500    .0084667    .5058316       -1.6        1.8
       satis |      1500       .0212    .6087235       -1.6          2
     perform |      1500    5.005317    .8949845    2.35022   8.084294

. gen perform_gr2=.
(1500 missing values generated)

. replace perform_gr2=1 if perform<5
(719 real changes made)

. replace perform_gr2=2 if perform>=5&perform!=.
(781 real changes made)

. tab perform_gr2,missing  //将因变量处理为类别变量,perform_gr2=0 代表员工工作表现不好, perform_gr2=1 代表员工工作表现好

perform_gr2 |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |        719       47.93       47.93
          2 |        781       52.07      100.00
------------+-----------------------------------
      Total |      1,500      100.00

数据分布可以看到,我们所需使用的变量为:

进行模型估计
gsem (perform_gr2 <- support satis) (satis <- support)      //模型估计
gsem, coeflegend`        //计算效应
nlcom _b[perform_gr2:satis]*_b[satis:support]        //计算间接效应
nlcom _b[perform_gr2:support]+_b[perform_gr2:satis]*_b[satis:support]    //计算总效应

gsem (perform_gr2 <- support satis) (satis <- support) 先进行模型估计,nlcom _b[perform_gr2:satis]*_b[satis:support] 计算间接效应, nlcom _b[perform_gr2:support]+_b[perform_gr2:satis]*_b[satis:support] 计算总效应,具体结果如下:

. gsem (perform_gr2 <- support satis) (satis <- support)   //模型估计

Iteration 0:   log likelihood =  -2091.094  
Iteration 1:   log likelihood =  -2091.094  

Generalized structural equation model             Number of obs   =       1500
Log likelihood =  -2091.094

-----------------------------------------------------------------------------------
                  |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
------------------+----------------------------------------------------------------
perform_gr2 <-    |
            satis |    .415528   .0170752    24.34   0.000     .3820612    .4489948
          support |   .2578802   .0205485    12.55   0.000     .2176059    .2981546
            _cons |   1.509674   .0102077   147.90   0.000     1.489667    1.529681
------------------+----------------------------------------------------------------
satis <-          |
          support |   .2288945   .0305047     7.50   0.000     .1691064    .2886826
            _cons |    .019262   .0154273     1.25   0.212    -.0109749    .0494989
------------------+----------------------------------------------------------------
var(e.perform_gr2)|   .1560887   .0056996                      .1453081     .167669
      var(e.satis)|   .3569007   .0130322                      .3322507    .3833795
-----------------------------------------------------------------------------------

. gsem, coeflegend      //计算效应

Generalized structural equation model             Number of obs   =       1500
Log likelihood =  -2091.094

-----------------------------------------------------------------------------------
                  |      Coef.  Legend
------------------+----------------------------------------------------------------
perform_gr2 <-    |
            satis |    .415528  _b[perform_gr2:satis]
          support |   .2578802  _b[perform_gr2:support]
            _cons |   1.509674  _b[perform_gr2:_cons]
------------------+----------------------------------------------------------------
satis <-          |
          support |   .2288945  _b[satis:support]
            _cons |    .019262  _b[satis:_cons]
------------------+----------------------------------------------------------------
var(e.perform_gr2)|   .1560887  _b[var(e.perform_gr2):_cons]
      var(e.satis)|   .3569007  _b[var(e.satis):_cons]
-----------------------------------------------------------------------------------

. nlcom _b[perform_gr2:satis]*_b[satis:support]     //直接估计间接效应,ab = 0.095,P值显著,中介效应存在

       _nl_1:  _b[perform_gr2:satis]*_b[satis:support]

------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _nl_1 |   .0951121   .0132645     7.17   0.000     .0691142    .1211099
------------------------------------------------------------------------------

. nlcom _b[perform_gr2:support]+_b[perform_gr2:satis]*_b[satis:support]  //计算总效应,总效应 c=0.353

       _nl_1:  _b[perform_gr2:support]+_b[perform_gr2:satis]*_b[satis:support]

------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _nl_1 |   .3529923   .0238251    14.82   0.000     .3062959    .3996886
------------------------------------------------------------------------------

3.3.2 计算置信区间 CI

对于因变量 Y 是多分类变量,中介变量 M 为多分类变量的情况,可以考虑通过直接计算置信区间 CI 的方式进行中介效应分析。下文中我们结合 Stata 和 R 语言为大家提供一种多阶段计算置信区间 CI 的方法,用以分析类别变量的中介效应。

调用数据并定义变量

数据基本描述:这是一组有关大型百货公司销售人员的数据,我们用来讨论经理的激励与员工工作表现之间的关系,基本假设是:经理的激励 (perceived support from managers) 可能通过影响员工的工作满意度 (job satisfaction) 而影响员工的工作表现 (job performance) 。

下文中为了解释方便,我们将因变量 Y 处理为三分类变量,中介变量 M 处理为二分类变量

. use http://www.stata-press.com/data/r15/gsem_multmed    //调用数据
(Fictional job-performance data)

. summarize    //查看数据分布

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      branch |      1500          38    21.65593          1         75
     support |      1500    .0084667    .5058316       -1.6        1.8
       satis |      1500       .0212    .6087235       -1.6          2
     perform |      1500    5.005317    .8949845    2.35022   8.084294

. gen satis_gr2=.
(1500 missing values generated)

. replace satis_gr2=0 if satis<=0
(802 real changes made)

. replace satis_gr2=1 if satis>=0&satis!=.
(803 real changes made)

. tab satis_gr2,missing     //将中介变量处理为类别变量,satis_gr2=0 代表员工工作满意度低,satis_gr2=1 代表员工工作满意度高

  satis_gr2 |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |        697       46.47       46.47
          1 |        803       53.53      100.00
------------+-----------------------------------
      Total |      1,500      100.00

. gen perform_gr3=.
(1500 missing values generated)

. replace perform_gr3=1 if perform<4.5
(418 real changes made)

. replace perform_gr3=2 if perform>=4.5&perform<5.5
(648 real changes made)

. replace perform_gr3=3 if perform>=5.5&perform!=.
(434 real changes made)

. tab perform_gr3,missing  //将因变量处理为类别变量,perform_gr3=1 代表员工工作表现不好, perform_gr3=2 代表员工工作表现一般,per
> form_gr3=3 代表员工工作表现优秀

perform_gr3 |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |        418       27.87       27.87
          2 |        648       43.20       71.07
          3 |        434       28.93      100.00
------------+-----------------------------------
      Total |      1,500      100.00

数据分布可以看到,我们的样本量为 1500, 其中所需使用的变量为:

方法介绍

前文介绍了多种中介效应的检验方法,其中的一个重点在于建立置信区间 (CI),在此基础之上检验中介效应。文献中有几种计算置信区间(CI)的方法。这些方法大致可以分为四类:(1) the distribution of the product (e.g., MacKinnon, Fritz, Williams, & Lockwood, 2007; MacKinnon, Lockwood,Hoffman, West, & Sheets, 2002); (2) the Monte Carlo method (MacKinnon, Lockwood, & Williams, 2004); (3) resampling methods (e.g., bootstrap resampling; MacKinnon et al., 2004); (4) the asymptotic normal distribution method.

Tofighi & MacKinnon (2011) 在文章中介绍了 RMediation 程序包,可以通过 R语言实现上述多个建立置信区间检验中介效应的方法。

具体实施步骤

第一步,我们需要通过 Stata 对变量之间关系进行分析。这一步可以用逐步检验回归系数的方法进行,这里我们采用 two-step regression (Zhao, Lynch et al. 2010)

logit satis_gr2 support     //分析中介变量和自变量之间的关系
mlogit perform_gr3 support satis_gr2,base(1)   //控制中介变量后,看自变量和因变量之间的关系

具体结果如下:

. logit satis_gr2 support

Iteration 0:   log likelihood = -1035.9723  
Iteration 1:   log likelihood =  -1022.275  
Iteration 2:   log likelihood = -1022.2694  
Iteration 3:   log likelihood = -1022.2694  

Logistic regression                               Number of obs   =       1500
                                                  LR chi2(1)      =      27.41
                                                  Prob > chi2     =     0.0000
Log likelihood = -1022.2694                       Pseudo R2       =     0.0132

------------------------------------------------------------------------------
   satis_gr2 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     support |   .5433644   .1052097     5.16   0.000     .3371572    .7495716
       _cons |     .13959   .0522446     2.67   0.008     .0371925    .2419875
------------------------------------------------------------------------------

. mlogit perform_gr3 support satis_gr2,base(1)

Iteration 0:   log likelihood = -1616.2168  
Iteration 1:   log likelihood = -1313.8029  
Iteration 2:   log likelihood = -1280.1679  
Iteration 3:   log likelihood = -1279.5623  
Iteration 4:   log likelihood = -1279.5621  
Iteration 5:   log likelihood = -1279.5621  

Multinomial logistic regression                   Number of obs   =       1500
                                                  LR chi2(4)      =     673.31
                                                  Prob > chi2     =     0.0000
Log likelihood = -1279.5621                       Pseudo R2       =     0.2083

------------------------------------------------------------------------------
 perform_gr3 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
1            |  (base outcome)
-------------+----------------------------------------------------------------
2            |
     support |   1.362149   .1541686     8.84   0.000     1.059984    1.664314
   satis_gr2 |   1.533283   .1508245    10.17   0.000     1.237673    1.828894
       _cons |   .0722626   .0838749     0.86   0.389    -.0921292    .2366545
-------------+----------------------------------------------------------------
3            |
     support |   2.866737   .2031084    14.11   0.000     2.468651    3.264822
   satis_gr2 |   3.563446   .2090607    17.05   0.000     3.153694    3.973197
       _cons |  -2.000543   .1634619   -12.24   0.000    -2.320922   -1.680164
------------------------------------------------------------------------------

第二步:联网状态,在 R 语言中安装程序包

install.packages("RMediation")
library (package = "RMediation")

命令 install.packages("RMediation") 可以自动在网上获取 RMediation 程序包,library (package = "RMediation") 将安装包载入正在使用的 R 环境,具体结果如下:

> install.packages("RMediation")
试开URL’https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/RMediation_1.1.4.zip'
Content type 'application/zip' length 96732 bytes (94 KB)
downloaded 94 KB

程序包‘RMediation’打开成功,MD5和检查也通过

下载的二进制程序包在
        C:\Users\1212\AppData\Local\Temp\Rtmp6XTJIW\downloaded_packages里

> library (package = "RMediation")
载入需要的程辑包:MASS
载入需要的程辑包:lavaan
This is lavaan 0.6-5
lavaan is BETA software! Please report any bugs.
载入需要的程辑包:e1071

第三步,使用 R 语言 RMediation 软件包进行计算

medci (mu.x = 0.543, mu.y = 1.533, se.x = 0.105, se.y = 0.151, rho = 0, alpha = 0.1, type = "prodclin")    
medci (mu.x = 0.543, mu.y = 3.563, se.x = 0.105, se.y = 0.209, rho = 0, alpha = 0.1, type = "prodclin")
> medci (mu.x = 0.543, mu.y = 1.533, se.x = 0.105, se.y = 0.151, rho = 0, alpha = 0.1, type = "prodclin")    
$`95% CI`
[1] 0.5456374 1.1411552

$Estimate
[1] 0.832419

$SE
[1] 0.1813394

结果中,相较于员工员工表现不好,员工是否满意对于经理激励和员工工作表现一般的中介作用置信区间为 (0.546, 1.141),区间不包含 0 ,中介效应成立。

> medci (mu.x = 0.543, mu.y = 3.563, se.x = 0.105, se.y = 0.209, rho = 0, alpha = 0.1, type = "prodclin")
$`95% CI`
[1] 1.301461 2.588863

$Estimate
[1] 1.934709

$SE
[1] 0.3915647

结果中,相较于员工员工表现不好,员工是否满意对于经理激励和员工工作表现优秀的中介作用置信区间为 (1.301, 2.589),区间不包含 0 ,中介效应成立。

拓展:type 是类型,默认值为 "PRODCLIN" 程序,还可选 "DOP" (RDOP 程序)、"MC" (蒙特卡罗方法)、"asymp" (AND方法) 或 "all" (使用所有四种方法)。需要注意,参数类型的值必须用单引号或双引号括起来。

连享会计量方法专题…… https://gitee.com/arlionn/Course

4. 总结

参考文献:

关于我们


欢迎加入Stata连享会(公众号: StataChina)
上一篇 下一篇

猜你喜欢

热点阅读