You are on page 1of 20

NIH Public Access

Author Manuscript
Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Published in final edited form as:
NIH-PA Author Manuscript

Behav Res Methods. 2008 February ; 40(1): 55–60.

A Graphical Representation of the Mediated Effect

Matthew S. Fritz and David P. MacKinnon


Department of Psychology, Arizona State University Tempe, AZ 85287-1104

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.
NIH-PA Author Manuscript

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
NIH-PA Author Manuscript

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.

Corresponding author: Matthew S. Fritz, M.A. Department of Psychology Arizona State University Box 871104 Tempe, AZ 85287-1104
Phone: (480) 965-0915 Fax: (480) 727-6176 matt.fritz@asu.edu.
Portions of this work have been presented at the annual meeting of the Society for Prevention Research.
Fritz and MacKinnon Page 2

Mediation
Mediation is the name given to models in which the effect of an antecedent or independent
NIH-PA Author Manuscript

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:

(1)

(2)

(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,
NIH-PA Author Manuscript

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.

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,

(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.
NIH-PA Author Manuscript

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, c – c’, 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).

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 3

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
NIH-PA Author Manuscript

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 corresponding to
X=0 and a second horizontal line is placed at corresponding to X=1. The distance
between the horizontal lines represents the total effect of X on Y, . Then, Equation 2 is plotted
for both values of X, resulting in a vertical line at and a second vertical line at
. The distance between the two vertical lines represents the action theory and is equal
NIH-PA Author Manuscript

to . Finally, Equation 3 is plotted at both values of X. The slopes of these parallel simple
regression lines are equal to . Looking at the vertical line, the distance between the
horizontal line and the point where the regression line for the X=0 group intersects the
vertical line is equal to , and the distance from this intersection point to the
horizontal line is equal to the mediated effect, .

Interpreting the plot is straightforward (MacKinnon, 2007; MacKinnon, Fairchild, & Fritz,
2007; Merrill, 1994). Looking at Figure 2, it can be seen that 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 , 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, , 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, , is then the predicted change in Y
for an unit increase in M, which corresponds to a one unit change in X. Finally, looking at
the length of relative to the length of indicates the amount of the overall effect of X on
NIH-PA Author Manuscript

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 , 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

, which is equal to the mean of Y, and at , and vertical lines are plotted

at , which equals the mean of M, and . The distance between the


horizontal lines is then equal to and distance between the two vertical lines is equal to .
Finally, Equation 3 is plotted. Because X is continuous, specific values of X must be selected

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 4

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 . Looking at the
NIH-PA Author Manuscript

vertical line, the distance between the horizontal line and the

point where the regression line for the mean of X intersects the vertical line is
equal to , and the distance from the intersection point to the horizontal line is equal
to the mediated effect, . The interpretation of the effects in the plot are identical to case with
a dichotomous X variable.

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

A word of caution is needed for inconsistent mediation models. In an inconsistent mediation


model, and are significant, but opposite in sign, which can cause to be nonsignificant.
As shown in Equation 4, if and are equal in magnitude but opposite in sign, then 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
and 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 line outside of the range of the horizontal lines that represent the total effect .

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.
NIH-PA Author Manuscript

Instead of estimating Equation 3, however, the equation

(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

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 5

X=1 when the interaction effect 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, .
NIH-PA Author Manuscript

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
NIH-PA Author Manuscript

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 (se =
0.0636) , (se = 0.0640) , (se = 0.0637) , and (se = 0.0238) , which
are plotted in Figure 5. The plot shows the difference in magnitude between the direct effect
and the indirect effect , 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 gave a 95% confidence interval of [−0.02161, 0.06354], which
shows that the indirect effect is not significant.

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 (se = 0.0745) , (se =
0.0231) , (se = 0.0620) , and (se = 0.0619) , which are plotted in Figure 6.
Looking at this plot, we see that the proportion of the total effect, , that is attributable to the
NIH-PA Author Manuscript

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 gives a 95% confidence interval of [0.11332, 0.20432], which leads
to the conclusion that the mediator is significant.

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.

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 6

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
NIH-PA Author Manuscript

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
Refer to Web version on PubMed Central for supplementary material.

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

APPENDIX A
A.1. R Program For Plotting Mediated Effects
NIH-PA Author Manuscript

“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’)
NIH-PA Author Manuscript

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]

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 7

i1<−sum.yx$coefficients[1,1]

#Equation 2
NIH-PA Author Manuscript

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]
NIH-PA Author Manuscript

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)
NIH-PA Author Manuscript

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)

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 8

#Effect of X on Y (c)
hor1<−i1+c*0
NIH-PA Author Manuscript

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


NIH-PA Author Manuscript

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)
NIH-PA Author Manuscript

#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)

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 9

vert1<−i2+a*meanx
vert2<−i2+a*(meanx+1)
abline(v=vert1)
NIH-PA Author Manuscript

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)
NIH-PA Author Manuscript

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)
NIH-PA Author Manuscript

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−

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 10

1sd)”),
lty=1:3,lwd=3,bty=“n”) }
detach(data1)
NIH-PA Author Manuscript

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.*/
NIH-PA Author Manuscript

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;
NIH-PA Author Manuscript

%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;

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 11

data out3; set out1;


if _model_=“MODEL2” then i2=intercept;
if _model_=“MODEL2” then a=x;
NIH-PA Author Manuscript

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);
NIH-PA Author Manuscript

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;
NIH-PA Author Manuscript

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);

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 12

%let href1=&i2;
%let href2=%sysevalf(&i2+&a);
NIH-PA Author Manuscript

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;
NIH-PA Author Manuscript

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));
NIH-PA Author Manuscript

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;

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 13

*Syntax for the continuous, interaction condition;


%if(&cont=1 and &int=1) %then %do;
proc means data=data1 noprint;
NIH-PA Author Manuscript

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));
NIH-PA Author Manuscript

%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;
NIH-PA Author Manuscript

quit;

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: 3806354]
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

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 14

(ATLAS) program. Journal of the American Medical Association 1996;276:1555–1562. [PubMed:


8918852]
Goldberg L, MacKinnon DP, Elliot DL, Moe EL, Clarke GN, Cheong J. The adolescents training and
NIH-PA Author Manuscript

learning to avoid steroids program: Preventing drug use and promoting health behaviors. Archives of
Pediatrics & Adolescent Medicine 2000;154:332–338. [PubMed: 10768668]
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.
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).
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: 11519372]
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. [PubMed:
11928892]
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. [PubMed:
20157642]
MacKinnon DP, Taborga MP, Morgan-Lopez AA. Mediation designs for tobacco prevention research.
Drug and Alcohol Dependence 2002;68:S69–S83. [PubMed: 12324176]
NIH-PA Author Manuscript

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.
NIH-PA Author Manuscript

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 15
NIH-PA Author Manuscript

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.
NIH-PA Author Manuscript
NIH-PA Author Manuscript

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 16
NIH-PA Author Manuscript

Figure 2.
Plot of the mediated effect for a dichotomous X variable.
NIH-PA Author Manuscript
NIH-PA Author Manuscript

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 17
NIH-PA Author Manuscript

Figure 3.
Plot of the mediated effect for a continuous X variable. Note that sd stands for the standard
deviation of X.
NIH-PA Author Manuscript
NIH-PA Author Manuscript

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 18
NIH-PA Author Manuscript
NIH-PA Author Manuscript

Figure 4.
Plot of the mediated effect with a XM interaction.
NIH-PA Author Manuscript

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 19
NIH-PA Author Manuscript
NIH-PA Author Manuscript

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

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.
Fritz and MacKinnon Page 20
NIH-PA Author Manuscript

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).
NIH-PA Author Manuscript
NIH-PA Author Manuscript

Behav Res Methods. Author manuscript; available in PMC 2010 July 13.

You might also like