Skip to content

Instantly share code, notes, and snippets.

@rmcelreath
Created June 29, 2021 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmcelreath/9257bcd9d9e89d5e5f5af79a369494aa to your computer and use it in GitHub Desktop.
Save rmcelreath/9257bcd9d9e89d5e5f5af79a369494aa to your computer and use it in GitHub Desktop.
Code examples for RFDT
# simulate interventions
# B1 -> D (should be b*m)
post <- extract.samples(flbi)
quantile( with(post,b*m) )
# now do the same with simulation
# B1 = 0
# B1 -> M
M_B1_0 <- with( post , a1 + b*0 + k*0 )
# M -> D
D_B1_0 <- with( post , a2 + b*0 + m*M_B1_0 + k*0 )
# now same but with B1 = 1
M_B1_1 <- with( post , a1 + b*1 + k*0 )
D_B1_1 <- with( post , a2 + b*0 + m*M_B1_1 + k*0 )
# difference to get causal effect
d_D_B1 <- D_B1_1 - D_B1_0
quantile(d_D_B1)
@vitallish
Copy link

this is very helpful - however should line 17 read b*1 instead of b*0?

@rmcelreath
Copy link
Author

The b term on line 17 is the daughter's birth order, which needs to match line 13. Only mother's birth order (B1) is intervened on.

@vitallish
Copy link

Ah I see - thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment