# 1 Theory

• Baron & Kenny, 1986 (citations as of 3/27/17 = 66,271)
• See Kenny’s website for useful information: http://davidakenny.net/cm/mediate.htm
• Extremely common and popular method in social, but now used throughout psychology

• Baron & Kenny define moderator and mediator for us:

“The moderator function of third variables, which partitions a focal independent variable into subgroups that establish its domains of maximal effectiveness regarding a given dependent variable”

“The mediator function of a third variable, which represents the generative mechanism through which the focal independent variable can influence the dependent variable of interest”"

• In short, the mediator explains why X->Y, and it’s through M
• Having one mediator is called simple mediation.

Preacher & Hayes, 2008 explain this figure as:

“X’s causal effect into its indirect effect on Y through M and its direct effect on Y (path c’). Path c’ a represents the effect of X on the proposed mediator, whereas path b is the effect of M on Y partialling out the effect of X. The indirect effect of X on Y through M can then be quantified as the product of a and b (i.e., ab)”

• The mediation is trying explain the direct path seen in the total effect (the analysis without the mediation term)
• So we can connect the total effect back the simple moderation: $c = c' + ab$

$total = direct + indirect$

## 1.1 A hypothetical example of mediation

• Children with the ability to delay gratification tend to be more success in life (Marshmallow test)
• You hypothesize that it is their respect/trust in of authority figures to keep their promises that is intermediating in the causal chain for success in later life
• You collect 268 4-year-olds, give them the Marshmallow test (measure their time to eat the marshmallow). Rather than waiting 20 years, you operationalize success as how they did at the end of the year on kindergarten entrance exam. You also measure how must trust they have in authority figures (1-10 scale through an established battery for children)
library(car)
set.seed(42)
# For simulation of mediation steps see Hallgren, 2013
# path a strength
a=.4
# path b strength
b=.4
# path c' strength
cp=.01
# people
n <- 268
# Normal distribution of time (mins)
X <- rnorm(n, 5, 2)
# Mediator
M <- a*X+rnorm(n, 0, 1)
# Our equation to  create Y
Y <- cp*X + b*M + rnorm(n, sd=1)
#Built our data frame
Marshmallow.Data<-data.frame(Success=Y,Time=X,Trust=M)

### 1.1.1 Baron and Kenny Steps to testing mediation

• Step 1: Test Y~X
• Is there a relationship? If yes you can proceed (if not stop as you have no total effect path to try to mediate)
library(stargazer)
Model.1<-lm(Success~Time, data= Marshmallow.Data)
stargazer(Model.1,type="html",
intercept.bottom = FALSE,
single.row=FALSE,
notes.append = FALSE,
header=FALSE)
 Dependent variable: Success Constant 0.027 (0.169) Time 0.143*** (0.032) Observations 268 R2 0.070 Adjusted R2 0.067 Residual Std. Error 1.010 (df = 266) F Statistic 20.096*** (df = 1; 266) Note: p<0.1; p<0.05; p<0.01
• Step 2: Test M~X
• Is there a relationship? If yes you can proceed (if not stop as you have no path a)
Model.2<-lm(Trust~Time, data= Marshmallow.Data)
stargazer(Model.2,type="html",
intercept.bottom = FALSE,
single.row=FALSE,
notes.append = FALSE,
header=FALSE)
 Dependent variable: Trust Constant 0.305* (0.168) Time 0.334*** (0.032) Observations 268 R2 0.296 Adjusted R2 0.294 Residual Std. Error 1.001 (df = 266) F Statistic 112.073*** (df = 1; 266) Note: p<0.1; p<0.05; p<0.01
• Step 3: Test Y ~ M + X
• Is there a relationship? If yes you can proceed (if not stop as you have no path b)
• X is now here as an control for M to predict X (some people say leave it out, Kenny says leave it in)
Model.3<-lm(Success~Trust+Time, data= Marshmallow.Data)
stargazer(Model.3,type="html",
intercept.bottom = FALSE,
single.row=FALSE,
notes.append = FALSE,
header=FALSE)
 Dependent variable: Success Constant -0.086 (0.159) Trust 0.369*** (0.058) Time 0.019 (0.035) Observations 268 R2 0.195 Adjusted R2 0.189 Residual Std. Error 0.942 (df = 265) F Statistic 32.059*** (df = 2; 265) Note: p<0.1; p<0.05; p<0.01
