Last active
October 14, 2023 07:48
-
-
Save tmalsburg/3d8f71deadd2cdfb8baa179aeffb155e to your computer and use it in GitHub Desktop.
Quick simulation of 50 experiments and their means and 95% confidence intervals
This file contains hidden or 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
set.seed(1) | |
mu <- 0 | |
sigma <- 1 | |
N.trials <- 20 | |
N.sims <- 50 | |
rnorm(N.trials*N.sims, mu, sigma) |> | |
matrix(nrow=N.sims) -> Y | |
d <- apply(Y, 1, \(y) c(mean(y), sd(y)/sqrt(length(y)))) | |
plot(d[1,], pch=19, ylim=c(-1,1), | |
col=ifelse(d[1,]+2*d[2,]<0 | d[1,]-2*d[2,]>0, "red", "black"), | |
xlab="Simulation number", ylab="DV") | |
arrows(1:N.sims, d[1,]+2*d[2,], 1:N.sims, d[1,]-2*d[2,], | |
col=ifelse(d[1,]+2*d[2,]<0 | d[1,]-2*d[2,]>0, "red", "black"), | |
code=0, lwd=2) | |
abline(h=0, lty=2, col="red", lwd=3) | |
Author
tmalsburg
commented
Oct 14, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment