Skip to content

Instantly share code, notes, and snippets.

@ajstewartlang
Last active November 23, 2018 22:06
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 ajstewartlang/422fda3a81f0b7186f940176cbed70d9 to your computer and use it in GitHub Desktop.
Save ajstewartlang/422fda3a81f0b7186f940176cbed70d9 to your computer and use it in GitHub Desktop.
100000 samples with N=20 and no difference in population sampled from
library(tidyverse)
df <- NULL
set.seed(1111)
sample_size = 20
for (i in 1:100000) {
a <- rnorm(sample_size, mean = 10, sd = 2)
b <- rnorm(sample_size, mean = 10, sd = 2)
a <- cbind(a, rep ("A", sample_size), rep (i, sample_size))
b <- cbind(b, rep("B", sample_size), rep (i, sample_size))
df <- as.tibble(rbind(df, (rbind(a, b))))
}
colnames(df) <- c("Score","Condition", "Sample")
df$Score <- as.numeric(df$Score)
data <- NULL
for (i in 1:100000) {
toa <- as.tibble(cbind(filter(df, Sample==i & Condition=="A")$Score,
filter(df, Sample==i & Condition=="B")$Score))
data <- rbind(data, tidy(t.test(toa$V1, toa$V2)))
}
ggplot(data, aes(x = p.value)) + geom_histogram()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment