​Stata:8大中介效应检验命令大比拼 您所在的位置:网站首页 直接效应大于间接效应 ​Stata:8大中介效应检验命令大比拼

​Stata:8大中介效应检验命令大比拼

2023-12-25 11:17| 来源: 网络整理| 查看: 265

方程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,显著则中介效应显著,不显著则中介效应不显著。

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

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

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

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

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

方法1、逐步检验回归系数方法

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

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

reg readmath //分析 x 和 m 之间的关系

reg science readmath // 加入 m,看 x 和 y 之间的关系

操作结果为:

方法2、两步回归法 (two-step regression)

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

reg readmath //分析 x 和 m 之间的关系

reg science readmath // 加入 m,看 x 和 y 之间的关系

方法3、sobel检验--中介效应检验程序Sobel-Goodman mediation tests

语法格式为:

sgmediation depvar [ifexp] [inrange] , mv:(mediatorvar) iv(indvar) [ cv(covarlist) quietly ]

选项含义为:

depvar表示因变量

mv:(mediatorvar) 表示用于指定中介变量

iv(indvar) 表示用于指定自变量

cv(covarlist)表示用于指定控制变量

depvar表示因变量

mv:(mediatorvar) 表示用于指定中介变量

iv(indvar) 表示用于指定自变量

cv(covarlist)表示用于指定控制变量

查看数据

edit

desc

数据如下:

. helpsgmediation

. 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 typeformat label variable label

--------------------------------------------------------------------------------------

id float%9.0g

female float%9.0g fl

ses float%9.0g sl

schtyp float%9.0g scl typeof school

prog float%9.0g sel typeof program

readfloat%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:

. setmore 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

方法4:基于bootstrap的sobel检验方法

操作案例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

方法5 、结构方程中介效应检验

在使用结构方程模型(sem)估计完中介效应之后,我们可以使用medsem命令进一步检验中介效应。

medsem基于使用Stata的-sem命令估计的模型(包括观察到的变量或潜在变量,以及观察到的变量和潜在变量的组合)进行中介分析。有medsem使用两种方法作为其过程的基础。第一种方法是众所周知的Baron and Kenny方法,由Iacobucci等人(2007)调整用于结构方程模型。第二种方法是Zhao等人(2010)的方法。

首先下载安装该命令:

ssc install medsem,replace

命令medsem是专门用于sem命令之后计算中介效应的。

语法格式为:

medsem - Mediation analysis using structural equation modelling

medsem, indep(varname) med(varname) dep(varname) [mcreps(number) stand zlc rit rid]

选项含义为:

indep(varname)代表解释变量(X);

med(varname)代表中介变量(M);

dep(varname)代表被解释变量(Y);

mereps(number)指定蒙特卡罗复制的数量,默认是样本的数量大小;

stand指定输出标准化的系数。当省略这一项时,默认输出非标准化系数;

zlc用于指定(Zhao et al..,2010)的中介效应估计方法,当省略这一选项时,默认是(Iacobucci et al. (2007))改进的BK方法。

选项rit用于指定输出中介效应与总效应之比,即rit, ratio of the indirect effect to the total effect

rid,即 rid用于指定输出中介效应与直接效应之比。

indep(varname)代表解释变量(X);

med(varname)代表中介变量(M);

dep(varname)代表被解释变量(Y);

mereps(number)指定蒙特卡罗复制的数量,默认是样本的数量大小;

stand指定输出标准化的系数。当省略这一项时,默认输出非标准化系数;

zlc用于指定(Zhao et al..,2010)的中介效应估计方法,当省略这一选项时,默认是(Iacobucci et al. (2007))改进的BK方法。

选项rit用于指定输出中介效应与总效应之比,即rit, ratio of the indirect effect to the total effect

rid,即 rid用于指定输出中介效应与直接效应之比。

. qui sem (readanomia71 pwless71)(SES->educ66 occstat66)(Alien67anomia66 pwless66)(F3->anomia67 pwless67)(F4->anomia71 pwless71)(F2 F3anomia66 pwless66)(F3->anomia67 pwless67)(F2



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有