Example of moderated mediation using Process Model 58 in RStudio

Example-of-moderated-mediation-using-Process-model-58-in-RStudio-WEB-b.knit


Youtube video walkthrough: https://youtu.be/lMQEOrd-_Mo

Brief overview of Process Model 58

The figure below is a diagram of the conceptual model that Process Model 58 can be used to test. In this model, the antecedent variable (X) is specified as having a direct and indirect effect (the latter via a mediating variable) on the consequent (Y). Unlike a traditional mediation model, the effect of the antecedent X on the mediator M and the effect of the mediator on the consequent is moderated by variable W.


Parameters are estimated using the Process model using OLS regression equations [unless the consequent is binary, in which case logistic regression is used when estimating part of the overall model]. The parameters in this model [which assumes continuous mediator and consequent variables] are estimated using two OLS regression equations as depicted here:




Example using Process Model 58

Our example involves a re-analysis of data from Gu, Liu, and Chen’s (2022) article, The effect of trait mindfulness on social media rumination: Upward social comparison as a moderated mediator . The dataset was provided by the authors in the supplemental materials for their article. I have resaved the data as a .csv file more conveniently named traitmind_orig_data. You can download a copy of the .csv file for this re-analysis here.

Here is the figure of the conceptual model provided by the authors [they indicate using Process Model 58 in the text of the results section].

In my opinion, the conceptual diagram I provide next is a more accurate reflection of the model they tested [where the covariates are included by default as predictors of both the mediator and the consequent]. I have included descriptive names, as well as the variable names as they appear in the dataset in parentheses.

In this model, the authors postulated that trait mindfulness impacts social media rumination is partially mediated by upward social comparison (USC). Self-esteem (SE) is specified as a moderator of the effect of trait mindfulness on USC and as a moderator of the effect of USC on rumination. [I’ll be honest, I don’t understand the language in the title of ‘Upward Social Comparison as a Moderated Mediator’ since the moderator variable can only be thought of as moderating effects.]

A few issues limiting reproducibility of the original results

As I was putting this presentation together, I found that I was unable to completely reproduce the authors’ results based on the data provided by them and what was described in the methods section of the main text.

Through some investigation, I found some of the correlations in their correlation matrix did not reproduce, with these generally involving the demographic variables they were using as controls in their primary analysis. If there were errors with the control variables supplied in the supplemental materials, then this would certainly explain discrepancies between what I obtained using Process Model 58 below and what is reported by the authors in the article.

Another issue I need to raise is the need for authors to be clear about whether or not they used mean-centering when forming their product terms and which (if any) variables were mean centered. How an analyst addresses the issue of mean-centering during the construction of products will impact the estimates obtained, as well as interpretation of those estimates, for lower order terms in the regression models. Gu et al. (2022) did not explicitly indicate whether or not they chose to use mean centering. In the analysis I provide below, I use mean-centering during construction of products.

One last issue to raise: The Gu et al. (2022) appear to use conditioning values of -1sd, mean, +1sd on the moderator when computing simple slopes and associated tests. Hayes (2022) recommends using the 16th, 50th, and 84th percentiles of the moderator instead, which makes more sense particularly when working with a moderator that is non-normal. This is what I use below.

Generating descriptive statistics and correlations

Using the describe() function from the psych package, we can generate various descriptive statistics for the focal variables in Gu et al.’s (2022) analysis.

library(psych)

#Here, I generate descriptives using a subset of variables in the
#data frame.

describe(traitmind_orig_data[,c("mindfulness","USC","SE",
                                "rumination")])
##             vars   n mean   sd median trimmed  mad min max range  skew kurtosis
## mindfulness    1 317 5.60 0.76    5.6    5.58 0.89   4   7     3  0.17    -0.70
## USC            2 317 3.12 1.54    3.0    3.04 1.78   1   7     6  0.34    -0.84
## SE             3 317 4.85 1.36    5.0    4.90 1.48   1   7     6 -0.42     0.10
## rumination     4 317 3.61 1.51    3.8    3.62 1.78   1   7     6 -0.08    -0.89
##               se
## mindfulness 0.04
## USC         0.09
## SE          0.08
## rumination  0.08

Using the corr.test function from the psych package, we see the correlations involving all the focal variables in the model are reproduced - i.e., as they appear in Table 3 of the article. As noted previously, correlations involving many of the demographic variables were not reproducible based on the data provided.

library(psych)
corr.test(traitmind_orig_data[,c("gender","age","education","usage",
                "mindfulness","SE","USC","rumination")])
## Call:corr.test(x = traitmind_orig_data[, c("gender", "age", "education", 
##     "usage", "mindfulness", "SE", "USC", "rumination")])
## Correlation matrix 
##             gender   age education usage mindfulness    SE   USC rumination
## gender        1.00 -0.12      0.05  0.06       -0.03  0.04  0.06       0.00
## age          -0.12  1.00     -0.01 -0.15        0.23  0.07 -0.30      -0.29
## education     0.05 -0.01      1.00  0.06       -0.13  0.22  0.04       0.20
## usage         0.06 -0.15      0.06  1.00       -0.03  0.02  0.18       0.28
## mindfulness  -0.03  0.23     -0.13 -0.03        1.00  0.06 -0.26      -0.15
## SE            0.04  0.07      0.22  0.02        0.06  1.00 -0.05       0.08
## USC           0.06 -0.30      0.04  0.18       -0.26 -0.05  1.00       0.49
## rumination    0.00 -0.29      0.20  0.28       -0.15  0.08  0.49       1.00
## Sample Size 
## [1] 317
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##             gender  age education usage mindfulness   SE  USC rumination
## gender        0.00 0.58      1.00  1.00        1.00 1.00 1.00       1.00
## age           0.04 0.00      1.00  0.15        0.00 1.00 0.00       0.00
## education     0.37 0.79      0.00  1.00        0.41 0.00 1.00       0.01
## usage         0.31 0.01      0.32  0.00        1.00 1.00 0.02       0.00
## mindfulness   0.57 0.00      0.02  0.55        0.00 1.00 0.00       0.12
## SE            0.47 0.19      0.00  0.74        0.27 0.00 1.00       1.00
## USC           0.30 0.00      0.47  0.00        0.00 0.38 0.00       0.00
## rumination    0.98 0.00      0.00  0.00        0.01 0.14 0.00       0.00
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

Running the analysis: Process Model 58

Step 1: If you have not already done so, you will need to download a copy of the Process macro from this site and load it for use. Unless the macro is activated, you cannot use the commands I show you next to run the model!

## 
## ********************* PROCESS for R Version 4.3.1 ********************* 
##  
##            Written by Andrew F. Hayes, Ph.D.  www.afhayes.com              
##    Documentation available in Hayes (2022). www.guilford.com/p/hayes3   
##  
## *********************************************************************** 
##  
## PROCESS is now ready for use.
## Copyright 2020-2023 by Andrew F. Hayes ALL RIGHTS RESERVED
## Workshop schedule at http://haskayne.ucalgary.ca/CCRAM
## 

Step 2: After loading Process, type in the syntax to run the analysis.

process(data = traitmind_orig_data, y = "rumination", 
        x = "mindfulness", m = "USC", w = "SE", 
        cov = c("gender","age","education","usage"), 
        center = 2, model = 58, seed = 12345, 
        intprobe = .20, plot=1, moments = 0, progress=0,contrast=1)

