Last active
June 21, 2017 17:28
-
-
Save alexpghayes/df84d0bd13c49c756d5894c5241ff878 to your computer and use it in GitHub Desktop.
sampling distribution simulation for alisa
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
library(tidyverse) | |
get_ts <- function(group_size, ttt_p_inf, ctrl_p_inf) { | |
a <- rbinom(1, size = group_size, prob = ttt_p_inf) # a | |
c <- rbinom(1, size= group_size, prob = ctrl_p_inf) # c | |
b <- group_size - a | |
d <- group_size - c | |
((a - c) / group_size) / sqrt((a * b + c * d) / group_size ^ 3) | |
} | |
test_stats <- replicate(2000, get_ts(group_size = 50, ttt_p_inf = 0.3, ctrl_p_inf = 0.3)) | |
ggplot(NULL, aes(test_stats, y = ..density..)) + | |
geom_histogram(binwidth = 0.3) + | |
geom_density(fill = "cyan4", alpha = 0.5) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment