Skip to content

Instantly share code, notes, and snippets.

@timcdlucas
Created July 31, 2020 19:04
Show Gist options
  • Save timcdlucas/cf78de262c29c5d76e1a1c37a2a6c1af to your computer and use it in GitHub Desktop.
Save timcdlucas/cf78de262c29c5d76e1a1c37a2a6c1af to your computer and use it in GitHub Desktop.
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