-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58b2118
commit 790022b
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Assume mean of Group 1 known to be 0 | ||
# Therefore we only measure Group 2 data | ||
# Let eps = true difference in means | ||
# Let sigma = true variance of data | ||
# We wish to find smallest sample size, N, such that | ||
# E[p] < 0.05 | ||
|
||
find.minimum.n <- function(eps, sigma, n.sims = 10000) | ||
{ | ||
n <- 2 | ||
|
||
n.too.small <- TRUE | ||
|
||
while (n.too.small) | ||
{ | ||
p <- rep(NA, n.sims) | ||
|
||
for (i in 1:n.sims) | ||
{ | ||
x <- rnorm(n, eps, sigma) | ||
p[i] <- t.test(x)$p.value | ||
} | ||
|
||
if (mean(p) < 0.05) | ||
{ | ||
n.too.small <- FALSE | ||
} | ||
else | ||
{ | ||
n <- n + 1 | ||
} | ||
} | ||
|
||
return(n) | ||
} | ||
|
||
set.seed(1) | ||
epsilons <- 10 ^ seq(-1, 1, by = 0.01) | ||
|
||
df <- data.frame(Effect = epsilons, N = NA) | ||
|
||
for (i in 1:nrow(df)) | ||
{ | ||
eps <- df$Effect[i] | ||
df$N[i] <- find.minimum.n(eps, 1, 2500) | ||
} | ||
|
||
ggplot(df, aes(x = Effect, y = N)) + geom_line() + scale_x_log10() + opts(title = "Minimum Sample Size Required to Pass p < .05 NHST in Expectation") + xlab("Effect Size") + ylab("Minimum N") | ||
ggsave("article5/sample_size.png") | ||
|
||
save(df, file = "cache.Rdata") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.