Learn R Programming

DAMisc (version 1.3)

DAintfun: Surface Plots for Two-Way Interactions

Description

Makes surface plots to display interactions between two continuous variables

Usage

DAintfun(obj, varnames, theta = 45, phi = 10, xlab=NULL, ylab=NULL, zlab=NULL,...)

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.
theta
Angle defining the azimuthal viewing direction to be passed to persp
phi
Angle defining the colatitude viewing direction to be passed to persp
xlab
Optional label to put on the x-axis, otherwise if NULL, it will take the first element of varnames
ylab
Optional label to put on the y-axis, otherwise if NULL, it will take the second element of varnames
zlab
Optional label to put on the z-axis, otherwise if NULL, it will be Predictions
...
Other arguments to be passed down to the initial call to persp

Value

  • x1Values of the first element of varnames used to make predictions.
  • x2Values of the second element of varnames used to make predictions.
  • predThe predictions based on the values x1 and x2.
  • graphA graph is produced, but no other information is returned.

Details

This function makes a surface plot of an interaction between two continuous covariates. If the model is $$y_{i} = b_{0} + b_{1}x_{i1} + b_{2}x_{i2} + b_{3}x_{i1}\times x_{i2} + \ldots + e_{i},$$ this function plots $b_{1}x_{i1} + b_{2}x_{i2} + b_{3}x_{i1}\times x_{i2}$ for values over the range of $X_{1}$ and $X_{2}$. The highest 75%, 50% and 25% of the bivariate density of $X_{1}$ and $X_{2}$ (as calculated by sm.density from the sm package) are colored in with colors of increasing gray-scale.

Examples

Run this code
data(InteractionEx)
mod <- lm(y ~ x1*x2 + z, data=InteractionEx)
DAintfun(mod, c("x1", "x2"))

## Make interactive with:
# mypanel <- function(panel){
# 	DAintfun(mod, c("x1", "x2"), theta=panel$theta, phi=panel$phi)
# 	panel}
# panel <- rp.control(theta=0, phi=25)
# rp.slider(panel, theta, -360, 360, mypanel, showvalue=TRUE)
# rp.slider(panel, phi, 0, 90, mypanel, showvalue=TRUE)

Run the code above in your browser using DataLab