I have decided to write an R version of the PROCESS macro for mediation, moderation, and conditional process analysis, which is called RePROCESS.

I will regularly update the package as I add more models and post updates on this blog.

Unlike the SPSS macro, it generates the plots for you, and runs the analyses run at least four times faster! However, I’m not sure how computation time compares to the SAS version.

The development version of the package has now been released and allows you to run Model 1, which is for a single predictor and moderator variable.

Installation

First, you need to have the devtools package installed as you will be installing from the Github repo.

# 1. Install devtools
install.packages("devtools")

# 2. Install RePROCESS from Github
devtools::install_github("smancuso/RePROCESS")

# 3. Load the RePROCESS package
library(RePROCESS)

Model 1 parameters

Below is the output from the help file via help("model1"). This displays all the available options.

RePROCESS Model 1

Description

Implementation of the PROCESS (v3.0) Model 1 for moderation and conditional effects based on Hayes (2018).

Automatically generates interaction plots and Johnson-Neyman plots of areas of significance.

Predictor or moderating variables can be continuous, binary, or multicategorical. However, both cannot be multicategorical.

Usage

model1(Y, X, W, CV = NULL, ci = 0.95, B = 5000, boot.inf = FALSE,
  seed = 1234, digits = 4, probe.p = 0.1, mean.center = FALSE,
  se.HC = c("none", "HC0", "HC1", "HC2", "HC3", "HC4"), 
  x.multicat = FALSE,
  x.code = c("indicator", "sequential", "helmert", "effect"),
  w.multicat = FALSE, 
  w.code = c("indicator", "sequential", "helmert", "effect"), 
  cond.type = c("perc", "mean"), 
  JN = FALSE, plot.JN = FALSE,
  plot.int = FALSE, 
  data)

Arguments

Y Dependent variable.
X Independent variable.
W Moderating variable.
CV Covariates. Defaults to NULL.
ci Confidence interval range. Defaults to 0.95.
B Number of bootstrap resamples. Defaults to 5000.
boot.inf Obtains bootstrapped confidence intervals for regression. Defaults to FALSE.
seed Seed value to replicate analyses. Defaults to 1234.
digits Number of digits to output. Defaults to 4.
mean.center Mean centre the predictors X and W. Defaults to FALSE.
se.HC Use HC consistent standard errors. Options are: c("none", "HC0", "HC1", "HC2", "HC3", "HC4"). Defaults to "none".
x.multicat Logical value to identify if X is a multicategorical variable. Defaults to FALSE.
x.code Coding format for multicategorical X. Options are c("indicator", "sequential", "helmert", "effect"). Defaults to "indicator".
w.multicat Logical value to identify if W is a multicategorical variable. Defaults to FALSE.
w.code Coding format for multicategorical W. Options are c("indicator", "sequential", "helmert", "effect"). Defaults to "indicator".
cond.type Conditioning values for W. Options are "perc" for percentiles (.16, .50, .84) or "mean" for M, M +/- SD. Defaults to "perc".
JN Calculates the Johnson-Neyman areas of statistical significance. Defaults to FALSE.
plot.JN Plots the Johnson-Neyman areas of statistical significance. Defaults to FALSE.
plot.int Plots the interaction plot. Defaults to FALSE.
data Name of data.frame or tibble.
p.probe Maximum p-value of interaction term at which conditional effects should be probed. Defaults to .10.

Author(s)

Sam Mancuso

References

Hayes, A. F. (2018). Introduction to Mediation, Moderation, and Conditional Process Analysis (2e). The Guilford Press: New York.

Running the Model 1 analysis

Caveats

Before running the analyses, please note the following caveats and limitations.

  • The model1 function cannot have multicategorical predictors for both X and W. Otherwise, X and W can be a mix of dichotomous, multicategorical, or continuous variable.
  • Notably, dichotomous or multicategorical X and/or W variables cannot be of the class "factor". They should either be "numerical" or "labelled" (see below).

Example: 10.2 Sex discrimination in the work place

I am going to run the sex discrimination in the workplace example analysis from Hayes (2018, p. 354) book. The data files for the examples, can be found via his website.

First, I am going to load the protest data in the CSV format.

# Read data
protest <- read.csv("protest.csv", header = TRUE)

# View data
head(protest)

You will notice that the variables are named:

  • subnum
  • protest
  • sexism
  • angry
  • liking
  • respappr

As a result of importing the data, the protest is of class "integer". It is actually a multicategorical variable coded as follows:

  • 0 = no protest
  • 1 = individual protest
  • 2 = collective protest

You should change it to the "numeric" class using the as.numeric() function or change it to the "labelled" class using the labelled() function from the haven package. I prefer using the latter, but either will suffice.

Coding dichotomous or multicategorical variables

The RePROCESS package automatically loads the haven, and dplyr packages so you don’t have to load them manually. Now, let’s change the protest variable so that it is of class "labelled".

Putting it all together:

Running the analyses

To recreate Example 10.2, use the following arguments. Note that variable names much be entered as strings.

  • Y = "liking"
  • X = "protest"
  • W = "sexism"
  • x.multicat = TRUE
  • x.code = "indicator"
  • data = protest
  • plot.int = TRUE

The x.multicat = TRUE argument specifies that protest tells the function that protest multicategorical variable, while x.code = "indicator" tells the function to use indicator coding to represent the protest variable in the data.

The plot.int = TRUE tells the function to generate an interaction plot.

The function is called as follows:

model1(
Y = "liking",
X = "protest",
W = "sexism",
CV = NULL,
x.multicat = TRUE,
x.code = "indicator",
data = protest,
plot.int = TRUE
)

Which gives you the following output:

---------------------------------------------------------------------
RePROCESS Procedure for R Version 0.1
Based on SPSS/SAS PROCESS Macro by Andrew F. Hayes www.afhayes.com
Coded by Sam Mancuso sammancuso.com
---------------------------------------------------------------------
Model : 1
Y : liking
X : protest
W : sexism

Covariates:
None

Sample size: 129

Coding of categorical X variable (protest) for analysis:

X1 X2
0 0 0
1 1 0
2 0 1

---------------------------------------------------------------------

OUTCOME VARIABLE:
liking

Model Summary
R R.sq MSE F.value df1 df2 p
0.3673 0.1349 0.9919 3.8372 5 123 0.0029

Model
coeff se t p LLCI ULCI
(Intercept) 7.7062 1.0525 7.3218 0.0000 5.6229 9.7896
protest2 -4.1288 1.4985 -2.7553 0.0068 -7.0949 -1.1626
protest3 -3.4908 1.4078 -2.4796 0.0145 -6.2775 -0.7041
sexism -0.4725 0.2053 -2.3017 0.0230 -0.8788 -0.0662
protest2:sexism 0.9012 0.2875 3.1346 0.0022 0.3321 1.4703
protest3:sexism 0.7778 0.2752 2.8266 0.0055 0.2331 1.3225

Test(s) of unconditional interaction(s):
R2.change F.value df1 df2 p
protest x sexism 0.0822 5.8474 2 123 0.0038

Moderator value(s):
sexism	4.2500

Effect se t p LLCI ULCI
protest2 -0.2985 0.3402 -0.8775 0.3819 -0.9720 0.3749
protest3 -0.1851 0.3089 -0.5991 0.5502 -0.7966 0.4264

Test of conditional means
F.value df1 df2 p
0.4021 2 123 0.6698

Estimated conditional means being compared:
protest liking
0 5.6981
1 5.3996
2 5.5131
----------------

Moderator value(s):
sexism	5.1200

Effect se t p LLCI ULCI
protest2 0.4855 0.2191 2.2163 0.0285 0.0519 0.9192
protest3 0.4916 0.2158 2.2782 0.0244 0.0645 0.9188

Test of conditional means
F.value df1 df2 p
3.3377 2 123 0.0388

Estimated conditional means being compared:
protest liking
0 5.2871
1 5.7726
2 5.7787
----------------

Moderator value(s):
sexism	5.8960

Effect se t p LLCI ULCI
protest2 1.1849 0.3052 3.8825 2e-04 0.5808 1.7890
protest3 1.0952 0.3158 3.4684 7e-04 0.4702 1.7203

Test of conditional means
F.value df1 df2 p
8.818 2 123 3e-04

Estimated conditional means being compared:
protest liking
0 4.9204
1 6.1053
2 6.0156
----------------

--------------------- ANALYSIS NOTES AND ERRORS ---------------------

Level of confidence for all confidence intervals in output:
95.0000

W values in conditional tables are the 16th, 50th, and 84th percentiles.

It also generates the following interaction plot:

Example 10.2 Plot

Citation

If you use this package, please cite both Hayes (2018) and the following:

Mancuso, S. G. (2018). RePROCESS: Mediation, Moderation, and Conditional Process Analysis for R. R package version 0.1.0. http://www.sammancuso.com

Feedback

If there are any issues with the package, either leave a comment here or raise and issue over on Github.

Stay tuned for Model 4…

Reference

Hayes, A. F. (2018). Introduction to Mediation, Moderation, and Conditional Process Analysis (2e). The Guilford Press: New York.

2 thoughts on “RePROCESS: PROCESS macro for R – Model 1

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.