Skip to content

Instantly share code, notes, and snippets.

@rmcelreath
Created June 18, 2021 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rmcelreath/e9ae9e623c9d49dcbd4b97fb660408fb to your computer and use it in GitHub Desktop.
Save rmcelreath/e9ae9e623c9d49dcbd4b97fb660408fb to your computer and use it in GitHub Desktop.
Code examples for RFDT
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