查看原文
其他

Stata:中介效应之sgmediation操作

来源:一文读懂中介效应之sgmediation操作


中介效应是指变量间的影响关系(X→Y)不是直接的因果链关系,而是通过一个或一个以上变量(M)的间接影响产生的,此时我们称M为中介变量,而X通过M对Y产生的的间接影响称为中介效应。

中介效应是间接效应的一种,模型中在只有一个中介变量的情况下,中介效应等于间接效应;当中介变量不止一个的情况下,中介效应不等于间接效应,此时间接效应可以是部分中介效应和(或)所有中介效应的总和。

自变量X对因变量Y的影响,如果X变量通过影响M变量来影响Y变量,则M为中介变量。

通常将变量经过中心化转化后,得方程1 :Y=cX+e1;

方程2 :M=aX+e2;

方程3 :Y= c′X+bM+e3。

其中,c是X对Y的总效应,a、b是经过中介变量M的中介效应,c′是直接效应。当只有一个中介变量时,效应之间有c=c′+ab,中介效应的大小用c-c′=ab来衡量。

中介效应检验过程

中介效应是间接效应,无论变量是否涉及潜变量,都可以用结构方程模型分析中介效应。

步骤为:

第一步检验系统c,如果c不显著,Y与X相关不显著,停止中介效应分析,如果显著进行第二步;

第二步依次检验a,b,如果都显著,那么检验c′,c′显著,为部分中间效应模型,c′不显著,为完全中介效应模型;

如果a,b至少 有一个不显著,做Sobel检验,检验的统计量是Z = ^a^b / Sab,显著则中介效应显著,不显著则中介效应不显著。

Sobel检验免费的在线计算器:

“http://www.danielsoper.com/statcalc/calc31.aspx”,只要把这a、b、SEa、SEb四个数输入,就可以直接得到Z值及其单侧与双侧概率。

中介效应检验程序Sobel-Goodman mediation tests

语法格式为:

sgmediation depvar [if exp] [in range] , mv:(mediatorvar) iv(indvar) [ cv(covarlist) quietly ]

选项含义为:

  • depvar表示因变量
  • mv:(mediatorvar) 表示用于指定中介变量
  • iv(indvar) 表示用于指定自变量
  • cv(covarlist)表示用于指定控制变量

案例应用

本例使用hsbdemo数据集,其中science作为DV, math作为IV, read作为中介变量。也就是说,模型说数学影响阅读,而阅读反过来又影响科学。这个模型可能有也可能没有太大的实际意义,但是它将允许我们演示运行一个中介效应测试的过程。我们将使用sgmediation command来完成这个任务,您可以使用findit sgmediation来下载这个命令。

该数据包括200个学生的选择的项目类型(prog, 三种类型 categorical variable), 他们的社会地位(ses 三种地位 categorical variable),写作分数(write, a continuous variable)。导入数据,然后进行查看数据

edit
 desc

数据如下:

help sgmediation

. use "C:\Users\Metrics\Desktop\hsbdemo.dta", clear
(highschool and beyond (200 cases))

. desc

Contains data from C:\Users\Metrics\Desktop\hsbdemo.dta
  obs:           200                          highschool and beyond (200 cases)
 vars:            13                          30 Oct 2009 14:13
 size:        10,000                          
--------------------------------------------------------------------------------------
              storage   display    value
variable name   type    format     label      variable label
--------------------------------------------------------------------------------------
id              float   %9.0g                 
female          float   %9.0g      fl         
ses             float   %9.0g      sl         
schtyp          float   %9.0g      scl        type of school
prog            float   %9.0g      sel        type of program
read            float   %9.0g                 reading score
write           float   %9.0g                 writing score
math            float   %9.0g                 math score
science         float   %9.0g                 science score
socst           float   %9.0g                 social studies score
honors          float   %19.0g     honlab     honors english
awards          float   %9.0g                 
cid             int     %8.0g                 
--------------------------------------------------------------------------------------
Sorted by: 

set more off

进行操作为:

 sgmediation science, mv(read) iv(math)

结果为:

. sgmediation science, mv(read) iv(math)
# 表示mv(read)为中介变量,iv(math)为自变量
Model with dv regressed on iv (path c)

      Source |       SS           df       MS      Number of obs   =       200
-------------+----------------------------------   F(1, 198)       =    130.81
       Model |  7760.55791         1  7760.55791   Prob > F        =    0.0000
    Residual |  11746.9421       198  59.3279904   R-squared       =    0.3978
-------------+----------------------------------   Adj R-squared   =    0.3948
       Total |     19507.5       199  98.0276382   Root MSE        =    7.7025

------------------------------------------------------------------------------
     science |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        math |     .66658   .0582822    11.44   0.000     .5516466    .7815135
       _cons |   16.75789   3.116229     5.38   0.000     10.61264    22.90315
