Created
April 5, 2023 08:40
-
-
Save thlytras/2357c7931ef59d536cad6c6c1f1a573a to your computer and use it in GitHub Desktop.
Minimal example of collider bias, using R
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(42) | |
dat <- data.frame( | |
A = rbinom(500, 1, 0.5), | |
B = rbinom(500, 1, 0.5) | |
) | |
dat$C = rbinom(500, 1, 0.1 + 0.3*dat$A + 0.4*dat$B) | |
tb <- with(dat, table(A,B)) | |
tb0 <- with(subset(dat, C==0), table(A,B)) | |
tb1 <- with(subset(dat, C==1), table(A,B)) | |
print(tb) | |
print(chisq.test(tb)) | |
print(tb0) | |
print(chisq.test(tb0)) | |
print(tb1) | |
print(chisq.test(tb1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment