R - Moderated Mediation Analysis with PROCESS Model 7 & Model 8

Running Hayes' PROCESS-macro (Version 3.5 and later) with R

Arndt Regorz, Dipl. Kfm. & M.Sc. Psychologie, 07/14/2021


For years the PROCESS macro has been the standard way of testing conditional indirect effects (moderated mediation, mediated moderation) when using SPSS. At the end of 2020 Hayes has released the PROCESS function for R, too. This video will show you how to run and interpret a moderated mediation analysis with Hayes' PROCESS function for R / RStudio. In addition, you can finde the PROCESS syntax used for testing a moderated mediation.

Primarily, the video explains PROCESS models 7 and 8, that is a moderated mediation (conditional process analysis) with a moderated a-path from the independent variable to the mediator. However, at the end of the video there is some additional information you could use if you want to test PROCESS models 14 or 15 within R (models with a moderated b-path).

Content

  1. Video tutorial
  2. Downloading PROCESS
  3. Initializing the Code
  4. PROCESS syntax for a moderated mediation
  5. Additional options
  6. More information

1. Video tutorial PROCESS model 7 & 8 for R


(Note: When you click on this video you are using a service offered by YouTube.)

2. Downloading PROCESS

You can download PROCESS for R from here:
https://www.processmacro.org/download.html

Currently (May, 2021) you will find a folder named “PROCESS v3.5beta for R”. There you will find an R-file “process.r”. Please be aware that it is at this point in time still a beta version so there could be bugs in the code.

3. Initializing the Code

Since PROCESS is not an R package you cannot use the commands install.packages() and library() with it. As a user defined function it has to be installed by running the file “process.r”.

If you open it in Rstudio, run it. It will take a minute or two for the code to run. After that has been completed you have gained a new R function, process(). With this function you can run PROCESS in the R environment in your active R session.

If you do not want to have to rerun the code of process.r each time you open R, then Hayes recommends saving your R workspace after running process.r

4. PROCESS syntax for a moderated mediation

Here you can find my recommendation for the R syntax for testing PROCESS model 7 or model 8, i.e. a moderated mediation with a moderated a-path.

Before you can run them you have to load and initialize the PROCESS-function.

PROCESS model 7

# PROCESS Model 7
process (data = my_data_frame,
y = "DV", x = "IV", m = "MED",
w = "MOD", model = 7,
cov = "COV", center = 2,
moments = 1, modelbt = 1,
boot = 10000, seed = 654321)

PROCESS model 8

# PROCESS Model 8
process (data = my_data_frame,
y = "DV", x = "IV", m = "MED",
w = "MOD", model = 8,
cov = "COV", center = 2,
moments = 1, modelbt = 1,
boot = 10000, seed = 654321)

And if you want to test a moderated mediation with a moderated b-path:

PROCESS model 14

# PROCESS Model 14
process (data = my_data_frame,
y = "DV", x = "IV", m = "MED",
w = "MOD", model = 14,
cov = "COV", center = 2,
moments = 1, modelbt = 1,
boot = 10000, seed = 654321)

Please be extremely careful with this model! In almost all cases it is safer to use model 15 instead.

PROCESS model 15

# PROCESS Model 15
process (data = my_data_frame,
y = "DV", x = "IV", m = "MED",
w = "MOD", model = 15,
cov = "COV", center = 2,
moments = 1, modelbt = 1,
boot = 10000, seed = 654321)

5. Additional Options

The following additional options can be helpful if you run a moderated mediation analysis with PROCESS.

Including covariates

You can include one or more covariates in your model. For two or more covariates you have to bind them together with the c(...)-Funktion.
cov = "age"
cov = c("age", "gender")

Robust standard errors

My code recommendation above uses bootstrapping as a robust method. In addition (or instead of it) you can request robust standard errors, e.g. HC4:
hc = 4

Johnson-Neyman method

If you want Johnson-Neyman significance regions for the moderation results, you can request them:
jn = 1

Changing the number format

You can change the decimal places, e.g. to three:
decimals = 10.3

Adjusting your confidence level

You can adjust the the confidence level, e.g. to 97.5%:
conf = 97.5

6. More Information

If you want to know more about the theory behind a moderated mediation analysis I recommend Andrew Hayes' excellent book:
“Introduction to Mediation, Moderation, and Conditional Process Analysis: A Regression-Based Approach”
http://www.afhayes.com/introduction-to-mediation-moderation-and-conditional-process-analysis.html