📌 조절매개효과분석(moderated mediation effect analysis)
📝 ex) mtcars
> str(mtcars)
'data.frame': 32 obs. of 11 variables:
$ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
$ cyl : num 6 6 4 6 8 6 8 4 4 6 ...
$ disp: num 160 160 108 258 360 ...
$ hp : num 110 110 93 110 175 105 245 62 95 123 ...
$ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
$ wt : num 2.62 2.88 2.32 3.21 3.44 ...
$ qsec: num 16.5 17 18.6 19.4 17 ...
$ vs : num 0 0 1 1 0 1 0 1 1 1 ...
$ am : num 1 1 1 0 0 0 0 0 0 0 ...
$ gear: num 4 4 4 3 3 3 3 4 4 4 ...
$ carb: num 4 4 1 1 2 1 4 2 2 4 ...
매개변수 모델
> model.M <- lm(wt ~ disp * am, data=mtcars)
> model.M <- lm(wt ~ disp + am + disp:am, data=mtcars)
위 두 코드는 같은 결과를 나타낸다.
종속변수 모델
> model.Y <- lm(mpg ~ disp * am + wt * am, data=mtcars)
> model.Y <- lm(mpg ~ disp + am + wt + disp:am + wt:am, data=mtcars)
위 두 코드는 같은 결과를 나타낸다.
> library(mediation)
> set.seed(12)
자동변속기
mediate(model.m=매개변수 모델, model.y=종속변수 모델, covariates=list(조절변수 수준), treat='독립변수', mediator='매개변수', boot=TRUE, sims=추출할 개수)
> model.med1 <- mediate(model.m=model.M,
+ model.y=model.Y,
+ covariates=list(am=0),
+ treat='disp',
+ mediator='wt',
+ boot=TRUE, sims=500)
> summary(model.med1)
Causal Mediation Analysis
Nonparametric Bootstrap Confidence Intervals with the Percentile Method
(Inference Conditional on the Covariate Values Specified in `covariates')
Estimate 95% CI Lower 95% CI Upper p-value
ACME -0.0103 -0.0230 0.00 0.21
ADE -0.0173 -0.0371 0.00 0.06 .
Total Effect -0.0276 -0.0365 -0.02 <2e-16 ***
Prop. Mediated 0.3719 -0.1751 1.02 0.21
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Sample Size Used: 32
Simulations: 500
수동변속기
> model.med2 <- mediate(model.m=model.M,
+ model.y=model.Y,
+ covariates=list(am=1),
+ treat='disp',
+ mediator='wt',
+ boot=TRUE, sims=500)
> summary(model.med2)
Causal Mediation Analysis
Nonparametric Bootstrap Confidence Intervals with the Percentile Method
(Inference Conditional on the Covariate Values Specified in `covariates')
Estimate 95% CI Lower 95% CI Upper p-value
ACME -0.0408 -0.0868 -0.01 0.024 *
ADE -0.0182 -0.1251 0.01 0.140
Total Effect -0.0590 -0.1511 -0.04 <2e-16 ***
Prop. Mediated 0.6916 0.1372 1.18 0.024 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Sample Size Used: 32
Simulations: 500
📌 두 모델 비교
수동변속기의 간접효과가 더 크고 통계적으로 유의하다.
그러나 간접효과가 통계적으로 유의한지는 통계적 검정 절차가 필요하다.
📌 매개효과분석
> set.seed(12)
> model.med <- mediate(model.m=model.M,
+ model.y=model.Y,
+ treat='disp', mediator='wt',
+ boot=TRUE, sims=500)
📌 매개효과 모델에서의 조절효과 검정
test.modmed(object=매개효과분석 모델, covariates.1=list(조절변수 수준1), covariates.2=list(조절변수 수준2))
> set.seed(12)
> test.modmed(object=model.med,
+ covariates.1=list(am=0), covariates.2=list(am=1),
+ sims=500)
Test of ACME(covariates.1) - ACME(covariates.2) = 0
data: estimates from model.med
ACME(covariates.1) - ACME(covariates.2) = 0.030573, p-value = 0.044
alternative hypothesis: true ACME(covariates.1) - ACME(covariates.2) is not equal to 0
95 percent confidence interval:
0.005078988 0.083113017
Test of ADE(covariates.1) - ADE(covariates.2) = 0
data: estimates from model.med
ADE(covariates.1) - ADE(covariates.2) = 0.0008819, p-value = 0.98
alternative hypothesis: true ADE(covariates.1) - ADE(covariates.2) is not equal to 0
95 percent confidence interval:
-0.03518009 0.10092579
Test of ACME(covariates.1) - ACME(covariates.2) = 0
Test of ADE(covariates.1) - ADE(covariates.2) = 0