• Step 4: Test X ~ Y + M
• Estabilish complete mediation
• Reverse path: M is now here as an control for Y to predict X
• If there is complete mediation path c’ will go to zero
• If there is partial mediation path c’ will remain (but should get smaller) if paths a and b were meaningful
Model.4<-lm(Time~Success+Trust, data= Marshmallow.Data)
stargazer(Model.4,type="html",
intercept.bottom = FALSE,
single.row=FALSE,
notes.append = FALSE,
header=FALSE)
 Dependent variable: Time Constant 3.212*** (0.192) Success 0.058 (0.106) Trust 0.864*** (0.093) Observations 268 R2 0.297 Adjusted R2 0.292 Residual Std. Error 1.632 (df = 265) F Statistic 56.039*** (df = 2; 265) Note: p<0.1; p<0.05; p<0.01

### 1.1.2 Interpretation

• So we have complete mediation, the c’ prime path went to nearly zero
• In this case time was not significant, but it could be with larger samples…
• The variance of time was explained by the mediator, path ab
• but how do we test the significance of the mediator, path ab?

### 1.1.3 Significance of indirect path

• Well in our case, both path a and b were strong and significant (joint significance)
• Joint significance is an indirect test of the indirect path and is mostly holds up more modern methods (but you probably cannot publish just by showing significance on paths a and b)
• We need a direct test the significance of the indirect path (ab)
• The Baron and Kenny method was to use the Sobel’s test, which estimates the SE on terms ab of our equation, $$c = c' + ab$$ and tests it against zero
• Sobel assumes of paths a and b as independent, it’s very conservative and very low powered (see http://davidakenny.net/cm/mediate.htm for details)
• There are other tests, but Sobel was the most common in its day
library(bda)
mediation.test(Marshmallow.Data$Trust,Marshmallow.Data$Time,Marshmallow.Data$Success) ## Sobel Aroian Goodman ## z.value 5.478920e+00 5.461111e+00 5.496905e+00 ## p.value 4.279292e-08 4.731637e-08 3.865154e-08 • Bootstrapping has replaced the Sobel’s test so we will focus on using that test in the examples • There are two type of bootstrapping, BCa and percentile methods (remember we covered them at the start of the term) • BCa can be a bit anti-conservative but more powerful, percentile method is less powerful more conservative #### 1.1.3.1 Mediation package in R • You will only need Model.2 (M~X) and Model.3 (Y~M+X) from above • but the language changes a bit in the way we talk about these things as this package can handle larger designs with control variables and many different types of regressions (linear, generalized, and mixed, mixture, censored and survival) library(mediation) Med.Boot.BCa <- mediate(Model.2, Model.3, boot = TRUE, boot.ci.type = "bca", sims=200, treat="Time", mediator="Trust") summary(Med.Boot.BCa) ## ## Causal Mediation Analysis ## ## Nonparametric Bootstrap Confidence Intervals with the BCa Method ## ## Estimate 95% CI Lower 95% CI Upper p-value ## ACME 0.1235 0.0876 0.17 <2e-16 *** ## ADE 0.0194 -0.0308 0.09 0.56 ## Total Effect 0.1429 0.0926 0.21 <2e-16 *** ## Prop. Mediated 0.8644 0.5683 1.53 <2e-16 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Sample Size Used: 268 ## ## ## Simulations: 200 plot(Med.Boot.BCa) • ACME: Average Causal Mediation Effects (ACME) [total effect - direct effect] • ADE: Average Direct Effects [total effect - indirect effect] • Total Effect = Direct (ADE) + Indirect (ACME) • These are unstandardized effects Prop. Mediated: conceptually ACME / Total effect • Note: I did 200 simulations for time, but 2000 is best if you are doing BCa. • By changing the code we can get percentile method over BCa Med.Boot.perc <- mediate(Model.2, Model.3, boot = TRUE, boot.ci.type = "perc", sims=200, treat="Time", mediator="Trust") summary(Med.Boot.perc) ## ## Causal Mediation Analysis ## ## Nonparametric Bootstrap Confidence Intervals with the Percentile Method ## ## Estimate 95% CI Lower 95% CI Upper p-value ## ACME 0.1235 0.0857 0.16 <2e-16 *** ## ADE 0.0194 -0.0366 0.08 0.59 ## Total Effect 0.1429 0.0860 0.20 <2e-16 *** ## Prop. Mediated 0.8644 0.5165 1.39 <2e-16 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Sample Size Used: 268 ## ## ## Simulations: 200 plot(Med.Boot.perc) • These results match Baron and Kenny and the process macro in SPSS • The benefit here is you test mediator in glm or mixed (cannot be done so easily in SPSS) • The drawback in R is you want to test things like multi-mediation you need to program it yourself (for now) ### 1.1.4 Testing the mediator as moderator? • Could it be that our mediator is really just a moderator? ## 1.2 Power • When you plan to run mediation you must carefully think about the power you might need. • Because the M is basically collinear X you will need more subjects than you would normally think • Kenny has worked out an easy app to estimate power for simple designs • https://davidakenny.shinyapps.io/MedPower/ • For larger designs you need to build custom simulations and the Mediation package can help ## 1.3 Partial Mediation • When the direct effect and indirect effect are both real • Many times you don’t have the power for complete mediation and you might think its partial mediation • Kenny suggests using Hayes (2013) recommendation: never drawing the conclusion that its complete or partial • Below I have created a well-powered (power = .8) examine both the direct and indirect effects library(car) set.seed(42) # For simulation of mediation steps see Hallgren, 2013 # path a strength a=.4 # path b strength b=.4 # path c' strength cp=.2 # people n <- 177 # Normal distribution of time (mins) X <- rnorm(n, 5, 2) # Mediator M <- a*X+rnorm(n, 0, 1) # Our equation to create Y Y <- cp*X + b*M + rnorm(n, sd=1) #Built our data frame Marshmallow.Data.Part<-data.frame(Success=Y,Time=X,Trust=M) Part.Model.2<-lm(Trust~Time, data= Marshmallow.Data.Part) Part.Model.3<-lm(Success~Trust+Time, data= Marshmallow.Data.Part) Part.Med.Boot.BCa <- mediate(Part.Model.2, Part.Model.3, boot = TRUE, boot.ci.type = "bca", sims=200, treat="Time", mediator="Trust") summary(Part.Med.Boot.BCa) ## ## Causal Mediation Analysis ## ## Nonparametric Bootstrap Confidence Intervals with the BCa Method ## ## Estimate 95% CI Lower 95% CI Upper p-value ## ACME 0.1726 0.0956 0.26 <2e-16 *** ## ADE 0.1724 0.0994 0.29 <2e-16 *** ## Total Effect 0.3450 0.2676 0.42 <2e-16 *** ## Prop. Mediated 0.5002 0.2584 0.71 <2e-16 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Sample Size Used: 177 ## ## ## Simulations: 200 plot(Part.Med.Boot.BCa) ## 1.4 Moderated-Mediated • Moderation is trying to figure out the factors they influence the strength of the relationship between X to Y • Mediation is trying to figure out the intermediating factors involved into getting from X to Y • Moderated-Mediated is that effect of the mediator is moderated • In practical terms, what if our mediation above (respect/trust in authority) was moderated by parenting styles of parents • Strict parents created respect of the authority, while permissive parents create opposition to authority • Measurement scale from -3 to 3 (permissive to authoritative) • Thus our mediation of respect/trust is stronger for kids with authoritative than permissive parents • but it could also be that children from authoritative parents will be much more well-behaved in general • We will examine different types of models to examine this effect set.seed(42) # path a strength a=.4 # path b strength b=.4 # path c' strength cp=.01 # people n <- 268 # Normal distribution of time (mins) X <- rnorm(n, 5, 2) # Moderator Mod<-runif(n, -3, 3) # Mediator M <- a*X*Mod+rnorm(n, 0, 1) # Our equation to create Y Y <- cp*X*Mod + b*M + M*Mod + rnorm(n, sd=1) #Built our data frame Marshmallow.Mod<-data.frame(Success=Y,Time=X,Trust=M,Parents=Mod) ### 1.4.1 Moderation on Path a, b, c’ • In this case we think the direct (c’) and indirect path (a,b) is moderated by Parenting style • So we have to interact it in Model 2 and Model 3 • Model 2 from Kenny becomes, $$M ~ X*Mod$$ • Model 3 from Kenny becomes, $$Y ~ M*Mod+X*Mod$$ • Note this is Hayes’ process model 59 Mod.Med.Model.2<-lm(Trust~Time*Parents, data= Marshmallow.Mod) stargazer(Mod.Med.Model.2,type="html", intercept.bottom = FALSE, single.row=FALSE, notes.append = FALSE, header=FALSE)  Dependent variable: Trust Constant -0.065 (0.173) Time 0.002 (0.033) Parents -0.281*** (0.100) Time:Parents 0.455*** (0.020) Observations 268 R2 0.922 Adjusted R2 0.922 Residual Std. Error 1.022 (df = 264) F Statistic 1,047.406*** (df = 3; 264) Note: p<0.1; p<0.05; p<0.01 Mod.Med.Model.3<-lm(Success~Trust*Parents+Time*Parents, data= Marshmallow.Mod) stargazer(Mod.Med.Model.3,type="html", intercept.bottom = FALSE, single.row=FALSE, notes.append = FALSE, header=FALSE)  Dependent variable: Success Constant -0.055 (0.165) Trust 0.383*** (0.058) Parents 0.024 (0.097) Time -0.014 (0.032) Trust:Parents 1.009*** (0.011) Parents:Time 0.013 (0.032) Observations 268 R2 0.977 Adjusted R2 0.976 Residual Std. Error 0.971 (df = 262) F Statistic 2,202.624*** (df = 5; 262) Note: p<0.1; p<0.05; p<0.01 • In this moderation package we list the moderator as a covariate and set the levels we wish to control for • We can use the +/- 1SD from the mean (also we can use zero if wanted to see the average parent) • This allows us to view impact of the moderator on the direct and indirect effect • Lets look at permissive parents first • Still no direct effect, but an effect for ACME Permissive<-mean(Marshmallow.Mod$Parents)-sd(Marshmallow.Mod$Parents) Permissive ## [1] -1.680635 Mod.Med.Boot.BCa.1 <- mediate(Mod.Med.Model.2, Mod.Med.Model.3, covariates = list(Parents = Permissive), boot = TRUE, boot.ci.type = "bca", sims=200, treat="Time", mediator="Trust") summary(Mod.Med.Boot.BCa.1) ## ## Causal Mediation Analysis ## ## Nonparametric Bootstrap Confidence Intervals with the BCa Method ## ## (Inference Conditional on the Covariate Values Specified in covariates') ## ## Estimate 95% CI Lower 95% CI Upper p-value ## ACME 1.0028 0.9030 1.11 <2e-16 *** ## ADE -0.0355 -0.1340 0.08 0.47 ## Total Effect 0.9673 0.8658 1.06 <2e-16 *** ## Prop. Mediated 1.0367 0.9165 1.15 <2e-16 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Sample Size Used: 268 ## ## ## Simulations: 200 plot(Mod.Med.Boot.BCa.1) • Lets let look at authoritative parents • Still no direct effect, but a stonger effect for ACME Authoritative<-mean(Marshmallow.Mod$Parents)+sd(Marshmallow.Mod\$Parents)
Authoritative
## [1] 1.71852
Mod.Med.Boot.BCa.2 <- mediate(Mod.Med.Model.2, Mod.Med.Model.3,
covariates = list(Parents = Authoritative), boot = TRUE,
boot.ci.type = "bca", sims=200, treat="Time", mediator="Trust")
summary(Mod.Med.Boot.BCa.2)
##
## Causal Mediation Analysis
##
## Nonparametric Bootstrap Confidence Intervals with the BCa Method
##
## (Inference Conditional on the Covariate Values Specified in covariates')
##
##                Estimate 95% CI Lower 95% CI Upper p-value
## ACME              1.659        1.449         1.90  <2e-16 ***
## ADE               0.007       -0.129         0.10    0.87
## Total Effect      1.666        1.481         1.91  <2e-16 ***
## Prop. Mediated    0.996        0.943         1.08  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Sample Size Used: 268
##
##
## Simulations: 200
plot(Mod.Med.Boot.BCa.2)

• To get a significance test on if the moderator is causing a difference in the direct or indirect effects we can use this code
• Note:
Mod.Med.Boot.BCa.3 <- mediate(Mod.Med.Model.2, Mod.Med.Model.3, boot = TRUE,
boot.ci.type = "bca", sims=5, treat="Time", mediator="Trust")
test.modmed(Mod.Med.Boot.BCa.3, covariates.1 = list(Parents = Permissive),
covariates.2 = list(Parents = Authoritative), sims = 200)
##
##  Test of ACME(covariates.1) - ACME(covariates.2) = 0
##
## data:  estimates from Mod.Med.Boot.BCa.3
## ACME(covariates.1) - ACME(covariates.2) = -0.65647, p-value <
## 2.2e-16
## alternative hypothesis: true ACME(covariates.1) - ACME(covariates.2) is not equal to 0
## 95 percent confidence interval:
##  -0.9168896 -0.4100557
##
##
##  -0.2575408  0.1494442