Click here to download the source R Markdown file: multiple_regression.Rmd. For this R Markdown file to “knit” you’ll need to ensure you’ve installed the “development” version of the moderndive package by running:

install_github("moderndive/moderndive", ref = "geom_parallel_slopes")

Data set 1

Let’s use the same data as in Jenny and Albert’s example project proposal.

school_name average_sat_math percent_economically_disadvantaged school_size
Newton South High 620 8.8 large
Quincy High 502 34.7 large
Hopedale Jr Sr High 535 9.0 medium
Madison Park High 358 68.1 large
Center For Technical Education Innovation 555 36.5 large

Interaction model

An interaction model is flexible: it allows for different slopes and different intercepts.

To plot an interaction model, we use geom_smooth() like we did in Chapter 6. Note that while the three lines at first glance seem parallel, they aren’t quite.

ggplot(ma_schools, aes(x = percent_economically_disadvantaged, y = average_sat_math, color = school_size))+
  geom_point() +
  geom_smooth(method = "lm", se = FALSE ) +
  labs(y = "Math SAT Score", x = "Percentage of Economically Disadvantaged Students")