# Mediation and Moderation Analysis in JASP

Over the past few years, we’ve found that mediation and moderation analysis are highly requested features. Since version 0.10.1, JASP can do both! This blogpost goes through two introductory examples, showing how mediation and moderation can be performed in JASP. Mediation means that the effect of a variable X on variable Y is (partially) indirect, through the variable M. Moderation means that the effect of a variable X on variable Y is different for different levels of a third variable. In this tutorial, we start with the latter for a simple example case, focusing on how to perform hypothesis tests and how to interpret the coefficients in the model.

## Moderation with a binary moderator

Moderation means that the effect of a variable X on variable Y is different for different levels of a third variable. This phrasing becomes clearer through an example: say we have a (fictional) dataset where we used standardised scales to measure observed closeness (Y) of a pet parrot to its owner and the amount of affection behaviour (X) shown by the owner. The idea is that the amount of affection shown by the owner has a positive effect on the closeness between them and their parrot. However, this effect may be different for a male or a female parrot. If this is the case, we say the effect of affection on closeness is moderated by the parrot’s gender.

You can download the data we generated for this example here and the JASP file here. The dataset looks like the following screenshot, with an affection variable on a scale from 0-25, and a closeness variable measured on a scale of 1-10. In addition, a gender dummy (0-1) and a gender categorical variable (Male – Female) are included.

Using the descriptive statistics module in JASP, we can create a scatter plot of the data, with on the x-axis the affection, on the y-axis the closeness, and with different colours for male and female parrots (by adding gender as the split variable). As you can see, the line indicating the relation between affection and closeness has a different angle for male parrots than for female parrots. Specifically, the line is almost flat for male parrots, indicating that showing affection to your male parrot has a very small effect on the closeness between you. Conversely, the relation between affection and closeness for female parrots is clear and positive. From this plot, we may already want to conclude that the relation between affection and closeness is moderated by gender.

Warning: This plot will be available from JASP version 0.12 onwards.

To statistically analyze this expected moderation, we can use linear regression analysis to create the following regression model:

closenessi = β0 + β1 ⋅ affectioni + β2 ⋅ genderi + β3 ⋅ affectioni ⋅ genderi + εi

Here, β0 indicates the intercept term, β1 indicates the main effect of affection, β2 indicates the main effect of gender, and β3 indicates the interaction effect, which is the same as the moderation effect. To create this model in the JASP linear regression analysis, add closeness as the dependent variable, and then add affection and the gender dummy as the covariates. Then, in the model pane, add the interaction effect between affection and gender to the model terms (hold down shift to select both variables at the same time from the available components). The screenshot below shows what the model pane should look like1.

The resulting table with coefficient estimates is shown below. In the table, for model H₁ we see that there is a significant interaction effect, indicating that the effect of affection on closeness is moderated by gender. Specifically, we can state that the effect is 0.375 higher for the female parrots (genderi = 1) than for the male parrots, for which the effect is estimated at 0.042. Thus, the effect for female parrots alone is 0.412, meaning that on average, each point increase on the affection scale is associated with an increase in closeness of 0.412. This effect can be validated by filtering out the male parrots and running a linear regression for only the female parrots.

The same procedures can be followed using the Bayesian linear regression module. Instead of performing a hypothesis test using a p-value, we can look at the evidence for the model including the moderation — in the form of a Bayes Factor. For the present example, comparing the model without the interaction effect (M0) to the model with the interaction effect (M1) using the default JZS prior, we achieve a very large Bayes Factor (BF10 = 2.618⋅109), indicating that M1 is much more likely than M0. The marginal posterior distribution of the moderation effect is displayed below. For information on how to perform this Bayesian moderation analysis, see the JASP file.

## Mediation analysis

Mediation analysis investigates whether and to what extent the effect of a variable X on variable Y is explained by the variable M. A key quantity for mediation analysis is the indirect effect. In this section, we show you how the indirect effect can be estimated in JASP. For this, we take another example.

Say we have done an observational study where we followed parents and their children. We have asked the parents using a standardized scale to what extent they usually have a laissez-faire attitude in the upbringing of their children, and for the children we measure how independent they are. As researchers with extensive knowledge of the literature, we may be able to assume that a strong laissez-faire attitude has a positive effect on the independence of the child. Now we may want to get more information about the mechanism by which this process occurs. For example, we might hypothesize that a laissez-faire attitude influences the amount of exploration behaviour of the child, which in turn affects their independence. In this example, exploration is the hypothesized mediator of the effect of attitude on independence.

The data we generated for this example can be found here and the JASP file to follow along with this tutorial can be found here. A plot of the relation between laissez-faire and independence is shown below. As we can see, our dataset shows the positive relation – in line with our expectations based on the previous literature in our example. It is always a good idea to make such scatter plots: visually inspecting the data can lead us to find problems with data coding such as inputting 100 instead of 10 for a single participant.

Warning: This plot will be available from JASP version 0.12 onwards.

The theoretical mediation model is shown in the image below. In our example, X is the extent of laissez-faire, Y is the child’s independence, and M is the exploration behaviour. The arrows indicate effects: τ is the direct effect of X on Y, and α ⋅ β is called the indirect effect. The total effect is the sum of the direct and the indirect effect: mediation analysis decomposes an existing effect into these two terms.

In JASP, this model can be fit using the mediation analysis, within the structural equation modelling module. The GIF below shows how to add the module.

Drag the X variable to the predictor box, the Y variable to the outcome, and the M variable to the mediator box to start. You will immediately see parameter estimates for the individual effects, as well as for the indirect and total effect. The confidence intervals are best calculated through the bias corrected bootstrap because the sampling distribution of the indirect effect is asymmetric (Biesanz, Falk, & Savalei, 2010). Fortunately, these confidence intervals are easily obtained through requesting the bootstrap in the options. The options window for this model in JASP is shown in the image below:

The resulting coefficient values and their confidence intervals are shown in the following tables:

From these tables, using the bootstrap confidence intervals, we may conclude that there is mediation in this model: the 95% CI of the indirect effect is [0.256, 0.444], which does not include 0. Another interesting observation is that the direct effect of laissez faire on independence is actually negative, even though the total effect is positive. This gives us an interesting view into the process by which parenting style fosters independence!

Parenting style influences more than just independence, and we might want to know more about the effects of a laissez-faire parenting style. We might have measured another variable in our study: disobedience. In JASP, it is easy to add this outcome variable to the model, by simply dragging it to the outcome variables box. We can then easily get parameter estimates for the additional outcome, as well as a graphical representation of the model called a path plot. With these tools in hand, we can see that laissez faire parenting style increases disobedience too, partially via exploration.

## Conclusion

In this blog post, we have shown introductory examples of mediation and moderation analysis. Much more is possible in these procedures, such as multiple mediators, continuous moderators, and much more. Download JASP now to try out these analyses!

### Notes

1 NB: Some authors suggest mean-centering the continuous predictors before running this model. For this particular case, this makes no difference in the results. Mean centering can be done in JASP using the compute column functionality.

#### References

Jeremy C. Biesanz, Carl F. Falk & Victoria Savalei (2010) Assessing Mediational Models: Testing and Interval Estimation for Indirect Effects, Multivariate Behavioral Research, 45:4, 661-701, DOI: 10.1080/00273171.2010.498292