Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Idealistic simulation of true powers in psychology.
## 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