Created
June 29, 2021 09:26
-
-
Save rmcelreath/9257bcd9d9e89d5e5f5af79a369494aa 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
# 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) |
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.
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
this is very helpful - however should line 17 read b*1 instead of b*0?