Created
July 31, 2020 19:04
-
-
Save timcdlucas/cf78de262c29c5d76e1a1c37a2a6c1af 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
set.seed(10) | |
d <- data.frame(gender = factor(sample(c('male', 'female'), 20, replace = TRUE)), | |
height = factor(sample(c('tall', 'short'), 20, replace = TRUE))) | |
d$gender_dummy <- as.numeric(d$gender) - 1 | |
d$height_dummy <- as.numeric(d$height) - 1 | |
d$inter_dummy <- (as.numeric(d$gender) - 1)*(as.numeric(d$height) - 1) | |
d$y <- (as.numeric(d$gender) - 1) + (as.numeric(d$height) - 1) + (as.numeric(d$gender) - 1)*(as.numeric(d$height) - 1) + rnorm(20) | |
m1 <- lm(y ~ gender * height, d) | |
m2 <- lm(y ~ gender_dummy * height_dummy, d) | |
m3 <- lm(y~ gender_dummy + height_dummy + gender_dummy : height_dummy, d) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment