Skip to content

Instantly share code, notes, and snippets.

@alexpghayes
Created February 28, 2019 16:56
Show Gist options
  • Save alexpghayes/71cd5e82d650525fddbe4f1d6e80da51 to your computer and use it in GitHub Desktop.
Save alexpghayes/71cd5e82d650525fddbe4f1d6e80da51 to your computer and use it in GitHub Desktop.
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