Created
June 18, 2021 18:46
-
-
Save rmcelreath/e9ae9e623c9d49dcbd4b97fb660408fb to your computer and use it in GitHub Desktop.
Code examples for RFDT
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(1908) | |
N <- 200 # number of pairs | |
U <- rnorm(N,0,1) # simulate confounds | |
# birth order and family sizes | |
B1 <- rbinom(N,size=1,prob=0.5) # 50% first borns | |
M <- rnorm( N , 2*B1 + U ) | |
B2 <- rbinom(N,size=1,prob=0.5) | |
D <- rnorm( N , 2*B2 + U + 0*M ) | |
f <- function(data,indices) with(data[indices,], cov(B1,D) / cov(B1,M) ) | |
dat <- data.frame(M=M,D=D,B1=B1,B2=B2) | |
library(boot) | |
boot( data=dat , statistic=f , R=1e4 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment