Skip to content

Instantly share code, notes, and snippets.

@cddesja
Created July 2, 2020 18:32
Show Gist options
  • Save cddesja/c32be7f794b7b0cec9a685ada678f95d to your computer and use it in GitHub Desktop.
Save cddesja/c32be7f794b7b0cec9a685ada678f95d to your computer and use it in GitHub Desktop.
mtcars$vs.f <- ifelse(mtcars$vs == 0, "0", "1")
mtcars.0 <- subset(mtcars, vs.f == "0")
mtcars.1 <- subset(mtcars, vs.f == "1")
coef(lm(mpg ~ cyl * vs.f, data = mtcars)) # association between 1 should be strong
coef(lm(mpg ~ cyl, data = mtcars.0)) # association between 0 smaller
coef(lm(mpg ~ cyl, data = mtcars.1)) # association between 1 larger
cor(mtcars.0$mpg, mtcars.0$cyl)
cor(mtcars.1$mpg, mtcars.1$cyl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment