Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. library(tidyverse)
  2.  
  3. tb <- tibble(A_effect = sort(rep(seq(-.5,.5,.002),501)),
  4. B_effect = rep(seq(-.5,.5,.002),501)) %>%
  5. mutate(noA_noB = .5,
  6. A_noB = .5 + A_effect,
  7. noA_B = .5 + B_effect,
  8. A_B = .5 + A_effect + B_effect) %>%
  9. mutate(B_among_A = (A_B)/(A_B + A_noB),
  10. B_among_nonA = (noA_B)/(noA_B+noA_noB)) %>%
  11. mutate(effect = ifelse(A_B < 0 | A_B > 1, NA, B_among_A - B_among_nonA))
  12.  
  13. ggplot(tb, aes(x = A_effect, y = B_effect)) +
  14. geom_raster(aes(fill = effect), interpolate=TRUE) +
  15. scale_fill_gradient2(low="red", mid="blue", high="red",
  16. midpoint=0, limits=range(tb$effect),
  17. name = "Collider Bias") +
  18. theme_classic() +
  19. labs(x = "Effect of binary A on P(C = 1)",
  20. y = "Effect of binary B on P(C = 1)",
  21. title = "Estimated linear effect of A on B when selecting on collider",
  22. caption = "A, B, C are binary w/ mean .5. True A and B relationship is 0.\nGray is when combined A and B effect gives P(C) outside 0 and 1.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement