PMCCPMCCPMCC

Search tips
Search criteria 

Advanced

 
Logo of nihpaAbout Author manuscriptsSubmit a manuscriptHHS Public Access; Author Manuscript; Accepted for publication in peer reviewed journal;
 
Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Published in final edited form as:
Behav Res Methods. 2008 February; 40(1): 55–60.
PMCID: PMC2903052
NIHMSID: NIHMS215043

A Graphical Representation of the Mediated Effect

Abstract

Mediation analysis is widely used in the social sciences. Despite the popularity of mediation models, few researchers have used graphical methods, other than structural path diagrams, to represent their models. Plots of the mediated effect can help a researcher better understand the results of the analysis and convey these results to others. This article presents a method for creating and interpreting plots of the mediated effect for a variety of mediation models, including models with a dichotomous independent variable, a continuous independent variable, and an interaction between an independent variable and the mediating variable. An empirical example is then presented to illustrate these plots. Finally, sample code for creating plots of the mediated effect in R and SAS is included.

Keywords: Mediation, Plots

Graphical representations of data are often used by researchers to explore relations among variables. Plots and graphs can be used for initial data exploration, to examine violations of model assumptions, and to show predicted scores from a final model. Despite their versatility and usefulness, researchers have rarely used plots to illustrate the results from mediation studies. Instead, researchers present path diagrams which show the structural relationship between the independent, mediator, and dependent variables. However, plots that not only show the structural properties of the mediation model, but actually illustrate the magnitude of the mediated effect itself can be very useful as a visual representation of the mediated effect, which may be more desirable than presenting numerical results alone. These plots may be especially useful when investigating complex mediation models such as inconsistent mediation models where the direct effect and mediated effect have opposite signs or models where the mediator interacts with the independent variable, which were first described by Merrill (1994). MacKinnon (2007) used a similar approach to describe more general plots of the effects in mediation models.

The purpose of this paper is to explain how to construct plots of the mediated effect for a study with a dichotomous (e.g., random assignment to a treatment and control group) or a continuous independent variable, a continuous mediator, and a continuous outcome variable. An empirical example is then used to show what the finished plots look like and how to interpret plots of the mediated effect. Finally, sample code for creating plots of the mediated effect are given for two common statistical software packages, SAS (SAS Institute, 2006) and R (R Core Development Team, 2006), to assist researchers in making their own plots. The goal of this paper is to give researchers another tool for presenting and explaining results from mediational studies that may be used in presentations and publications.

Mediation

Mediation is the name given to models in which the effect of an antecedent or independent variable (X) on a dependent variable (Y) is transmitted through a third intervening or mediating variable (M). In other words, X affects M, which in turn affects Y. Figure 1 shows a diagram of a single mediator model, where the top diagram represents the total effect of X on Y and the bottom diagram represents the mediated effect of X on Y through M. These two path diagrams can be represented using the regression equations:

Y=i1+cX+e1
(1)

M=i2+aX+e2
(2)

Y=i3+cX+bM+e3
(3)

where c is the total effect of X on Y, c’ is the effect of X on Y adjusted for M, b is the effect of M on Y adjusted for X, a is the effect of X on M, i1, i2, and i3 are the intercepts, and e1, e2, and e3 are the residuals. The a path is known as the action theory because X is often directly manipulated, while the b path is known as the conceptual theory (Chen, 1990; MacKinnon, Taborga, & Morgan-Lopez, 2002), because M is not usually directly manipulated.

Figure 1
Path diagrams for i. the total effect of the independent variable on the dependent variable and ii. the indirect effect of the independent variable on the dependent variable through the mediator variable.

The mediated or indirect effect is equal to ab or the product of the action theory and the conceptual theory coefficients. The effect of X on Y that does not pass through M is called the direct effect and is equal to c’. Models where c’ = 0 are called completely mediated models and models where c’ ≠ 0 are called partially mediated models (Baron & Kenny, 1986). In ordinary-least-squares regression,

c=ab+c
(4)

although this relationship does not hold for all logistic regression or multilevel models. Mediation should not be confused with an interaction, also known as moderation, where the magnitude of the effect of X on Y is determined by the value of M; in a completely mediated model, if M is held constant, then X has no effect on Y.

There are many statistical tests of mediation and these tests fall into three categories: causal steps, product of coefficients, and difference in coefficients. In the causal steps tests, each step in the causal chain is tested for significance in sequence. For example, the Baron and Kenny (1986) test first tests the significance of the effect of X on Y, c, then the significance of the effect of X on M, a, then finally the effect of M on Y controlling for X, b; if all three effects are significant, then mediation is present. The product of coefficients tests directly test the indirect effect, ab, for significance by dividing ab by its standard error and comparing the resulting value to a normal distribution or by creating confidence intervals around the indirect effect such as in MacKinnon, Fritz, Williams, and Lockwood (in press). Finally, the difference in coefficients tests investigate the difference between the overall effect and the part of the overall effect that does not pass through the mediator, cc’, by dividing the difference by its standard error and comparing the value to a t-distribution for significance. For more information on tests of mediation see MacKinnon, Lockwood, Hoffman, West, and Sheets (2002) and MacKinnon, Lockwood, and Williams (2004).

Despite the variety of different statistical tests of mediation, all of the tests operate under the same assumptions. The first assumption is that the order of causation is correct, that is, X causes M, even when X is not random assignment to treatment, and M causes Y. Also, the interaction between X and M is assumed to be zero in Equation 3, although this assumption can be relaxed as described later in this paper. Other assumptions are that the dependent variables have a normal distribution and the residuals are independent and normally distributed. These assumptions apply to all of the plots.

Plotting the Mediated Effect

To plot a mediated effect for a dichotomous independent variable, first Equations 1, 2, and 3 must be estimated to find values for the intercepts and regression coefficients (MacKinnon, 2007; Merrill, 1994). Note that X was dummy coded 0 and 1, and for convenience hats were not included over the parameter estimates in the plots. Second, the data is plotted with Y on the vertical axis and M on the horizontal axis as shown in Figure 2. Next, Equation 1 is plotted for the values of X (i.e., 0 and 1), such that a horizontal line is placed at Y=i^1 corresponding to X=0 and a second horizontal line is placed at Y=i^1+c^ corresponding to X=1. The distance between the horizontal lines represents the total effect of X on Y, c^. Then, Equation 2 is plotted for both values of X, resulting in a vertical line at M=i^2 and a second vertical line at M=i^2+a^. The distance between the two vertical lines represents the action theory and is equal to a^. Finally, Equation 3 is plotted at both values of X. The slopes of these parallel simple regression lines are equal to b^. Looking at the M=i^2+a^ vertical line, the distance between the Y=i^1+c^ horizontal line and the point where the regression line for the X=0 group intersects the M=i^2+a^ vertical line is equal to c^, and the distance from this intersection point to the Y=i^1 horizontal line is equal to the mediated effect, a^b^.

Figure 2
Plot of the mediated effect for a dichotomous X variable.

Interpreting the plot is straightforward (MacKinnon, 2007; MacKinnon, Fairchild, & Fritz, 2007; Merrill, 1994). Looking at Figure 2, it can be seen that c^ is the predicted amount of change in Y for a one unit change in X and that the larger the distance between the horizontal lines, the larger the overall effect of X on Y. The same is true of a^, which is the predicted amount of change in M for a one unit change in X; the larger the distance between the vertical lines, the greater the effect of X on M. The slope of the simple regression lines, b^, is then the predicted change in Y for a one unit change in M adjusted for X. Regardless of whether the effect is positive or negative, the steeper the slope of the simple regression lines, the larger the effect of M on Y adjusting for X. The mediated effect, a^b^, is then the predicted change in Y for an a^ unit increase in M, which corresponds to a one unit change in X. Finally, looking at the length of a^b^ relative to the length of c^ indicates the amount of the overall effect of X on Y that is mediated by M; in this example the mediator accounts for about 60% of the effect of X on Y. Regardless of the relative size of a^b^ , statistical significance of the mediated effect should be investigated using one of the tests of mediation described earlier.

For a continuous independent variable, Equations 1, 2, and 3 are again estimated to find values for the intercepts and regression coefficients, and the data is plotted with Y on the vertical axis and X on the horizontal axis, as shown in Figure 3. Next, Equations 1 and 2 are plotted for the mean of X and one unit above the mean of X, such that horizontal lines are plotted at Y=i^1+c^X, which is equal to the mean of Y, and at Y=i^1+c^(X+1), and vertical lines are plotted at M=i^2+a^X, which equals the mean of M, and M=i^2+a^(X+1). The distance between the horizontal lines is then equal to c^ and distance between the two vertical lines is equal to a^. Finally, Equation 3 is plotted. Because X is continuous, specific values of X must be selected to plot. In Figure 3, the values of X selected are the mean of X and one standard deviation above the mean of X, although any values of X may be selected and any number of values may be plotted (Aiken & West, 1991); the slope of each of these lines is equal to b^. Looking at the M=i^2+a^(X+1) vertical line, the distance between the Y=i^1+c(X+1) horizontal line and the point where the regression line for the mean of X intersects the M=i^2+a^(X+1) vertical line is equal to c^, and the distance from the intersection point to the Y=i^1+c^X horizontal line is equal to the mediated effect, a^b^. The interpretation of the effects in the plot are identical to case with a dichotomous X variable.

Figure 3
Plot of the mediated effect for a continuous X variable. Note that sd stands for the standard deviation of X.

In both Figure 2 and Figure 3, all of the estimates of the effects in the model, a^, b^ , c^ , and c^, were positive, but this will not necessarily occur when plotting real data. When b^ is negative, the simple regression lines slope downward. When c^ is negative, the distance between the horizontal lines will remain the same, but the order of the lines will be reversed and a^b^ and c^ will switch places. When a^ is negative, the distance between the vertical lines will remain the same, but the order of the lines will reverse, although a^b^ and c^ will still occur on the M=i^2+a^ line. For instance, in Figure 2, if a^ was negative, the line M=i^2+a^ would be a^ units to the left of the M=i^2 line.

A word of caution is needed for inconsistent mediation models. In an inconsistent mediation model, a^b^ and c^ are significant, but opposite in sign, which can cause c^ to be nonsignificant. As shown in Equation 4, if a^b^ and c^ are equal in magnitude but opposite in sign, then c^ would be equal to 0. When this occurs, the slopes of the simple regression lines may be positive or negative and the vertical lines may or may not be switched, depending on the signs of the a^ and b^ coefficients. It is also possible in inconsistent mediation models for the mediated effect to be larger than the total effect, such that the simple regression slopes of Equation 3 crosses the M=i^2+a^ line outside of the range of the horizontal lines that represent the total effect c^.

XM Interactions

In certain cases, the effect of the mediator is not equal across values of X. In these cases, an interaction between the independent variable and the mediating variable, known as an XM interaction, is present. A significant XM interaction indicates that the effect of M on Y is a function of X and changes as the value of X changes. Plotting a mediation model with a XM interaction is very similar to plotting the typical mediation model (Fritz & MacKinnon, 2006; Merrill, 1994). First, Equations 1 and 2 are estimated to find values for the coefficients. Instead of estimating Equation 3, however, the equation

Y=i3+cX+bM+gXM+e3
(5)

is estimated. The only difference between Equation 3 and Equation 5 is the inclusion of the XM interaction in Equation 5.

Plotting of the mediated effect with an XM interaction then directly follows the steps used to plot mediation models without an interaction; an example for a dichotomous independent variable is shown in Figure 4. In Figure 4, the solid line represents the simple regression line for the group coded X = 0 and the dashed line represents the simple regression line for the group coded X = 1. The dotted line represents the simple regression line for the group coded X=1 when the interaction effect g^ is set to 0 and the distance between the dashed and dotted lines at a specific value of M is equal to the interaction effect at that value of M, g^M.

Figure 4
Plot of the mediated effect with a XM interaction.

Empirical Example

To better illustrate the construction and use of these plots, an empirical example is included using data from the Athletes Training and Learning to Avoid Steroids (ATLAS) program (Goldberg et al., 1996; Goldberg et al., 2000). The ATLAS program was designed for high school football players to decrease their intentions to use anabolic steroids by offering improved dietary behavior and increased strength training self-efficacy as direct alternatives to steroid use that produced similar results without the negative consequences associated with illicit steroid use. ATLAS changed these three outcome variables (intentions to use steroids, nutrition behavior, and strength training self-efficacy) by targeting twelve main mediating variables, including knowledge of the effects of steroid use, peer tolerance of steroid use, and perceived severity of steroid use (See MacKinnon et al., 2001 for a complete list of the twelve mediators).

From these twelve mediator variables and three outcome variables, two examples are illustrated; note that the data in these plots have had a small amount of random error added to them, a process called jittering, to make them easier to read. The first example is that exposure to the ATLAS program (X) increased an athlete’s ability to resist offers of steroids (M), in turn increasing an athlete’s healthy nutrition behavior (Y). Using Cohort 1, wave C of the ATLAS data gives estimates and standard errors for the parameters of Equations 1-3 of a^=0.33 (se = 0.0636) , b^=0.058 (se = 0.0640) , c^=0.347 (se = 0.0637) , and c^=0.33 (se = 0.0238) , which are plotted in Figure 5. The plot shows the difference in magnitude between the direct effect c^ and the indirect effect a^b^ , with the direct effect making up a greater proportion of the overall effect, illustrated by the two horizontal lines. Looking at this plot, it can be seen that the proportion of the effect of X on Y mediated by M is very small and not likely to be significant. Testing for mediation using the PRODCLIN program (MacKinnon et al., in press) to create a confidence interval for a^b^ gave a 95% confidence interval of [−0.02161, 0.06354], which shows that the indirect effect is not significant.

Figure 5
Plot of the mediated effect of exposure to the ATLAS program (X) on resistance to drug offers (M) and nutrition behaviors (Y).

The second example is that exposure to the ATLAS program (X) decreased an athlete’s belief in media advertisements about the positive aspects of steroids (M) which then increased the athlete’s strength training self-efficacy (Y). Using Cohort 1, wave C of the ATLAS data gives estimates for the parameters of Equations 1-3 of a^=0.68 (se = 0.0745) , b^=0.23 (se = 0.0231) , c^=0.31 (se = 0.0620) , and c^=0.16 (se = 0.0619) , which are plotted in Figure 6. Looking at this plot, we see that the proportion of the total effect, c^ , that is attributable to the mediator is much larger, around 60%, compared to the plot in Figure 5. Testing the significance of the mediated effect using the PRODCLIN program (MacKinnon et al., in press) to create a confidence interval for a^b^ gives a 95% confidence interval of [0.11332, 0.20432], which leads to the conclusion that the mediator is significant.

Figure 6
Plot of the mediated effect of exposure to the ATLAS program (X) on belief in media advertisements (M) and strength training self-efficacy (Y).

Summary and Example Computer Programs

The plots discussed here are for the single mediator model only. However, many mediation models are much more complex, with multiple mediators or longitudinal data. Plotting these larger models requires more complex plots than the plots presented here, which are harder to interpret. For instance, in the multiple mediator case, the mediator variables would have to be standardized to place them on the same metric and then the plots of the individual mediators would have to be laid over one another. The interpretation of such a plot would then depend on the number of mediators and the signs and magnitudes of the individual mediated effects.

To help researchers in creating mediation plots for their own data, sample code for two common statistics packages, R (R Core Development Team, 2006) and SAS (SAS Institute, 2006), are included in the appendix, as are instructions for loading and using the code. Electronic versions of these programs are available at http://www.public.asu.edu/~davidpm/ripl/mediate.htm . These sample programs are meant to act as an outline for researchers who are plotting single mediator models. Researchers are encouraged to modify the programs as necessary to explore their data and to produce plots that fit their individual needs.

Supplementary Material

R Code

SAS Code

Acknowledgments

This research was supported by Public Health Service grant (DA06006).

APPENDIX A

A.1. R Program For Plotting Mediated Effects

“med_plots” <-
function (cont,int)
{
#med_plots.r by Matthew Fritz and David MacKinnon, 2007,
#Dept. of Psychology, Arizona State University
#This program plots the mediated effect for a single mediator mediation
#model and adds labels for the different effects.

#To read in file, type: source(“C:/med_plots.r”)
#To run file, type: med_plots(cont,int)
#where cont=0 if x is dichotomous           and
#      cont=1 if x is continuous            and
#where int=0 if there is no XM interaction  and
#      int=1 if there is an XM interaction

#Read in the data file

 data1<−read.table(‘C:/dichx_example.txt’)
 attach(data1)

#Rename the corresponding variables in the data set to x, m, and y

 x<−V1
 m<−V2
 y<−V3

#Runs the regression analyses from Equations 1, 2, and 3

 #Equation 1
 fit.yx<−glm(y~x)
 sum.yx<−summary(fit.yx)
 c<−sum.yx$coefficients[2,1]
 i1<−sum.yx$coefficients[1,1]

 #Equation 2
 fit.mx<−lm(m~x)
 sum.mx<−summary(fit.mx)
 a<−sum.mx$coefficients[2,1]
 i2<−sum.mx$coefficients[1,1]

 #Equation 3
  if(int==0) {
    fit.yxm<−lm(y~x+m)
    sum.yxm<−summary(fit.yxm)
    b<−sum.yxm$coefficients[3,1]
    cpr<−sum.yxm$coefficients[2,1]
    i3<−sum.yxm$coefficients[1,1]}
  else {
    fit.yxm<−lm(y~x+m+(x*m))
    sum.yxm<−summary(fit.yxm)
    b<−sum.yxm$coefficients[3,1]
    cpr<−sum.yxm$coefficients[2,1]
    i3<−sum.yxm$coefficients[1,1]
    g<−sum.yxm$coefficients[4,1]}



 #Plotting the effects
  meanx<−mean(x)
  sdx<−sd(x)
  mmin<−min(m)
  mmax<−max(m)
  ymin<−min(y)
  ymax<−max(y)


  plot(m,y,type=“n”,ylab=“ ”,xlab=“M”,xlim=range(mmin−((mmax−
 mmin)/5),mmax+((mmax−mmin)/5)),
       ylim=range(ymin−((ymax−ymin)/5),ymax+((ymax−ymin)/5)))
   points(m,y, pch=19)
   mtext(“Y”,side=2,las=1,adj=5)
   par(family=“serif”,font=4,cex=1.13)

   #Dichotomous X with no XM interaction condition
   if(cont==0 && int==0) {
      #Effect of X on M (a)
      vert1<−i2+a*0
      vert2<−i2+a*1
      abline(v=vert1)
      abline(v=vert2)
      arrows(vert1,ymin−((ymax−ymin)/5),vert2,ymin−((ymax−
ymin)/5),length=.1,code=3)
     text(((vert2−vert1)/2+vert1),ymin−((ymax−ymin)/5),“a”,pos=3)

     #Effect of X on Y (c)
     hor1<−i1+c*0
     hor2<−i1+c*1
     abline(h=hor1)
     abline(h=hor2)
     arrows(mmin−((mmax−mmin)/5),hor1,mmin−((mmax−
mmin)/5),hor2,length=.1,code=3)
     text(mmin−((mmax−mmin)/5),((hor2−hor1)/2+hor1),“c”,pos=4)

     #Simple regression lines
     abline((i3+cpr*0),b,col=1,lty=1,lwd=3)
     abline((i3+cpr*1),b,col=1,lty=2,lwd=3)

     #Legend
     legend(“topleft”,legend=c(“Y=i3+c’X+bM (X=0)”,
            “Y=i3+c’X+bM (X=1)”),
            lty=1:2,lwd=3,bty=“n”) }

   #Dichotomous X with an XM interaction condition
   if(cont==0 && int==1) {
     #Effect of X on M (a)
     vert1<−i2+a*0
     vert2<−i2+a*1
     abline(v=vert1)
     abline(v=vert2)
     arrows(vert1,ymin−((ymax−ymin)/5),vert2,ymin−((ymax−
ymin)/5),length=.1,code=3)
     text(((vert2−vert1)/2+vert1),ymin−((ymax−ymin)/5),“a”,pos=3)

     #Effect of X on Y (c)
     hor1<−i1+c*0
     hor2<−i1+c*1
     abline(h=hor1)
     abline(h=hor2)
     arrows(mmin−((mmax−mmin)/5),hor1,mmin−((mmax−
mmin)/5),hor2,length=.1,code=3)
     text(mmin−((mmax−mmin)/5),((hor2−hor1)/2+hor1),“c”,pos=4)

     #Simple regression lines
     abline((i3+cpr*0),b+g*0,col=1,lty=1,lwd=3)
     abline((i3+cpr*1),b+g*1,col=1,lty=2,lwd=3)
     abline((i3+cpr*1),b+g*0,col=1,lty=3,lwd=3)

     #Legend
     legend(“topleft”,legend=c(“Y=i3+c’X+bM+gXM (X=0)”,“Y=i3+c’X+bM+gXM
(X=1)”,
            “Y=i3+c’X+bM (X=1)”),lty=1:3,lwd=3,bty=“n”) }
   #Continuous X with no XM interaction condition
   if(cont==1 && int==0) {
     #Effect of X on M (a)
     vert1<−i2+a*meanx
     vert2<−i2+a*(meanx+1)
     abline(v=vert1)
     abline(v=vert2)
     arrows(vert1,ymin−((ymax−ymin)/5),vert2,ymin−((ymax−
ymin)/5),length=.1,code=3)
     text(((vert2−vert1)/2+vert1),ymin−((ymax−ymin)/5),“a”,pos=3)

     #Effect of X on Y (c)
     hor1<−i1+c*meanx
     hor2<−i1+c*(meanx+1)
     abline(h=hor1)
     abline(h=hor2)
     arrows(mmin−((mmax−mmin)/5),hor1,mmin−((mmax−
mmin)/5),hor2,length=.1,code=3)
     text(mmin−((mmax−mmin)/5),((hor2−hor1)/2+hor1),“c”,pos=4)

     #Simple regression lines
     abline((i3+cpr*(meanx+sdx)),b,col=1,lty=1,lwd=3)
     abline((i3+cpr*meanx),b,col=1,lty=2,lwd=3)
     abline((i3+cpr*(meanx−sdx)),b,col=1,lty=3,lwd=3)

     #Legend
     legend(“topleft”,legend=c(“Y=i3+c’X+b(MeanX+1sd)”,“Y=i3+c’X+b(MeanX)”,
            “Y=i3+c’X+b(MeanX−1sd)”),lty=1:3,lwd=3,bty=“n”) }
  #Continuous X with an XM interaction condition
  if(cont==1 && int==1) {
     #Effect of X on M (a)
     vert1<−i2+a*meanx
     vert2<−i2+a*(meanx+1)
     abline(v=vert1)
     abline(v=vert2)
     arrows(vert1,ymin,vert2,ymin,length=.1,code=3)
     text(((vert2−vert1)/2+vert1),ymin,“a”,cex=1.13,pos=3)

     #Effect of X on Y (c)
     hor1<−i1+c*meanx
     hor2<−i1+c*(meanx+1)
     abline(h=hor1)
     abline(h=hor2)
     arrows(mmin,hor1,mmin,hor2,length=.1,code=3)
     text(mmin,((hor2−hor1)/2+hor1),“c”,cex=1.13,pos=4)

     #Simple regression lines
     abline((i3+cpr*(meanx+sdx)),b+(g*(meanx+sdx)),col=1,lty=1,lwd=3)
     abline((i3+cpr*meanx),b+(g*(meanx)),col=1,lty=2,lwd=3)
     abline((i3+cpr*(meanx−sdx)),b+(g*(meanx−sdx)),col=1,lty=3,lwd=3)

     #Legend
     legend(“topleft”,legend=c(“Y=i3+c’(MeanX+1sd)+bM+gM*(Meanx+1sd)”,
            “Y=i3+c’(MeanX)+bM+gM*(MeanX)”,“Y=i3+c’(MeanX−1sd)+bM+gM*(MeanX−
1sd)”),
             lty=1:3,lwd=3,bty=“n”) }
detach(data1)
 }

A.2. SAS Program For Plotting Mediated Effects

/*med_plots.sas by Matthew Fritz and David MacKinnon, 2007,
  Dept. of Psychology, Arizona State University
  This program plots the mediated effect for a single mediator mediation
  model and adds labels for the different effects.
  To use this SAS macro, either open the file in SAS or cut and paste the
  code into a SAS syntax window.

  To run the macro, first open a data set in SAS. Rename the variables of
  interest to X, M, and Y, respectively, then set data1 equal to this data
  set. Next, go to the %med_plots(cont=, int=) line at the end of the file
  and specify values for cont (0=dichotomous X, 1=continuous X) and
  int (0=no XM interaction, 1=XM interaction) and then run the macro.*/

goptions reset=all;

%macro med_plots(cont,int);

*Change ‘b’ to the name of your data set;
data data1; set b;
xm=x*m;
run;

*Runs the regression analyses;
%if &int=0 %then %do;
proc reg data=data1 outest=out1 noprint;
model y=x;
model m=x;
model y=x m;
%end;

%else %do;
proc reg data=data1 outest=out1 noprint;
model y=x;
model m=x;
model y=x m xm;
%end;

*Captures the parameter estimates and makes the macro variables;
data out2; set out1;
if _model_=“MODEL1” then i1=intercept;
if _model_=“MODEL1” then c=x;
if c=‘.’ then delete;
keep i1 c;

data out3; set out1;
if _model_=“MODEL2” then i2=intercept;
if _model_=“MODEL2” then a=x;
if a=‘.’ then delete;
keep i2 a;

data out4; set out1;
if _model_=“MODEL3” then i3=intercept;
if _model_=“MODEL3” then cpr=x;
if _model_=“MODEL3” then b=m;
if _model_=“MODEL3” then g=xm;
if cpr=‘.’ then delete;
keep i3 cpr b g;

data data2; merge out2 out3 out4;
call symput(‘i1’,i1);
call symput(‘i2’,i2);
call symput(‘i3’,i3);
call symput(‘a’,a);
call symput(‘b’,b);
call symput(‘c’,c);
call symput(‘cpr’,cpr);
call symput(‘g’,g);
run;

*Syntax for the dichotomous, no interaction condition;
%if (&cont=0 and &int=0) %then %do;
data data1; set data1;
py=&i3+&cpr*x+&b*m;
%let vref1=&i1;
%let vref2=%sysevalf(&i1+&c);
%let href1=&i2;
%let href2=%sysevalf(&i2+&a);

proc gplot data=data1;
symbol1 value=none color=black i=rl line=1 width=3;
symbol2 value=none color=black i=rl line=3 width=3;
symbol3 value=‘0’ color=black i=none;
symbol4 value=‘1’ color=black i=none;
axis1 label=(‘Y’) reflabel=(justify=left ‘Y=i1’ ‘Y=i1+c’) ;
axis2 label=(‘M’) reflabel=(position=bottom ‘M=i2’ ‘M=i2+a’);
plot py*m=x/vref=&vref1 vref=&vref2 href=&href1 href=&href2
      vaxis=axis1 haxis=axis2 legend;
plot2 y*m=x/nolegend noaxis;
%end;

*Syntax for the dichotomous, interaction condition;
%if (&cont=0 and &int=1) %then %do;
data data1; set data1;
py=&i3+&cpr*x+&b*m+&g*x*m;
%let vref1=&i1; %let vref2=%sysevalf(&i1+&c);
%let href1=&i2;
%let href2=%sysevalf(&i2+&a);

proc gplot data=data1;
symbol1 value=none color=black i=rl line=1 width=3;
symbol2 value=none color=black i=rl line=3 width=3;
symbol3 value=‘0’ color=black i=none;
symbol4 value=‘1’ color=black i=none;
axis1 label=(‘Y’) reflabel=(justify=left ‘Y=i1’ ‘Y=i1+c’) ;
axis2 label=(‘M’) reflabel=(position=bottom ‘M=i2’ ‘M=i2+a’);
plot py*m=x/vref=&vref1 vref=&vref2 href=&href1 href=&href2
      vaxis=axis1 haxis=axis2 legend;
plot2 y*m=x/nolegend noaxis;
%end;

*Syntax for the continuous, no interaction condition;
%if(&cont=1 and &int=0) %then %do;
proc means data=data1 noprint;
var x;
output out=out5 mean(x)=meanx std(x)=stdx;

data out5; set out5;
xminussd=meanx−stdx;
xplussd=meanx+stdx;
call symput(‘meanx’,meanx);
call symput(‘xminussd’,xminussd);
call symput(‘xplussd’,xplussd);

data data1; set data1;
py1=&i3+&cpr*&xminussd+&b*m;
py2=&i3+&cpr*&meanx+&b*m;
py3=&i3+&cpr*&xplussd+&b*m;
label py1=‘MeanX−1SD’ py2=‘MeanX’ py3=‘MeanX+1SD’;
%let vref1=%sysevalf(&i1+&c*&meanx);
%let vref2=%sysevalf(&i1+&c*(&meanx+1));
%let href1=%sysevalf(&i2+&a*&meanx);
%let href2=%sysevalf(&i2+&a*(&meanx+1));

proc gplot data=data1;
symbol1 value=none color=black i=rl line=2 width=3;
symbol2 value=none color=black i=rl line=1 width=3;
symbol3 value=none color=black i=rl line=3 width=3; 
symbol4 value=‘0’ color=black i=none;
axis1 label=(‘Y’) reflabel=(justify=left ‘Y=i1’ ‘Y=i1+c’) ;
axis2 label=(‘M’) reflabel=(position=bottom ‘M=i2’ ‘M=i2+a’);
plot py1*m py2*m py3*m/vref=&vref1 vref=&vref2 href=&href1 href=&href2
      vaxis=axis1 haxis=axis2 legend;
plot2 y*m/nolegend noaxis;

%end;

*Syntax for the continuous, interaction condition;
%if(&cont=1 and &int=1) %then %do;
proc means data=data1 noprint;
var x;
output out=out5 mean(x)=meanx std(x)=stdx;

data out5; set out5;
xminussd=meanx−stdx;
xplussd=meanx+stdx;
call symput(‘meanx’,meanx);
call symput(‘xminussd’,xminussd);
call symput(‘xplussd’,xplussd);

data data1; set data1;
py1=&i3+&cpr*&xminussd+&b*m+&g*&xminussd*m;
py2=&i3+&cpr*&meanx+&b*m+&g*&meanx*m;
py3=&i3+&cpr*&xplussd+&b*m+&g*&xplussd*m;
label py1=‘MeanX−1SD’ py2=‘MeanX’ py3=‘MeanX+1SD’;
%let vref1=%sysevalf(&i1+&c*&meanx);
%let vref2=%sysevalf(&i1+&c*(&meanx+1));
%let href1=%sysevalf(&i2+&a*&meanx);
%let href2=%sysevalf(&i2+&a*(&meanx+1));

proc gplot data=data1;
symbol1 value=none color=black i=rl line=2 width=3;
symbol2 value=none color=black i=rl line=1 width=3;
symbol3 value=none color=black i=rl line=3 width=3;
symbol4 value=‘0’ color=black i=none;
axis1 label=(‘Y’) reflabel=(justify=left ‘Y=i1’ ‘Y=i1+c’) ;
axis2 label=(‘M’) reflabel=(position=bottom ‘M=i2’ ‘M=i2+a’);
plot py1*m py2*m py3*m/ vref=&vref1 vref=&vref2 href=&href1 href=&href2
      vaxis=axis1 haxis=axis2 legend;
plot2 y*m/ nolegend noaxis;
%end;

%mend;
%med_plots(cont=0,int=1);
run;
quit;

Footnotes

Portions of this work have been presented at the annual meeting of the Society for Prevention Research.

REFERENCES

  • Aiken LS, West SG. Multiple regression: Testing and interpreting interactions. Sage; Newbury Park, CA: 1991.
  • Baron RM, Kenny DA. The moderator-mediator distinction in social psychological research: Conceptual, strategic, and statistical considerations. Journal of Personality and Social Psychology. 1986;51:1173–1182. [PubMed]
  • Chen HT. Theory-driven evaluations. Sage; Thousand Oaks, CA: 1990.
  • Fritz MS, MacKinnon DP. Plots of the XM interaction in models of the mediated effect. A poster presented at the annual meeting of the Society for Prevention Research; San Antonio, TX. 2006, June.
  • Goldberg L, Elliot D, Clarke GN, MacKinnon DP, Moe E, Zoref L, et al. Effects of a multidimensional anabolic steroid prevention intervention: The Adolescents Training and Learning to Avoid Steroids (ATLAS) program. Journal of the American Medical Association. 1996;276:1555–1562. [PubMed]
  • Goldberg L, MacKinnon DP, Elliot DL, Moe EL, Clarke GN, Cheong J. The adolescents training and learning to avoid steroids program: Preventing drug use and promoting health behaviors. Archives of Pediatrics & Adolescent Medicine. 2000;154:332–338. [PubMed]
  • MacKinnon DP. An introduction to mediation analysis. Erlbaum; Mahwah, NJ: 2007.
  • MacKinnon DP, Fairchild AJ, Fritz MS. Mediation analysis. Annual Review of Psychology. 2007;58:593–614. [PMC free article] [PubMed]
  • MacKinnon DP, Fritz MS, Williams J, Lockwood CM. Distribution of the product confidence intervals for the indirect effect: Program PRODCLIN. Behavior Research Methods. (in press) [PMC free article] [PubMed]
  • MacKinnon DP, Goldberg L, Clarke GN, Elliot DL, Cheong J, Lapin A, et al. Mediating mechanisms in a program to reduce intentions to use anabolic steroids and improve exercise self-efficacy and dietary behavior. Prevention Science. 2001;2:15–28. [PubMed]
  • MacKinnon DP, Lockwood CM, Hoffman JM, West SG, Sheets V. A comparison of methods to test mediation and other intervening variable effects. Psychological Methods. 2002;7:83–103. [PMC free article] [PubMed]
  • MacKinnon DP, Lockwood CM, Williams J. Confidence limits for the indirect effect: Distribution of the product and resampling methods. Multivariate Behavioral Research. 2004;39:99–128. [PMC free article] [PubMed]
  • MacKinnon DP, Taborga MP, Morgan-Lopez AA. Mediation designs for tobacco prevention research. Drug and Alcohol Dependence. 2002;68:S69–S83. [PMC free article] [PubMed]
  • Merrill R. Unpublished dissertation. Arizona State University; Tempe: 1994. Treatment effect evaluation in non-additive mediation models.
  • R Core Development Team . R (Version 2.4.0) [Computer Program] The R Foundation for Statistical Computing; Vienna, Austria: 2006. Available at: www.r-project.org.
  • SAS Institute . SAS (Version 9.1) [Computer Program] SAS Institute, Inc; Cary, NC: 2006.