Last active
June 20, 2024 13:59
-
-
Save turgeonmaxime/76f13fea43c3f0e0da0124fc0581b537 to your computer and use it in GitHub Desktop.
Post-hoc power analysis
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
mu <- 0.1 | |
sigma <- 1 | |
nsamp <- 36 | |
B <- 1000 | |
real_power <- power.t.test(delta = mu, sd = sigma, n = nsamp, | |
alternative = "one.sided", | |
type = "one.sample")$power | |
res <- replicate(B, { | |
norm_samp <- rnorm(nsamp, mean = mu, sd = sigma) | |
mu_hat <- mean(norm_samp) | |
sigma_hat <- sd(norm_samp) | |
power.t.test(delta = mu_hat, sd = sigma_hat, n = nsamp, | |
alternative = "one.sided", | |
type = "one.sample")$power | |
}) | |
hist(res, 50, main = 'Post-hoc power estimates', xlab = 'Power') | |
abline(v = real_power, lty = 2) |
Author
turgeonmaxime
commented
Jun 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment