Skip to content

Instantly share code, notes, and snippets.

@alexpghayes
Last active June 21, 2017 17:28
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 alexpghayes/df84d0bd13c49c756d5894c5241ff878 to your computer and use it in GitHub Desktop.
Save alexpghayes/df84d0bd13c49c756d5894c5241ff878 to your computer and use it in GitHub Desktop.
sampling distribution simulation for alisa
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