【Mplus语句】多水平中介模型

最近,工作上遇到需要进行多水平中介模型(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-11-2-12-1-12-2-1

① 1-1-1 model

1-1-1.png
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

1-2-1.png
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

2-1-1.png
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

2-2-1.png
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-21-2-21-1-22-1-2

⑤ 2-2-2 model

2-2-2.png

这个,其实就是最普通且最简单的中介分析了,我就不放了,各种软件都可以做。

⑥ 1-2-2 model

1-2-2.png
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

1-1-2.png
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

2-1-2.png
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

网站内容部分截图:

Mplus1.png
Mplus2.png
Mplus3.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,454评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,553评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,921评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,648评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,770评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,950评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,090评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,817评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,275评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,592评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,724评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,409评论 4 333
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,052评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,815评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,043评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,503评论 2 361
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,627评论 2 350