# How do I derive slope and intercept for each group in regression model with a categorical and 2 continuous predictor variables?

$IQ = b_0 + b_1Group + b_2Age + b_3Income + b4\times Group\times Age$

Group is dummy coded ($0,1$)

I assume that the interaction of Group x Age tests the group difference in the slope of the IQ vs. Age regression line while controlling for Income.

I would like to show a scatter plot of the data for each group showing the slope and intercept to illustrate the slope difference between the groups in the age relationship. I know how to do it when only one continuous predictor variable, but not sure how to handle the presence of the second continuous predictor in the model above.

I need help with

1) what values to plot for IQ vs. Age plot (given that Age has been residualized on Income in the regression model)?

2) How to derive the slope and intercept of the regression line for each group depicting their IQ vs. Age relationship from a model that also contains Income as a second continuous predictor variable?

Assuming $Y = 100 + 150 \times Group + 5 \times Age + 20 \times Income + 4 \times Group*Age$

When $group = 0$, the model reduces to: $Y = 100 + 5 \times Age + 20 \times Income$

Notice that because there isn't any interaction between Income and Age, if you plot the regression line of Y versus age, the slope will always be 5 because the 3-D regression plane in this case is flat. The coefficient 20 for the Income merely shifts the line up and down.

The trick of incorporating the information of Income is then to plot a few regression lines that are representative of the Income. One of the common choices is mean, +/- 1 SD, and +/- 2SDs. Another common choice is some quantiles. Here I plotted 5 lines using the 0th, 20th, 40th, 60th, 80th, and 100th percentiles of Income (which I just assumed them to be 0, 5, 10, 25, and 45 units.) The 0th percentile group will have no offset, the 20th percentile group will have $5 \times 20$ upward offset; the 40th, $10 \times 20$, so on so forth. That would give us the plot on the left hand side below.

Now, when $group = 1$, the model becomes:

$Y = 100 + 150 + 5 \times Age + 20 \times Income + 4 \times Age$,

simply:

$Y = 250 + 9 \times Age + 20 \times Income$

Applying the same method as if Group = 0, we can then plot the other scenarios.

Below is the resultant graph. To make the plot more independent, I'd also suggest adding the actual income data for each selected percentile in the footnote. # Y = 100 + 150*Group + 5*age + 20*Income + 4*Group*Age

par(mfrow=c(1,2),mar=c(5,5,1,2))

plot(1,1,xlim=c(20,70), ylim=c(0,1800),ylab="Outcome", xlab="Age", axes=F)
title("Group = 0")
abline(100+(20*0), 5, col="#d9f0a3", lwd=2)
abline(100+(20*10), 5, col="#78c679", lwd=2)
abline(100+(20*25), 5, col="#41ab5d", lwd=2)
abline(100+(20*45), 5, col="#006837", lwd=2)
axis(side=1)
axis(side=2)

plot(1,1,xlim=c(20,70), ylim=c(0,1800),ylab="", xlab="Age", axes=F)
title("Group = 1")
abline(100+(20*0)+150, 5+4, col="#d9f0a3", lwd=2)
abline(100+(20*10)+150, 5+4, col="#78c679", lwd=2)
abline(100+(20*25)+150, 5+4, col="#41ab5d", lwd=2)
abline(100+(20*45)+150, 5+4, col="#006837", lwd=2)
axis(side=1)
axis(side=2)

legend(50,500, box.col="white",
title = "Income",
c("0th percentile",
"20th percentile",
"40th percentile",
"80th percentile",
"100th percentile"),
lty=1, lwd=2, cex=0.8,