最近,工作上遇到需要进行多水平中介模型(Multilevel Mediation Model)的分析需求,尤其是2(X)-2(M)-1(Y)这种跨水平中介模型。
由于最近进行数据分析的工具主要转到R上,所以,花费了些时间去找R语句分析2-2-1这种多水平中介模型,但目前依然没有找到比较趁手的包(mlma
这个包的用法属实还需要花些时间去理解)。
无奈,只能转向n年没有使用过的Mplus,好在Mplus方面的资源,尤其是关于复杂模型的语句还是不少,最后,用Mplus来解决问题了。
现在分析个数据,真的是恨不得把SPSS,stata,R,Mplus都开开,心疼我可怜的小surface,有时候烫得感觉下一秒就要炸了……
话不多说,趁着干活中间,换换脑子,记录下各种跨水平中介模型的Mplus语句吧,毕竟之前自己也Bing了不少时间。方便以后检索吧。
本部分是:关于Y在level1的四种模型:
1-1-1
,1-2-1
,2-1-1
,2-2-1
① 1-1-1 model
TITLE: 1-1-1 mediation (traditional MLM)
DATA: FILE IS mydata.dat; ! text file containing raw data in long format
VARIABLE: NAMES ARE
id x m y;
USEVARIABLES ARE
id x m y;
CLUSTER IS id; ! Level-2 grouping identifier
ANALYSIS: TYPE IS TWOLEVEL RANDOM;
MODEL: ! model specification follows
%WITHIN% ! Model for Within effects follows
sa | m ON x; ! regress m on x, call the random slope "sa"
sb | y ON m; ! regress y on m, call the random slope "sb"
sc | y ON x; ! regress y on x, call the random slope "sc"
%BETWEEN% ! Model for Between effects follows
sa sb sc m y; ! estimate Level-2 (residual) variances for sa, sb, sc, m, and y
[sa](a); ! estimate the mean of sa, call it "a"
[sb](b); ! estimate the mean of sb, call it "b"
sa WITH sc m y; ! estimate Level-2 covariances of sa with sc, m, and y
sb WITH sc m y; ! estimate Level-2 covariances of sb with sc, m, and y
sc WITH m y; ! estimate Level-2 covariances of sc with m and y
y WITH m; ! estimate Level-2 covariance of y and m
sa WITH sb(cab); ! estimate Level-2 covariance of sa and sb, call it "cab"
MODEL CONSTRAINT: ! section for computing indirect effect
NEW(ind); ! name the indirect effect
ind=a*b+cab; ! compute the indirect effect
OUTPUT: TECH1 TECH8 CINTERVAL; ! request parameter specifications, starting values,
! optimization history, and confidence intervals for all effects
还有1-1-1 model (unconflated MLM)
,1-1-1 model with fixed slopes (MSEM)
,1-1-1 model with random slopes (MSEM)
,详见文末资料来源。
② 1-2-1 model
TITLE: 1-2-1 mediation (MSEM)
DATA: FILE IS mydata.dat; ! text file containing raw data in long format
VARIABLE: NAMES ARE id x m y;
USEVARIABLES ARE id x y m;
CLUSTER IS id; ! Level-2 grouping identifier
BETWEEN ARE m; ! identify variables with only Between variance;
! variables that are not claimed as "BETWEEN ARE" or "WITHIN ARE" can have
! both Within and Between variance
ANALYSIS: TYPE IS TWOLEVEL RANDOM;
MODEL: ! model specification follows
%WITHIN% ! Model for Within effects follows
y ON x; ! regress y on x
%BETWEEN% ! Model for Between effects follows
x m y; ! estimate Level-2 (residual) variances for x, m, and y
m ON x(a); ! regress m on x, call the slope "a"
y ON m(b); ! regress y on m, call the slope "b"
y ON x; ! regress y on x
MODEL CONSTRAINT: ! section for computing indirect effect
NEW(indb); ! name the indirect effect
indb=a*b; ! compute the Between indirect effect
OUTPUT: TECH1 TECH8 CINTERVAL; ! request parameter specifications, starting values,
! optimization history, and confidence intervals for all effects
③ 2-1-1 model
TITLE: 2-1-1 mediation (traditional MLM)
DATA: FILE IS mydata.dat; ! text file containing raw data in long format
VARIABLE: NAMES ARE
group x m y;
USEVARIABLES ARE
group x m y;
BETWEEN IS x; ! identify variables with only Between variance;
! variables that are not claimed as "BETWEEN IS" or "WITHIN IS" can have
! both Within and Between variance
CLUSTER IS group; ! Level-2 grouping identifier
ANALYSIS: TYPE IS TWOLEVEL RANDOM;
MODEL: ! model specification follows
%WITHIN% ! Model for Within effects follows
m y; ! estimate Level-1 (residual) variances for m and y
y ON m(b); ! regress y on m, call the slope "b"
%BETWEEN% ! Model for Between effects follows
x m y; ! estimate Level-2 (residual) variances for x, m, and y
m ON x(a); ! regress m on x, call the slope "a"
y ON m(b); ! regress y on m, constrain the slope equal to "b"
y ON x; ! regress y on x
MODEL CONSTRAINT: ! section for computing indirect effect
NEW(indb); ! name the indirect effect
indb=a*b; ! compute the Between indirect effect
OUTPUT: TECH1 TECH8 CINTERVAL; ! request parameter specifications, starting values,
! optimization history, and confidence intervals for all effects
还有2-1-1 mediation (unconflated MLM)
,2-1-1 mediation (MSEM)
,2-1-1 mediation (MSEM)
,详见文末资料来源。
④ 2-2-1 model
TITLE: 2-2-1 mediation with latent variables (MSEM)
DATA: FILE IS mydata.dat; ! text file containing raw data in long format
VARIABLE: NAMES ARE
group x1 x2 x3 m1 m2 m3 m4 m5 y1 y2 y3 y4 y5;
MISSING ARE *; ! missing data denoted "*" in mydata.dat
USEVARIABLES ARE
group x1 x2 x3 m1 m2 m3 m4 m5 y1 y2 y3 y4 y5;
BETWEEN ARE x1 x2 x3 m1 m2 m3 m4 m5; ! identify variables with only Between variance;
! variables that are not claimed as "BETWEEN ARE" or "WITHIN ARE" can have
! both Within and Between variance
CLUSTER IS group; ! Level-2 grouping identifier
ANALYSIS: TYPE IS TWOLEVEL RANDOM; ! tell Mplus to perform multilevel modeling
MODEL: ! model specification follows
%WITHIN% ! Model for Within effects follows
yw BY y1 y2 y3 y4 y5; ! yw is a factor defined by y1, y2, y3, y4, and y5
%BETWEEN% ! Model for Between effects follows
mb BY m1 m2 m3 m4 m5; ! mb is a factor defined by m1, m2, m3, m4, and m5
xb BY x1 x2 x3; ! xb is a factor defined by x1, x2, and x3
yb BY y1 y2 y3 y4 y5; ! yb is a factor defined by y1, y2, y3, y4, and y5
mb ON xb(a); ! regress mb on xb, call the slope "a"
yb ON mb(b); ! regress yb on mb, call the slope "b"
yb ON xb; ! regress yb on xb, too
MODEL CONSTRAINT: ! section for computing indirect effect
NEW(ab); ! name the indirect effect
ab = a*b; ! compute the indirect effect
OUTPUT: TECH1 TECH8 CINTERVAL; ! request parameter specifications, starting values,
! optimization history, and confidence intervals for all effects
本部分是:关于Y在level2的四种模型:
2-2-2
,1-2-2
,1-1-2
,2-1-2
⑤ 2-2-2 model
这个,其实就是最普通且最简单的中介分析了,我就不放了,各种软件都可以做。
⑥ 1-2-2 model
TITLE: 1-2-2 mediation (MSEM)
DATA: FILE IS mydata.dat; ! text file containing raw data in long format
VARIABLE: NAMES ARE id x m y;
USEVARIABLES ARE id x m y;
CLUSTER IS id; ! Level-2 grouping identifier
BETWEEN ARE m y; ! identify variables with only Between variance;
! variables that are not claimed as "BETWEEN ARE" or "WITHIN ARE" can have
! both Within and Between variance
ANALYSIS: TYPE IS TWOLEVEL RANDOM;
MODEL: ! model specification follows
%WITHIN% ! Model for Within effects follows
x; ! estimate Level-1 (residual) variance for x
%BETWEEN% ! Model for Between effects follows
m y; ! estimate Level-2 (residual) variances for m and y
m ON x(a); ! regress m on x, call the slope "a"
y ON m(b); ! regress y on m, call the slope "b"
y ON x; ! regress y on x
MODEL CONSTRAINT: ! section for computing indirect effect
NEW(indb); ! name the indirect effect
indb=a*b; ! compute the Between indirect effect
OUTPUT: TECH1 TECH8 CINTERVAL; ! request parameter specifications, starting values,
! optimization history, and confidence intervals for all effects
⑦ 1-1-2 model
TITLE: 1-1-2 mediation (similar code used in example 3)
DATA: FILE IS mydata.dat; ! text file containing raw data in long format
VARIABLE: NAMES ARE
group x1 x2 x3 x4 m1 m2 m3 y1 y2 y3 y4 y5;
MISSING ARE *; ! missing data denoted "*" in mydata.dat
USEVARIABLES ARE
group x1 x2 x3 x4 m1 m2 m3 y1 y2 y3 y4 y5;
BETWEEN ARE y1 y2 y3 y4 y5; ! identify variables with only Between variance;
! variables that are not claimed as "BETWEEN ARE" or "WITHIN ARE" can have
! both Within and Between variance
CLUSTER IS group; ! Level-2 grouping identifier
ANALYSIS: TYPE IS TWOLEVEL RANDOM;
MODEL: ! model specification follows
%WITHIN% ! Model for Within effects follows
mw BY m1 m2 m3; ! mw is a factor defined by m1, m2, and m3
xw BY x1 x2 x3 x4; ! xw is a factor defined by x1, x2, x3, and x4
mw ON xw; ! regress mw on xw
%BETWEEN% ! Model for Between effects follows
mb BY m1 m2 m3; ! mb is a factor defined by m1, m2, and m3
xb BY x1 x2 x3 x4; ! xb is a factor defined by x1, x2, x3, and x4
yb BY y1 y2 y3 y4 y5; ! yb is a factor defined by y1, y2, y3, y4, and y5
yb ON mb(b); ! regress yb on mb, call the slope "b"
yb ON xb; ! regress yb on xb
mb ON xb(a); ! regress mb on xb, call the slope "a"
MODEL CONSTRAINT: ! section for computing indirect effect
NEW(ab); ! name the indirect effect
ab = a*b; ! compute the Between indirect effect
OUTPUT: TECH1 TECH8 CINTERVAL; ! request parameter specifications, starting values,
! optimization history, and confidence intervals for all effects
⑧ 2-1-2 model
TITLE: 2-1-2 mediation (MSEM)
DATA: FILE IS mydata.dat; ! text file containing raw data in long format
VARIABLE: NAMES ARE
id x m y;
USEVARIABLES ARE
id x m y;
CLUSTER IS id; ! Level-2 grouping identifier
BETWEEN ARE x y; ! identify variables with only Between variance;
! variables that are not claimed as "BETWEEN ARE" or "WITHIN ARE" can have
! both Within and Between variance
ANALYSIS: TYPE IS TWOLEVEL RANDOM;
MODEL: ! model specification follows
%WITHIN% ! Model for Within effects follows
m; ! estimate Level-1 (residual) variance for m
%BETWEEN% ! Model for Between effects follows
x y; ! estimate Level-2 (residual) variances for x and y
m ON x(a); ! regress m on x, call the slope "a"
y ON m(b); ! regress y on m, call the slope "b"
y ON x; ! regress y on x
MODEL CONSTRAINT: ! section for computing indirect effect
NEW(indb); ! name the indirect effect
indb=a*b; ! compute the Between indirect effect
OUTPUT: TECH1 TECH8 CINTERVAL; ! request parameter specifications, starting values,
! optimization history, and confidence intervals for all effects
这些其实已有研究者总结了,关键词检索:Mplus syntax files for single- and multilevel mediation models
,就能找到。
另外,在搜这个资料的过程中,我又找到了个各种复杂模型的Mplus语句大全:offbeat.group.shef.ac.uk/FIO/mplusmedmod.htm
网站内容部分截图: