Open malcolmbarrett opened 2 years ago
Another simulation based on the above:
n <- 10000
library(tidyverse)
c <- rbinom(n, 1, 0.4)
x <- rbinom(n, 1, ifelse(c == 1, 0.5, 0.2))
y <- x + c + 0 * x * c + rnorm(n)
data <- tibble(
x,
y,
c
)
mod <- lm(y ~ x + c, data)
mod |>
broom::tidy()
data_1 <- data |>
mutate(x = 1)
data_0 <- data |>
mutate(x = 0)
data_1$p <- predict(mod, newdata = data_1)
data_0$p <- predict(mod, newdata = data_0)
mean(data_1$p) - mean(data_0$p)
Big ideas: