Last active
March 25, 2018 21:34
-
-
Save JonasMoss/55f99d24669ff26f7d89f1e9a6c1e068 to your computer and use it in GitHub Desktop.
Idealistic simulation of true powers in psychology.
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
## A small simulation of how powers could be distributed in psychology. | |
## 'sn' is the skew-normal distribution, which I suppose is useful in this case. | |
## The package is available from CRAN: | |
## install.packages("sn") | |
set.seed(313) | |
N = 100000 | |
thetas = sn::rsn(N, xi = 0.05, omega = 0.15, alpha = 2) # Sample of true thetas. | |
## I assume the effect sizes (thetas) are sampled from the following | |
## distribution. | |
plot(theta, sn::dsn(theta, xi = 0.05, omega = 0.15, alpha = 2), type = "l") | |
# Generate slightly biased guesses for thetas. | |
thetas_guess = pmax(thetas + runif(N, -0.01, 0.07), 0.05) | |
# These ns are exact when the guesses are exact. | |
ns = (1.96 - qnorm(0.2))^2/thetas_guess^2 | |
hist(1 - pnorm(1.96 - sqrt(ns)*thetas), breaks = 100, main = "Power plot", | |
xlab = "Power", ylab = "Density", freq = FALSE) | |
abline(v = mean(1 - pnorm(1.96 - sqrt(ns)*thetas)), lty = 2, lwd = 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment