Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

48
Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer

Transcript of Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Page 1: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Using SPSS and R for Mediation Analyses

Matt BaldwinLucas Keefer

Page 2: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

We will cover…

• Simple and simultaneous mediation• Sequential mediation• Moderated mediation• Three models using PROCESS for SPSS• R-code for those models• MAYBE: Monte-Carlo estimator online

Page 3: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Terms

X

M

Y

a b

c’

Indirect effect: a * b ≠ 0

Page 4: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Terms

• Simple mediation– One predictor– One outcome– One or more mediators in parallel

• Sequential mediation– One predictor– One outcome – More than one mediator in sequence

Page 5: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Terms

• Moderated mediation: strength of indirect effect depends on one or more moderators– One predictor– One outcome– One or more mediators (not in sequence)– One or more moderators

• Bootstrapping: estimating a parameter from repeated resampling of the data– Approximates sampling distribution– Uses standard error to calculate confidence interval

for indirect effect (a*b)

Page 6: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

PROCESS: SPSS

• Andrew Hayes, Ph.D.• http://afhayes.com/introduction-to-

mediation-moderation-and-conditional-process-analysis.html

Page 7: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.
Page 8: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.
Page 9: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Installing PROCESS

Page 10: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.
Page 11: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

PROCESS: Models

• Templates PDF file: templates.pdf

Page 12: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model 4

• Simple mediation• Multiple mediators in parallel

Page 13: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model 4

Page 14: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.
Page 15: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model 4 Output

Page 16: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model 4 Output

• Remember, if the confidence interval does NOT include zero, the indirect effect is significant!

Page 17: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model 6

• Sequential mediation• Multiple mediators in sequence

Page 18: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model 6

Page 19: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.
Page 20: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model 6 Output

Page 21: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model 7

• Moderated mediation• Multiple mediators in parallel

Page 22: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model 7

Page 23: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model 7

Page 24: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model 7 Output

Page 25: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Bootstrapping Mediation in R

Page 26: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

The boot package

• Install the boot package and dependencies• What does it do?

Page 27: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

The boot package

boot(model, data, R = #)

Number of Resamples

Model

Data

Page 28: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Data

• Whatever object contains the data you are analyzing

• If there are filters to apply, do so beforehand:– med_data <- subset(data, filters)

Page 29: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model

• The model must be specified manually:• mediation<-function(med_data,i){• d <- med_data[i,]• model1<- lm(M~X, data=d) • model2<-lm(Y~M+X, data=d) • ab <- coef(model1)[2]*coef(model2)[2]• return(as.numeric(ab))• }

Page 30: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model

• The model must be specified manually:• mediation<-function(med_data,i){• d <- med_data[i,]• model1<- lm(M~X, data=d) • model2<-lm(Y~M+X, data=d) • ab <- coef(model1)[2]*coef(model2)[2]• return(as.numeric(ab))• }

Page 31: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model

• The model must be specified manually:• mediation<-function(med_data,i){• d <- med_data[i,]• model1<- lm(M~X, data=d) • model2<-lm(Y~M+X, data=d) • ab <- coef(model1)[2]*coef(model2)[2]• return(as.numeric(ab))• }

Page 32: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model

• The model must be specified manually:• mediation<-function(med_data,i){• d <- med_data[i,]• model1<- lm(M~X, data=d) • model2<-lm(Y~M+X, data=d) • ab <- coef(model1)[2]*coef(model2)[2]• return(as.numeric(ab))• }

Page 33: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model

• The model must be specified manually:• mediation<-function(med_data,i){• d <- med_data[i,]• model1<- lm(M~X, data=d) • model2<-lm(Y~M+X, data=d) • ab <- coef(model1)[2]*coef(model2)[2]• return(as.numeric(ab))• }

Page 34: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Model

• The model must be specified manually:• mediation<-function(med_data,i){• d <- med_data[i,]• model1<- lm(M~X, data=d) • model2<-lm(Y~M+X, data=d) • ab <- coef(model1)[2]*coef(model2)[2]• return(as.numeric(ab))• }

Page 35: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Simple Mediation

Page 36: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Simple Mediation

• mediation<-function(med_data,i){• d <- med_data[i,]• model1<- lm(M~X, data=d) • model2<-lm(Y~M+X, data=d) • ab <- coef(model1)[2]*coef(model2)[2]• return(as.numeric(ab))• }

Page 37: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Simple Mediation

• boot(model, data, R = #)• obj <- boot(mediation, med_data, R = 10000)• boot.ci(obj)

Page 38: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Moderated Mediation

Page 39: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Moderated Mediation

• mediation<-function(med_data,i){• d <- med_data[i,]• model1<- lm(M~X+W+WX, data=d) • model2<-lm(Y~M+X, data=d) • ab <- coef(model1)[2]*coef(model2)[2]• return(as.numeric(ab))• }

Page 40: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Sequential Mediation

Page 41: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Sequential Mediation

• mediation<-function(med_data,i){• d <- med_data[i,]• model1<- lm(M1~X, data=d) • model2<-lm(M2~M1+X, data=d) • model3<-lm(Y~M2+M1+X, data=d) • ab <- coef(model1)[2]*coef(model2)[2]*

coef(model3)[2]• return(as.numeric(ab))• }

Page 42: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Final Pointers

• Want to add model covariates? Just add them into all the model commands (NOT as first predictor)

Page 43: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Final Pointers

• Want to add model covariates? Just add them into all the model commands (NOT as first predictor)

• Because you are specifying the model manually, triple check your work!

Page 44: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Final Pointers

• Want to add model covariates? Just add them into all the model commands (NOT as first predictor)

• Because you are specifying the model manually, triple check your work! – It won’t catch misspecification

Page 45: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Final Pointers

• Want to add model covariates? Just add them into all the model commands (NOT as first predictor)

• Because you are specifying the model manually, triple check your work! – It won’t catch misspecification– Make sure it is storing the right coefficient

Page 46: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Thank you

Page 47: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Monte-Carlo Estimator

• Similar to bootstrapping method• Calculates indirect effect from a, b, and

standard error• http://www.quantpsy.org/medmc/medmc.ht

m

Page 48: Using SPSS and R for Mediation Analyses Matt Baldwin Lucas Keefer.

Thank You

• Please feel free to ask us questions now or later!

• Matt’s email: [email protected]• Lucas’ email: [email protected]• These slides can be found at

http://matthewbaldwin.yolasite.com/tools.php