I want to test whether two predicted values of y for a given value of x1 (a continuous variable) at two different levels of x2 (a continuous variable) are significantly different from each other.
I have a significant interaction of x1 and x2 predicting y. Below I plot the interaction effect, showing the effect of x1 on y for two levels of x2: +1 SD, and -1 SD. I want to test whether the predicted values of y given a specific value of x1 (e.g., x1 = +1 SD) are significantly different for two levels of x2.
Here is sample dataset:
set.seed(100)
x1 <- scale(rnorm(100,2,10), center=T, scale=F)
x2 <- scale(rnorm(100,2,10), center=T, scale=F)
y <- x1+x2+x1*x2+rnorm(100,1,2)
dat <- data.frame(y=y,x1=x1,x2=x2)
res <- lm(y~x1*x2,data=dat)
As you will see, the interaction of x1 and x2 is significant. Here is the interaction effect plotted, with predicted lines for x2 and +1 SD and -1 SD
As shown in the graph, predicted value of y when x1 is +1 SD above the mean and when x2 is +1 SD above the mean is 100.22364 (where the gray dotted line and solid blue line intersect), and the predicted value of y when x1 is +1 SD above the mean and when x2 is -1 SD above the mean is -77.46657 (where the gray dotted line and dashed blue line intersect). I need to create code to test whether the difference in those predicted ys (i.e., 100.22364- -77.46657 = 177.6902) is significantly different from 0 as well as code for obtaining inferential statistics for this test (i.e., t-value, p-value, 95% confidence interval).