The arguments for specification of our model are very general and apply to many Process models. Here is a breakdown of various arguments I have included in the code chunk above.

  1. y, x, m, and w: Set these arguments equal to the names of your consequent (y), antecedent (x), mediator (m), and moderator (w) variables, respectively. Make sure your variables are enclosed in quotation marks. Note: If you have more than one mediator in your model, type m = c(list of mediators enclosed in quotation marks and separated by commas), similar to the treatment of covariates (below)
  2. cov: This is the covariates argument. Specify the list of covariates to be included in the model. If you are only including a single covariate, then you can type “name of covariate”. If you are including more than one covariate, type c(list of covariates, each enclosed in quotation marks and separated by commas). If you have no covariates, do not include this argument.
  3. model: This specifies the Process template you wish to use. We are specifying Model 58 in the code chunk above.
  4. center: This argument is used to specify preferences for centering of the variables you are using in the construction of cross-products. Type center = 0 (or leave the argument out) if you do not want to use mean-centering during construction of products. Use center = 1 if you want to use mean centering of all variables [which will include centering binary variables if one or both are used during the construction of a product]. Use center = 2 if you want to use mean centering of only those variables that are continuous when forming products. In the code chunk above, we have set this argument = 2.
  5. moments: This argument is used to determine whether Process uses the default conditioning values of the moderator of 16th, 50th, and 84th percentiles or the more traditional values (for the moderator) of -1sd, mean, +1sd. Leaving the argument out of your code [or setting moments = 0] will result in conditioning values of the 16th, 50th, and 84th percentiles. Setting moments = 1 specifies conditioning values of -1sd, mean, +1sd. In the code chunk above, I have set the argument equal to 0 to request conditioning on the 16th, 50th, and 84th percentiles of the moderator.
  6. progress: This argument is used to determine whether the graphical counter showing bootstrap progress appears when running your analysis - or whether it is suppressed. By default, the counter appears. We will set progress = 0 to suppress it during our analysis. Setting progress = 1 (or leaving the argument out of the syntax altogether will result in the graphical counter appearing).
  7. intprobe: This argument determines which level of significance is required for the interaction terms for the program to generate simple slopes and associated tests to probe the interaction. Setting intprobe = .05 will make Process probe an interaction only if the interaction term is significant at p<.05. Setting intprobe = .20 (as I have done in the code chunk above) will make Process probe an interaction only if the interaction term is significant at p<.20. Seeting intprobe = 1 will mean interactions are always be probed.
  8. plot: This argument determines whether or not a table of predicted values is produced in the output for possible plotting of an interaction. Set plot=1 if you want this table to appear in your output. This setting was made in the code chunk above.
  9. seed: Assigning a seed number will allow you to reproduce the bootstrap standard errors and confidence intervals upon later re-analysis [assuming the same seed #].
  10. boot (not shown in code chunk above): This argument can be added to change the number of bootstrap resamples. By default, it is 5000.
  11. contrast: In general, this option allows you to test pairwise differences in specific indirect effects (Hayes, 2022). In the context of Model 58, setting contrast=1 will generate tests of all pairwise differences in indirect effects calculated at the conditioning values on the moderator. In our case, the output will contain the following tests: (a) difference in indirect effects computed at the 16th and 50th percentiles of the moderator; (b) difference in effects computed at the 16th and 84th percentiles of the moderator; (c) difference computed in effects computed at the 50th and 84th percentiles of the moderator.
## 
## ********************* PROCESS for R Version 4.3.1 ********************* 
##  
##            Written by Andrew F. Hayes, Ph.D.  www.afhayes.com              
##    Documentation available in Hayes (2022). www.guilford.com/p/hayes3   
##  
## *********************************************************************** 
##                    
## Model : 58         
##     Y : rumination 
##     X : mindfulness
##     M : USC        
##     W : SE         
## 
## Covariates: 
##        gender age education usage
## 
## Sample size: 317
## 
## Custom seed: 12345
## 
## 
## *********************************************************************** 
## Outcome Variable: USC
## 
## Model Summary: 
##           R      R-sq       MSE         F       df1       df2         p
##      0.4056    0.1645    2.0312    8.6940    7.0000  309.0000    0.0000
## 
## Model: 
##                 coeff        se         t         p      LLCI      ULCI
## constant       0.1695    0.6610    0.2564    0.7978   -1.1311    1.4702
## mindfulness   -0.3630    0.1107   -3.2781    0.0012   -0.5810   -0.1451
## SE            -0.0881    0.0653   -1.3490    0.1783   -0.2166    0.0404
## Int_1          0.1894    0.0767    2.4699    0.0141    0.0385    0.3403
## gender         0.0160    0.1624    0.0984    0.9217   -0.3037    0.3356
## age           -0.6051    0.1344   -4.5041    0.0000   -0.8695   -0.3408
## education      0.0453    0.1473    0.3079    0.7584   -0.2445    0.3351
## usage          0.2645    0.0944    2.8026    0.0054    0.0788    0.4502
## 
## Product terms key:
## Int_1  :  mindfulness  x  SE      
## 
## Test(s) of highest order unconditional interaction(s):
##       R2-chng         F       df1       df2         p
## X*W    0.0165    6.1006    1.0000  309.0000    0.0141
## ----------
## Focal predictor: mindfulness (X)
##       Moderator: SE (W)
## 
## Conditional effects of the focal predictor at values of the moderator(s):
##          SE    effect        se         t         p      LLCI      ULCI
##     -1.1819   -0.5869    0.1344   -4.3674    0.0000   -0.8513   -0.3225
##      0.1514   -0.3344    0.1127   -2.9659    0.0033   -0.5562   -0.1125
##      1.1514   -0.1450    0.1497   -0.9684    0.3336   -0.4396    0.1496
## 
## Data for visualizing the conditional effect of the focal predictor:
##   mindfulness        SE       USC
##       -0.8013   -1.1819    0.5624
##       -0.0013   -1.1819    0.0929
##        0.8227   -1.1819   -0.3907
##       -0.8013    0.1514    0.2425
##       -0.0013    0.1514   -0.0249
##        0.8227    0.1514   -0.3005
##       -0.8013    1.1514    0.0027
##       -0.0013    1.1514   -0.1133
##        0.8227    1.1514   -0.2328
## 
## *********************************************************************** 
## Outcome Variable: rumination
## 
## Model Summary: 
##           R      R-sq       MSE         F       df1       df2         p
##      0.5797    0.3361    1.5509   19.4878    8.0000  308.0000    0.0000
## 
## Model: 
##                 coeff        se         t         p      LLCI      ULCI
## constant       2.2786    0.5814    3.9193    0.0001    1.1346    3.4226
## mindfulness    0.0140    0.0989    0.1419    0.8872   -0.1806    0.2086
## USC            0.4123    0.0492    8.3741    0.0000    0.3154    0.5092
## SE             0.0873    0.0548    1.5937    0.1120   -0.0205    0.1951
## Int_1          0.0007    0.0331    0.0222    0.9823   -0.0644    0.0658
## gender        -0.1929    0.1432   -1.3464    0.1791   -0.4747    0.0890
## age           -0.3473    0.1208   -2.8738    0.0043   -0.5850   -0.1095
## education      0.4156    0.1285    3.2332    0.0014    0.1627    0.6685
## usage          0.3109    0.0833    3.7343    0.0002    0.1471    0.4748
## 
## Product terms key:
## Int_1  :  USC  x  SE      
## 
## Test(s) of highest order unconditional interaction(s):
##       R2-chng         F       df1       df2         p
## M*W    0.0000    0.0005    1.0000  308.0000    0.9823
## ----------
## Focal predictor: USC (M)
##       Moderator: SE (W)
## 
## Data for visualizing the conditional effect of the focal predictor:
##         USC        SE rumination
##     -1.9211   -1.1819     2.7172
##     -0.1211   -1.1819     3.4578
##      1.6789   -1.1819     4.1984
##     -1.9211    0.1514     2.8317
##     -0.1211    0.1514     3.5741
##      1.6789    0.1514     4.3164
##     -1.9211    1.1514     2.9176
##     -0.1211    1.1514     3.6613
##      1.6789    1.1514     4.4050
## 
## *********************************************************************** 
## Bootstrapping in progress. Please wait.
## 
## **************** DIRECT AND INDIRECT EFFECTS OF X ON Y ****************
## 
## Direct effect of X on Y:
##      effect        se         t         p      LLCI      ULCI
##      0.0140    0.0989    0.1419    0.8872   -0.1806    0.2086
## 
## Conditional indirect effects of X on Y:
## 
## INDIRECT EFFECT:
## 
## mindfulness    ->    USC    ->    rumination
## 
##          SE    Effect    BootSE  BootLLCI  BootULCI
##     -1.1819   -0.2415    0.0753   -0.3974   -0.1027
##      0.1514   -0.1379    0.0547   -0.2534   -0.0356
##      1.1514   -0.0599    0.0707   -0.2022    0.0787
## 
##      Pairwise contrasts between conditional indirect effects
##      (Effect1 minus Effect2):
##     Effect1   Effect2  Contrast    BootSE  BootLLCI  BootULCI
##     -0.1379   -0.2415    0.1036    0.0567   -0.0075    0.2179
##     -0.0599   -0.2415    0.1816    0.0933   -0.0042    0.3669
##     -0.0599   -0.1379    0.0780    0.0384    0.0006    0.1559
## 
## ******************** ANALYSIS NOTES AND ERRORS ************************ 
## 
## Level of confidence for all confidence intervals in output: 95
## 
## Number of bootstraps for percentile bootstrap confidence intervals: 5000
## 
## W values in conditional tables are the 16th, 50th, and 84th percentiles.
##  
## NOTE: The following variables were mean centered prior to analysis: 
##          SE mindfulness USC

The output includes tables for predicted values to plot simple slopes. Unfortunately, Process only gives you the conditioning values of your antecedent and moderator variables and predicted values on the consequent. If you want to plot the simple slopes, you will need to generate this yourself.

In the next code chunk, I create a dataframe containing three variables based on the first ‘Data for visualizing the conditional effect of the focal predictor’ table in the output. I name the dataframe plotdata1.

I type in mindfulness (the name of the focal antecedent) and provide the list of conditioning values going from top to bottom in the table provided in the output. Next, I type in SE (for self-efficacy; the moderator) and provide the list of conditioning values for this variable (again going from top to bottom based on the table in the output). Finally, I type USC (upward social comparison) and create a list of values [these are predicted scores on USC] following the same order I gave for the mindfulness and SE.

Next, I use the interaction.plot() function to plot out the simple slopes. The first argument specifies the X predictor; the second specifies the W (moderator) variable; the last argument specifies the response variable.

plotdata1 <- data.frame(mindfulness = c(-.8013,-.0013,.8227,-.8013,-.0013,.8227,-.8013,-.0013,.8227),
SE=c(-1.1819,-1.1819,-1.1819,.1514,.1514,.1514,1.1514,1.1514,1.1514),
USC=c(.5264,.0929,-.3907,.2425,-.0249,-.3005,.0027,-.1133,-.2328))

#interaction.plot() is a base function in r
interaction.plot(plotdata1$mindfulness,plotdata1$SE,plotdata1$USC)

Notice the plot references the name of the dataframe when referencing each of our variables. We can eliminate this reference using the following strategy using the attach() and detach() functions.

attach(plotdata1) #attach the dataframe
#interaction.plot() is a base function in r
interaction.plot(mindfulness,SE,USC)

detach(plotdata1)

The interaction term associated with the second regression model was not statistically significant (p=.9823). Since intprobe was set equal to .20, no simple slopes or tests are provided in the output to probe the interaction. However, again since we included the setting plot=1, a table was generated [‘Data for visualizing the conditional effect of the focal pred’] for plotting simple slopes in our output. Although it would make little sense to include a plot like this in an article when the interaction is not significant, we will go ahead and generate the plot using the same coding approach as I described above.

plotdata2 <- data.frame(USC = c(-1.9211,-.1211,1.6789,-1.9211,-.1211,1.6789,-1.9211,-.1211,1.6789),
SE=c(-1.1819,-1.1819,-1.1819,.1514,.1514,.1514,1.1514,1.1514,1.1514),
rumination=c(2.7172,3.4578,4.1984,2.8317,3.5741,4.3164,2.9176,3.6613,4.4050))

attach(plotdata2)
interaction.plot(USC,SE,rumination)

detach(plotdata2)

Conditional indirect effects and assessment of moderated mediation

In the output, we have the conditional indirect effects that are computed at the 16th, 50th, and 84th percentiles. Each of these can be tested for statistical significance using the 95% bootstrap confidence intervals. If 0 falls outside the lower and upper bound of a confidence interval, this is an indicator that a conditional indirect effect is significantly different from 0. If 0 falls between the lower and upper bound, then the conditional indirect effect is judged as not being different from 0. We see the indirect effects computed at the 16th percentile of SE and the 50th percentile of SE are both statistically significant. The indirect effect computed at the 84th percentile of SE is not significant.



Keep in mind that the results I have discussed so far do not give any indication as to whether the indirect effect of trait mindfulness on rumination is moderated by self-efficacy. Instead, they only provide information on the conditional indirect effects and whether a given effect is different from 0. You cannot base your judgment of moderated mediation solely by looking at the conditional indirect effects.

In other Process models (e.g., Model 7, 8, 14, and 15) where there is a single moderator of a path, Process will produce the Index of Moderated Mediation and a bootstrap confidence interval to test whether there is evidence of significant moderation of the indirect effect. In models containing different moderators of different paths (e.g., Model 21, 22, 28, and 29), you will see the Index of Moderated Moderated Mediation in the output.

In models 58 and 59 where there is only a single moderator of both paths in the tracing from the antecedent (X) to the consequent (Y), there is no Index of Moderated Mediation or index of Moderated Moderated Mediation produced. That is because the the indirect effect is effectively a non-linear (as opposed to linear) function of the moderating variable (Hayes & Rockwood, 2020). A possible approach to evaluating for evidence of moderated mediation is to examine the table containing ‘Pairwise contrasts between conditional indirect effects’ (c.f., Hayes & Rockwood, p. 29).


The values in the Contrast column are differences in conditional indirect effects (as shown in the previous table): contrast1 = -.1379-(-.2415) = .1036; contrast2 = -.0599-(-.2415) = .1816; contrast3 = -.0599-(-.1379) = .078. If you find at least one of these pairwise contrasts significant - i.e., 0 does not fall between the lower and upper bound of the 95% bootstrap confidence interval - then you may regard this as an indication the indirect effect is conditional on the level of the moderating variable. Looking at our output, we see that 0 falls outside the confidence bounds for the contrast for the indirect effect as computed at the 50th percentile (IE=-.1379) and 84th percentile (IE=-.0599) of the moderator (self-efficacy). This supports the claim of moderated mediation.

Before wrapping this discussion up, it is important to keep in mind that if you find that all confidence intervals for your contrasts include 0, this does not necessarily mean the hypothesis of moderated mediation is disconfirmed. According to Hayes and Rockwood (2020), it is possible that alternative choices of conditioning values for the moderator could ‘produce a confidence interval for the difference that might not include zero’ (p. 29). They go on to say that this approach can be useful for confirming, but not disconfirming, moderated mediation.


References

Gu, C., Liu, S., & Chen, S. (2022). The effect of trait mindfulness on social media rumination: Upward social comparison as a moderated mediator. Frontiers in Psychology, Volume 13 - 2022 | https://doi.org/10.3389/fpsyg.2022.931572
Hayes, A. F. (2022). Introduction to mediation, moderation, and conditional process analysis: A regression-based approach (3rd ed.). The Guilford Press: New York.
Hayes, A. F., & Rockwood, N. J. (2020). Conditional process analysis: Concepts, computation, and advances in the modeling of contingencies of mechanisms. American Behavioral Scientist,64, 19-54.

Comments

Popular posts from this blog

Factor analysis of EBI items: Tutorial with RStudio and EFA.dimensions package

Process model 7 using Hayes Process macro with RStudio

A tutorial on exploratory factor analysis with SPSS