------------------------------------------------------------------------------

Model with mediator regressed on iv (path a)
# 形成路劲a
      Source |       SS           df       MS      Number of obs   =       200
-------------+----------------------------------   F(1, 198)       =    154.70
       Model |  9175.57065         1  9175.57065   Prob > F        =    0.0000
    Residual |  11743.8493       198  59.3123704   R-squared       =    0.4386
-------------+----------------------------------   Adj R-squared   =    0.4358
       Total |    20919.42       199  105.122714   Root MSE        =    7.7015

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        math |    .724807   .0582745    12.44   0.000     .6098887    .8397253
       _cons |   14.07254   3.115819     4.52   0.000     7.928087    20.21699
------------------------------------------------------------------------------

Model with dv regressed on mediator and iv (paths b and c')

      Source |       SS           df       MS      Number of obs   =       200
-------------+----------------------------------   F(2, 197)       =     90.27
       Model |  9328.73944         2  4664.36972   Prob > F        =    0.0000
    Residual |  10178.7606       197  51.6688353   R-squared       =    0.4782
-------------+----------------------------------   Adj R-squared   =    0.4729
       Total |     19507.5       199  98.0276382   Root MSE        =    7.1881

------------------------------------------------------------------------------
     science |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        read |   .3654205   .0663299     5.51   0.000     .2346128    .4962283
        math |   .4017207   .0725922     5.53   0.000     .2585632    .5448782
       _cons |    11.6155   3.054262     3.80   0.000     5.592255    17.63875
------------------------------------------------------------------------------

Sobel-Goodman Mediation Tests
# 程序检验
                     Coef         Std Err     Z           P>|Z|
Sobel               .26485934    .05258136   5.037      4.726e-07
Goodman-1 (Aroian)  .26485934    .05272324   5.024      5.072e-07
Goodman-2           .26485934    .05243909   5.051      4.400e-07

                    Coef      Std Err    Z          P>|Z|
a coefficient   =  .724807   .058274   12.4378          0
b coefficient   =  .365421    .06633   5.50914    3.6e-08
Indirect effect =  .264859   .052581   5.03713    4.7e-07
  Direct effect =  .401721   .072592   5.53394    3.1e-08
   Total effect =   .66658   .058282   11.4371          0

Proportion of total effect that is mediated:  .39734065
Ratio of indirect to direct effect:           .65931219
Ratio of total to direct effect:              1.6593122


In this example the mediation effect of read was statistically significant with approximately 40% of the total effect (of math onscience) being mediated.

在这个例子中,read的中介效果在统计上是显著的,通过这个可以得到(Proportion of total effect that is mediated:  .39734065)大约40%的总效果(数学对科学)是被中介的。

操作案例2

如果需要加入协变量,则为如下命令

sgmediation science, mv(read) iv(math) cv(write)

结果为:

 sgmediation science, mv(read) iv(math) cv(write)

Model with dv regressed on iv (path c)

     Source |       SS           df       MS      Number of obs   =       200
-------------+----------------------------------   F(2, 197)       =     80.84
      Model |  8793.36552         2  4396.68276   Prob > F        =    0.0000
   Residual |  10714.1345       197  54.3864694   R-squared       =    0.4508
-------------+----------------------------------   Adj R-squared   =    0.4452
      Total |     19507.5       199  98.0276382   Root MSE        =    7.3747

------------------------------------------------------------------------------
    science |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       math |   .4757015     .07094     6.71   0.000     .3358022    .6156009
      write |   .3055482   .0701157     4.36   0.000     .1672745     .443822
      _cons |   10.68138   3.293391     3.24   0.001     4.186557    17.17621
------------------------------------------------------------------------------

Model with mediator regressed on iv (path a)

     Source |       SS           df       MS      Number of obs   =       200
-------------+----------------------------------   F(2, 197)       =     96.80
      Model |    10368.63         2  5184.31501   Prob > F        =    0.0000
   Residual |    10550.79       197  53.5573096   R-squared       =    0.4956
-------------+----------------------------------   Adj R-squared   =    0.4905
      Total |    20919.42       199  105.122714   Root MSE        =    7.3183

------------------------------------------------------------------------------
       read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       math |   .5196538   .0703972     7.38   0.000      .380825    .6584826
      write |   .3283984   .0695792     4.72   0.000     .1911828    .4656141
      _cons |   7.541599    3.26819     2.31   0.022     1.096471    13.98673
------------------------------------------------------------------------------

Model with dv regressed on mediator and iv (paths b and c')

     Source |       SS           df       MS      Number of obs   =       200
-------------+----------------------------------   F(3, 196)       =     65.32
      Model |  9752.65806         3  3250.88602   Prob > F        =    0.0000
   Residual |  9754.84194       196  49.7696017   R-squared       =    0.4999
-------------+----------------------------------   Adj R-squared   =    0.4923
      Total |     19507.5       199  98.0276382   Root MSE        =    7.0548

------------------------------------------------------------------------------
    science |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       read |   .3015317   .0686815     4.39   0.000     .1660822    .4369813
       math |   .3190094   .0766753     4.16   0.000      .167795    .4702239
      write |   .2065257   .0707644     2.92   0.004     .0669683    .3460831
      _cons |   8.407353   3.192799     2.63   0.009     2.110703      14.704
------------------------------------------------------------------------------

Sobel-Goodman Mediation Tests

                    Coef         Std Err     Z           P>|Z|
Sobel               .15669211    .04152593   3.773      .00016107
Goodman-1 (Aroian)  .15669211    .04180646   3.748      .00017822
Goodman-2           .15669211    .0412435   3.799      .00014517

                   Coef      Std Err    Z          P>|Z|
a coefficient   =  .519654   .070397   7.38174    1.6e-13
b coefficient   =  .301532   .068681   4.39029    .000011
Indirect effect =  .156692   .041526   3.77336    .000161
 Direct effect =  .319009   .076675   4.16053    .000032
  Total effect =  .475702    .07094   6.70569    2.0e-11

Proportion of total effect that is mediated:  .32939164
Ratio of indirect to direct effect:           .49118333
Ratio of total to direct effect:              1.4911833




操作案例3 bootstrap with case resampling

bootstrap r(ind_eff) r(dir_eff), reps(1000): sgmediation science, mv(read) iv(math)
estat bootstrap, percentile bc

结果为:

 bootstrap r(ind_eff) r(dir_eff), reps(1000): sgmediation science, mv(read) iv(math)
(running sgmediation on estimation sample)

Bootstrap replications (1000)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400
..................................................   450
..................................................   500
..................................................   550
..................................................   600
..................................................   650
..................................................   700
..................................................   750
..................................................   800
..................................................   850
..................................................   900
..................................................   950
..................................................  1000

Bootstrap results                               Number of obs     =        200
                                                Replications      =      1,000

      command:  sgmediation science, mv(read) iv(math)
        _bs_1:  r(ind_eff)
        _bs_2:  r(dir_eff)

------------------------------------------------------------------------------
             |   Observed   Bootstrap                         Normal-based
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _bs_1 |   .2648593   .0548346     4.83   0.000     .1573855    .3723332
       _bs_2 |   .4017207   .0819454     4.90   0.000     .2411106    .5623307
------------------------------------------------------------------------------


. estat bootstrap, percentile bc

Bootstrap results                               Number of obs     =        200
                                                Replications      =       1000

      command:  sgmediation science, mv(read) iv(math)
        _bs_1:  r(ind_eff)
        _bs_2:  r(dir_eff)

------------------------------------------------------------------------------
             |    Observed               Bootstrap
             |       Coef.       Bias    Std. Err.  [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _bs_1 |   .26485934  -.0057812   .05483462    .1520132   .3652509   (P)
             |                                       .1712486   .3799049  (BC)
       _bs_2 |   .40172068   .0059509   .08194541    .2422861    .563365   (P)
             |                                       .2336006   .5417721  (BC)
------------------------------------------------------------------------------
(P)    percentile confidence interval
(BC)   bias-corrected confidence interval


References

Aroian, L.A. (1944). The probability function of the product of two normally distributed variables. Annals of Mathematical Statistics, 18, 265-271.

Baron, R.M. & Kenny, D.A. (1986), Moderator-Mediator Variables Distinction in Social Psychological Research: Conceptual, Strategic, and Statistical Considerations. Journal of Personality and Social Psychology, 51 (6), 1173–82.

Goodman, L.A. (1960) On the exact variance of products. Journal of the American Statistical Association, 55, 708-713.

MacKinnon, D. P. & Dwyer, J. H. (1993). Estimating mediated effects in prevention studies. Evaluation Review, 17, 144-158.

MacKinnon, D. P., Warsi, G., & Dwyer, J. H. (1995). A simulation study of mediated effect measures. Multivariate Behavioral Research, 30(1), 41-62.

Preacher, K. J. & Hayes, A. F. (2004). SPSS and SAS procedures for estimating indirect effects in simple mediation models. Behavior Research Methods, Instruments, & Computers, 36(4), 717-731.

Sobel, M.E. (1982) Asymptotic confidence intervals for indirect effects in structural equation models. Sociological Methodology, 13, 290-312.

Sobel, M.E. (1986) Some new results on indirect effects and their standard errors in covariance structure models. Sociological Methodology, 16, 159-186.

您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存