?? 連享會主頁:
?? 論文班·精講8篇論文 ?? 2021 年 5.2-4 日 ?? 主講:梁平漢(中山大學(xué));張川川 (浙江大學(xué));連玉君 (中山大學(xué)) ?? 課程主頁 :https:///lianxh/TE , 誠邀助教6名
New! lianxh
命令發(fā)布了: GIF 動圖介紹 隨時(shí)搜索 Stata 推文、教程、手冊、論壇,安裝命令如下: ? . ssc install lianxh
作者: 曹琳君 (南開大學(xué))郵箱: jilyo@stu.xmu.edu.cn & 1072759894@qq.com
目錄
1. 背景介紹
2. med4way 命令介紹
2.1 理論部分
2.2 安裝和語法結(jié)構(gòu)
3. Stata 實(shí)例
4. 結(jié)語
5. 參考資料
6. 相關(guān)推文
1. 背景介紹 中介分析是闡明 X 和 Y 如何關(guān)聯(lián)的重要機(jī)制之一。在連享會以往的推文中,我們介紹了傳統(tǒng)的中介效應(yīng)分析方法(具體鏈接見相關(guān)推文部分),包括逐步檢驗(yàn)回歸系數(shù)法、系數(shù)乘積檢驗(yàn)法和系數(shù)差異檢驗(yàn)法。
然而,在使用傳統(tǒng)的中介效應(yīng)分析時(shí),研究者也面臨下列問題:(1)如果沒有對中介-結(jié)果混雜因素 (mediator-outcome confounders)進(jìn)行控制,那么傳統(tǒng)的中介方法產(chǎn)生的結(jié)果可能有很大的偏差 (Andrea Bellavia, 2021)。(2)傳統(tǒng)的中介分析沒有包含 的交互作用 (exposure-mediator interaction)。如果交互作用確實(shí)存在且被忽視,直接和間接的影響就會有偏差 (Andrea Bellavia, 2021)。(3)傳統(tǒng)的中介分析主要適用于 和 是連續(xù)變量且影響是線性的情況。對于非線性的影響,用傳統(tǒng)的中介分析方法分析并不容易 (Andrea Bellavia, 2021)。
因此,能夠解決上述問題的因果中介分析方法逐漸受到研究者的重視。在下文中,作者主要向大家介紹一種可以同時(shí)分析中介效應(yīng) (M)和 交互效應(yīng) (X-M)的因果中介分析命令 med4way
。
對因果中介分析背景有更多興趣的研究者也可以點(diǎn)擊下方的參考鏈接。參考鏈接:Mediation and interaction analysis 。
溫馨提示: 文中鏈接在微信中無法生效。請點(diǎn)擊底部「閱讀原文」 。
2. med4way 命令介紹 2.1 理論部分 如下圖所示,包含 交互作用的因果中介分析將 對 的影響(總體效應(yīng))分為四個(gè)效應(yīng):純間接效應(yīng)或被調(diào)節(jié)的主效應(yīng) (pure natural indirect effect or mediated main effect),參照交互效應(yīng) (reference interaction),被調(diào)節(jié)的交互效應(yīng) (mediated interaction) 和被控制的直接效應(yīng) (Controlled direct effect)。
在表中 是結(jié)果變量 是暴漏因素也就是我們常說的 , 是潛在中介變量。 表示當(dāng)暴漏因素 處于 a 水平且潛在的中介變量 處于 m 水平時(shí), 的取值。
2.2 安裝和語法結(jié)構(gòu) med4way
命令是 Andrea Discacciati, Andrea Bellavia, Jane J Lee, Maitreyi Mazumdar & Linda Valeri (2018) 根據(jù)上述表格所編寫的 Stata 新命令。
安裝和數(shù)據(jù)下載有兩種途徑:
(1) 從作者的 github 主頁下載:
. net install med4way, from('https://raw./anddis/med4way/master/') replace *-下載范例數(shù)據(jù) . net get med4way, from('https://raw./anddis/med4way/master/')
(2) 從連享會主頁下載:
*-安裝程序文件 . net install med4way , from(https://file./StataCMD/med4way) *-下載附帶數(shù)據(jù) . net get med4way , from(https://file./StataCMD/med4way)
語法結(jié)構(gòu)如下:
. help med4way . med4way depavr varlist [if] [in], a0(real) a1(real) m(real) yreg(string) mreg(string)
varlist
:依次為暴露因素、中介變量 、多個(gè)混雜因素(可有可無,視情況而定);a0(real)
:real 表示暴露因素的參考維度 (the referent level of the exposure);假設(shè)暴露因素 表示是否吸煙, 表示不吸煙,那么 0 就是參考維度。a1(real)
:real 表示暴露因素的真實(shí)維度 (the actual level of the exposure);假設(shè)暴露因素 表示是否吸煙,暴露因素 表示吸煙,那么1就是真實(shí)維度。m(real)
:real 表示中介變量的維度 (the level of the mediator);yreg(string)
:string 表示為結(jié)果指定的回歸模型形式 (the form of the regression model for the outcome);mreg(string)
:string 表示為中介指定的回歸模型形式 (the form of the regression model for the mediator )。3. Stata 實(shí)例 下面我們用一個(gè) med4way 命令的模擬數(shù)據(jù)集 med4way_example_1.dta 進(jìn)行演示。在該數(shù)據(jù)集中結(jié)果變量和中介變量都是二元變量。
. net get med4way , from(https://file./StataCMD/med4way) . use med4way_example_1.dta . med4way y_bin treat m_bin cvar1 cvar2 cvar3, /// a0(0) a1(1) m(0) /// yreg (logistic) mreg(logistic) /* Notes: y_bin:因變量 treat:暴露因素 m_bin:中介變量 cvar1:混雜因素1 cvar2:混雜因素2 cvars:混雜因素3 */
模型的運(yùn)行結(jié)果如下:
Summary Outcome (yvar): y_bin Exposure (avar): treat Mediator (mvar): m_bin Covariates (cvars): cvar1 cvar2 cvar3 Model for the outcome (yreg): logistic Model for the mediator (mreg): logistic Referent exposure level (a0): 0 Actual exposure level (a1): 1 Mediator level for the decomposition (m): 0 Fixed values of the covariates (c): .577 .319 62.26 -> Model for the outcome Iteration 0: log likelihood = -690.9676 Iteration 1: log likelihood = -589.56724 Iteration 2: log likelihood = -589.33454 Iteration 3: log likelihood = -589.33446 Iteration 4: log likelihood = -589.33446 Logistic regression Number of obs = 1,000 LR chi2(6) = 203.27 Prob > chi2 = 0.0000 Log likelihood = -589.33446 Pseudo R2 = 0.1471 ---------------------------------------------------------------------------------- y_bin | Coef. Std. Err. z P>|z| [95% Conf. Interval] -----------------+---------------------------------------------------------------- treat | -.2944844 .289416 -1.02 0.309 -.8617292 .2727605 m_bin | 1.046198 .2400432 4.36 0.000 .5757223 1.516674 _treatXm_bin_000 | .9821457 .3321434 2.96 0.003 .3311566 1.633135 cvar1 | .1219094 .1451617 0.84 0.401 -.1626023 .4064212 cvar2 | .1908434 .158203 1.21 0.228 -.1192287 .5009155 cvar3 | .0451507 .0065279 6.92 0.000 .0323562 .0579451 _cons | -3.823604 .4667596 -8.19 0.000 -4.738436 -2.908772 ---------------------------------------------------------------------------------- -> Model for the mediator Iteration 0: log likelihood = -588.16878 Iteration 1: log likelihood = -555.60573 Iteration 2: log likelihood = -555.11944 Iteration 3: log likelihood = -555.11923 Iteration 4: log likelihood = -555.11923 Logistic regression Number of obs = 1,000 LR chi2(4) = 66.10 Prob > chi2 = 0.0000 Log likelihood = -555.11923 Pseudo R2 = 0.0562 ------------------------------------------------------------------------------ m_bin | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- treat | .2400897 .1477509 1.62 0.104 -.0494968 .5296762 cvar1 | .3107653 .1491474 2.08 0.037 .0184418 .6030888 cvar2 | -.5623266 .154374 -3.64 0.000 -.8648942 -.259759 cvar3 | .0335621 .0065424 5.13 0.000 .0207393 .0463849 _cons | -1.188081 .4246957 -2.80 0.005 -2.02047 -.3556931 ------------------------------------------------------------------------------ -> 4-way decomposition: delta method ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- tereri | .9330728 .2970645 3.14 0.002 .350837 1.515309 ereri_cde | -.1102571 .108841 -1.01 0.311 -.3235814 .1030673 ereri_intref | .9440357 .28698 3.29 0.001 .3815654 1.506506 ereri_intmed | .0620038 .0435735 1.42 0.155 -.0233986 .1474062 ereri_pie | .0372904 .0243739 1.53 0.126 -.0104815 .0850623 ------------------------------------------------------------------------------ tereri=total excess relative risk; ereri_cde=excess relative risk due to controlled direct effect; ereri_intref=excess relative risk due to reference interaction; ereri_intmed=excess relative risk due to mediated interaction; ereri_pie=excess relative risk due to pure indirect effect.
模型1是各因素對 因變量 的回歸,模型2是各因素對中介變量 的回歸。最后一張表是總效應(yīng)的分解結(jié)果。
4. 結(jié)語 關(guān)于 med4way
的基本介紹在這里就結(jié)束了,想要深入了解的學(xué)者也可以閱讀下方的參考資料。由于地址限制,如果文中提供的下載方式無法奏效,大家可以直接訪問如下碼云倉庫,手動下載相關(guān)命令和數(shù)據(jù)文件。方法為:點(diǎn)擊【克隆/下載】,下載倉庫的 zip 文件,解壓后放置為 D:\med4way ,在 Stata 命令窗口執(zhí)行 net install med4way, from(D:\med4way)
即可安裝。
https:///caolinjun/med4way,或 https:///arlionn/med4way。 5. 參考資料