R: Plotting Conditional Regression Lines with Interactions in...
intr.plot.2d
R Documentation
Plotting Conditional Regression Lines with Interactions in Two Dimensions
Description
To plot regression lines for one two-way interactions, holding one of the predictors (in this function, z) at
values -2, -1, 0, 1, and 2 standard deviations above the mean.
regression coefficient for the interaction of predictors x and z
x.min,x.max
the range of x used in the plot
x
a specific predictor vector x, used instead of x.min and x.max
n.x
number of elements in predictor vector x
mean.z
mean of predictor z
sd.z
standard deviation of predictor z
z
a specific predictor vector z, used instead of z.min and z.max
xlab
title for the axis which the predictor x is on
ylab
title for the axis which the dependent y is on
sd.plot, sd2.plot, sd_1.plot, sd_2.plot
whether or not to plot
the regression line holding z at values 1, 2, -1, and -2 standard deviations above the mean, respectively.
Default values are all TRUE.
type.sd, type.sd2, type.sd_1, type.sd_2
types of lines to be plotted holding z at values 1, 2,
-1, and -2 standard deviations above the mean, respectively. Default are line type 2,3,4, and 5, respectively.
legend.pos
position of the legend; possible options are "bottomright", "bottom",
"bottomleft", "left", "center", "right", "topleft",
"top", and "topright".
legend.on
whether or not to show the legend
...
allows one to potentially include parameter values for inner functions
Details
To input the predictor x, one can use either the limits of x (x.max and x.min) , or a specific vector x (x).
To input the predictor z, one can use either the mean and standard deviation of z (mean.z and sd.z ), or a specific vector z (z).
Note
Sometimes some of the regression lines are outside the default scope of the coordinates
and thus cannot be seen; in such situations, one needs to, by entering additional arguments, adjust the scope to
let proper sections of regression lines be seen. Refer to examples below for more details.
Author(s)
Keke Lai, Ken Kelley (University of Notre Dame; KKelley@ND.Edu)
References
Cohen, J., Cohen, P., West, S. G. and Aiken, L. S. (2003). Applied multiple regression/correlation
analysis for the behavioral sciences (3rd ed.). Mahwah, NJ: Erlbaum.
See Also
intr.plot
Examples
## A situation where one regression line is outside the default scope of the coordinates
intr.plot.2d(b.0=16, b.x=2.2, b.z=2.6, b.xz=.4, x.min=0, x.max=20, mean.z=0, sd.z=3)
## Adjust the scope of x and y axes so that proper sections of regression lines can be seen
intr.plot.2d(b.0=16, b.x=2.2, b.z=2.6, b.xz=.4, x.min=0, x.max=50, mean.z=0,
sd.z=3, xlim=c(0,50), ylim=c(-20,100) )
## Use specific vector(s) to define the predictor(s)
intr.plot.2d(b.0=16, b.x=2.2, b.z=2.6, b.xz=.4, x=c(1:10), z=c(0,2,4,6,8,10))
intr.plot.2d(b.0=16, b.x=2.2, b.z=2.6, b.xz=.4, x.min=0, x.max=20,
z=c(1,3,6,7,9,13,16,20), ylim=c(0,100))
## Change the position of the legend so that it does not block regression lines
intr.plot.2d(b.0=10, b.x=-.3, b.z=1, b.xz=.5, x.min=0, x.max=40, mean.z=-5, sd.z=3,
ylim=c(-100,100),legend.pos="topright" )
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(MBESS)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/MBESS/intr.plot.2d.Rd_%03d_medium.png", width=480, height=480)
> ### Name: intr.plot.2d
> ### Title: Plotting Conditional Regression Lines with Interactions in Two
> ### Dimensions
> ### Aliases: intr.plot.2d
> ### Keywords: regression
>
> ### ** Examples
>
> ## A situation where one regression line is outside the default scope of the coordinates
> intr.plot.2d(b.0=16, b.x=2.2, b.z=2.6, b.xz=.4, x.min=0, x.max=20, mean.z=0, sd.z=3)
>
> ## Adjust the scope of x and y axes so that proper sections of regression lines can be seen
> intr.plot.2d(b.0=16, b.x=2.2, b.z=2.6, b.xz=.4, x.min=0, x.max=50, mean.z=0,
+ sd.z=3, xlim=c(0,50), ylim=c(-20,100) )
>
> ## Use specific vector(s) to define the predictor(s)
> intr.plot.2d(b.0=16, b.x=2.2, b.z=2.6, b.xz=.4, x=c(1:10), z=c(0,2,4,6,8,10))
>
> intr.plot.2d(b.0=16, b.x=2.2, b.z=2.6, b.xz=.4, x.min=0, x.max=20,
+ z=c(1,3,6,7,9,13,16,20), ylim=c(0,100))
>
> ## Change the position of the legend so that it does not block regression lines
> intr.plot.2d(b.0=10, b.x=-.3, b.z=1, b.xz=.5, x.min=0, x.max=40, mean.z=-5, sd.z=3,
+ ylim=c(-100,100),legend.pos="topright" )
>
>
>
>
>
>
> dev.off()
null device
1
>