I have a doubt about my homework on how to plot multiple interactions and I would be very grateful if anyone could help. I know this is a popular topic, but I have not seen questions addressing my specific problem. I hope is not a repetition
I have a model with 3 explanatory variables and two interactions. Two variables are continuous and one is a dummy. I would like to plot into a single image the marginal effect of the three interactions. the model is something like this
y = a+ b_1c1 + b_2c2 + b_3d + b_4c1c2 + b_5c1d
In sum, I have one continuous variable (c1), that is interacted both with the other continuous variable (c2) and the dummy variable (d). The code below uses data from the MASS package to allow a reproducible example.
library(interplot)
library(MASS) # to take the dataset from
data<- cars93
library(interplot) # for plotting interations
and I create my model
model<- lm(Price ~ Horsepower*EngineSize # c1*c2 interaction
+ Horsepower*Man.trans.avail, #c1*d interaction
data = data)
I would like to plot the estimated effects of the Horsepower
on price
as a function of the EngineSize
for Man.trans.avail
=0 (No),
and plot that same conditional effect of Horsepower
on price
as a function of the EngineSize
for Man.trans.avail
=1 (Yes). Possibly putting them into the same plot.
Using the interplot
function I am able to see the conditional Horsepower
on price
as a function of the EngineSize
but without controlling for Man.trans.avail
interplot(m=model, var1 = "Horsepower", var2 = "EngineSize", hist = TRUE)
The result plots the marginal effect line of Horsepower
and EngineSize
, however, is not able to plot two lines for different values of Man.trans.avail
and I was wondering whether you had some idea on how to plot marginal effects in similar circumstances.
I thank you a lot in advance for your replies