Conditional Effects Plots for Interactions in Linear Models

Description

Generates two conditional effects plots for two interacted continuous covariates in linear models.

Usage

1
2
3
DAintfun2(obj, varnames, rug=TRUE, ticksize=-.03, hist=FALSE, hist.col="gray75", 
	nclass=c(10, 10), scale.hist=.5, border=NA, name.stem = "cond_eff", 
	xlab = NULL, ylab = NULL, plot.type = "screen")

Arguments

obj

A model object of class lm

varnames

A two-element character vector where each element is the name of a variable involved in a two-way interaction.

rug

Logical indicating whether a rug plot should be included.

ticksize

A scalar indicating the size of ticks in the rug plot (if included) positive values put the rug inside the plotting region and negative values put it outside the plotting region.

hist

Logical indicating whether a histogram of the x-variable should be included in the plotting region.

hist.col

Argument to be passed to polygon indicating the color of the histogram bins.

nclass

vector of two integers indicating the number of bins in the two histograms, which will be passed to hist.

scale.hist

A scalar in the range (0,1] indicating how much vertical space in the plotting region the histogram should take up.

border

Argument passed to polygon indicating how the border of the histogram bins should be printed (NA for no border).

name.stem

A character string giving filename to which the appropriate extension will be appended

xlab

Optional vector of length two giving the x-labels for the two plots that are generated. The first element of the vector corresponds to the figure plotting the conditional effect of the first variable in varnames given the second and the second element of the vector corresponds to the figure plotting the conditional effect of the second variable in varnames conditional on the first.

ylab

Optional vector of length two giving the y-labels for the two plots that are generated. The first element of the vector corresponds to the figure plotting the conditional effect of the first variable in varnames given the second and the second element of the vector corresponds to the figure plotting the conditional effect of the second variable in varnames conditional on the first.

plot.type

One of ‘pdf’, ‘png’, ‘eps’ or ‘screen’, where the one of the first three will produce two graphs starting with name.stem written to the appropriate file type and the third will produce graphical output on the screen.

Details

This function produces graphs along the lines suggested by Brambor, Clark and Golder (2006) and Berry, Golder and Milton (2012), that show the conditional effect of one variable in an interaction given the values of the conditioning variable. This is an alternative to the methods proposed by John Fox in his effects package, upon which this function depends heavily.

Specifically, if the model is

y = b[0] + b[1]x1 + b[2]x2 + b[3]x1*x2 + ... + e[i],


this function plots calculates the conditional effect of X1 given X2

dy/dX1 = b[1] + b[3]X2

and the variances of the conditional effects

V(b[1] + b[3]X[2]) = V(b[1] + (X[2]^2)V(b[3]) + 2(1)(X[2])V(b[1],b[3]))

for different values of X2 and then switches the places of X1 and X2, calculating the conditional effect of X2 given a range of values of X1. 95% confidence bounds are then calculated and plotted for each conditional effects along with a horizontal reference line at 0.

Value

graphs

Either a single graph is printed on the screen (using par(mfrow=c(1,2))) or two figures starting with name.stem are produced where each gives the conditional effect of one variable based on the values of another.

Author(s)

Dave Armstrong (UW-Milwaukee, Department of Political Science)

References

Brambor, T., W.R. Clark and M. Golder. (2006) Understanding Interaction Models: Improving Empirical Analyses. Political Analysis 14, 63-82.
Berry, W., M. Golder and D. Milton. (2012) Improving Tests of Theories Positing Interactions. Journal of Politics.

Examples

1
2
3
data(InteractionEx)
mod <- lm(y ~ x1*x2 + z, data=InteractionEx)
DAintfun2(mod, c("x1", "x2"), hist=TRUE, scale.hist=.3)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.