My problem is simple. Suppose I have data with one response variable (y), and three explanatory variables (x1, x2, x3)...
# Example data
set.seed(123)
my.data <- data.frame(y = c(seq(1,5,length=20)+rnorm(20)),
x1 = c(seq(5,1,length=20)+rnorm(20)),
x2 = c(seq(1,10, length=20)+rnorm(20)),
x3 = rnorm(20))
I make a model. The only interactions in which I am interested in are these (only double interactions):
# Model creation
m1 <- lm(y ~ x1*x2*x3, data = my.data); summary(m1)
# x1:x2 -0.05754 0.06413 -0.897 0.387
# x1:x3 -0.47773 1.18781 -0.402 0.695
# x2:x3 -0.14915 0.48975 -0.305 0.766
I am able to visualize the individual intractions in desired way (heatmap) by this code but problem is that always one by one. For example intraction of "x1:x2"
# required packages
library(rms)
library(lattice)
ddI <- datadist(my.data)
options(datadist="ddI")
lininterp <- ols(y ~ x1*x2, data=my.data)
bplot(Predict(lininterp, x1=seq(c(min(my.data$x1)-1), c(max(my.data$x1)+1), length = 20),
x2=seq(c(min(my.data$x2)-1), c(max(my.data$x2)+1), length = 20)),
col.regions = colorRampPalette(c("red","yellow","darkgreen"))(100))
I have more than 3 explanatory variables, so the plotting is quite annoying. I would like to get something like this plot (below), but it is above my R programming skills:
I did not found any R package
which can handle it, therefore I appreciate any helpful suggestions.