Created
February 28, 2019 16:56
-
-
Save alexpghayes/71cd5e82d650525fddbe4f1d6e80da51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
df <- mtcars %>% | |
mutate( | |
# here 20, 25 are the cut points | |
region = cut(mpg, c(min(mpg), 20, 25, max(mpg))) | |
) | |
ols <- lm(hp ~ region * mpg, df) | |
summary(ols) | |
ggplot(df, aes(mpg, hp, color = region)) + | |
geom_point() + | |
geom_smooth(method = "lm") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment