$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?


2 Answers 2


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$,


$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.

enter image description here

R code for your reference:

# Y = 100 + 150*Group + 5*age + 20*Income + 4*Group*Age


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*5), 5, col="#addd8e", 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)

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*5)+150, 5+4, col="#addd8e", 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)

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,

There are various ways, but essentially you have to pick some particular income or incomes and then plot the results in the usual way. You can pick, e.g. the median income, top and bottom quartiles, etc. Then the income term becomes part of the intercept.

  • $\begingroup$ Thanks. So if Income is set to be $1000, i will get the following: For group assigned 0 in dummy variable: Intercept=b0 + b3*1000; For group assigned 1 in dummy variable: Intercept=b0 + b1 + b3*1000. Slope for Group assigned 0 is b2; Slope for Group assigned 1 is b2 + b4. QUESTION: When I plot these regression lines on the scatter plot of the data for each group, should I just use IQ vs. Age, or does Age need to be residualized on Income first before making scatter plot and drawing regression lines? $\endgroup$ May 8, 2013 at 3:30
  • $\begingroup$ I think you can plot them just as they are $\endgroup$
    – Peter Flom
    May 8, 2013 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.