Created
May 27, 2015 19:31
-
-
Save leeper/cf3b823e25735c836bdd to your computer and use it in GitHub Desktop.
One- and two-tailed tests.
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
layout(matrix(1:3, nrow = 1)) | |
# alpha = 0.05, two-tailed | |
curve(dnorm, from = -3.5, to = +3.5, lwd = 2, xaxs = "i", yaxs = "i", xlab = "z-statistic", ylim = c(0, .41), bty = "l", main = 'p<0.05, two-tailed ("Significant, Star-Worthy")') | |
polygon(c(qnorm(0.025), seq(qnorm(0.025), qnorm(.001), length.out = 20), -5), | |
c(0,dnorm(seq(qnorm(0.025), qnorm(.001), length.out = 20)), 0), col = rgb(1,0,0,alpha = 0.5)) | |
segments(qnorm(0.025), 0, qnorm(0.025), 0.4, lwd = 2) | |
polygon(c(5, qnorm(0.975), seq(qnorm(0.975), qnorm(.999), length.out = 20)), | |
c(0,0,dnorm(seq(qnorm(0.975), qnorm(.999), length.out = 20))), col = rgb(1,0,0,alpha = 0.5)) | |
segments(qnorm(0.975), 0, qnorm(0.975), 0.4, lwd = 2) | |
text(qnorm(0.975), 0.3, paste0("z = ", sprintf("%0.2f", qnorm(0.975))), pos = 4, cex = 1.5) | |
# alpha = 0.10, two-tailed | |
curve(dnorm, from = -3.5, to = +3.5, lwd = 2, xaxs = "i", yaxs = "i", xlab = "z-statistic", ylim = c(0, .41), bty = "l", main = 'p<0.10, two-tailed ("Not Significant, Not Star-Worthy")') | |
polygon(c(qnorm(0.05), seq(qnorm(0.05), qnorm(.001), length.out = 20), -5), | |
c(0,dnorm(seq(qnorm(0.05), qnorm(.001), length.out = 20)), 0), col = rgb(1,0,0,alpha = 0.5)) | |
segments(qnorm(0.05), 0, qnorm(0.05), 0.4, lwd = 2) | |
polygon(c(5, qnorm(0.95), seq(qnorm(0.95), qnorm(.999), length.out = 20)), | |
c(0,0,dnorm(seq(qnorm(0.95), qnorm(.999), length.out = 20))), col = rgb(1,0,0,alpha = 0.5)) | |
segments(qnorm(0.95), 0, qnorm(0.95), 0.4, lwd = 2) | |
text(qnorm(0.95), 0.3, paste0("z = ", sprintf("%0.2f", qnorm(0.95))), pos = 4, cex = 1.5) | |
# alpha = 0.05, one-tailed | |
curve(dnorm, from = -3.5, to = +3.5, lwd = 2, xaxs = "i", yaxs = "i", xlab = "z-statistic", ylim = c(0, .41), bty = "l", main = 'p<0.05, one-tailed ("Significant, Star-Worthy")') | |
polygon(c(5, qnorm(0.95), seq(qnorm(0.95), qnorm(.999), length.out = 20)), | |
c(0,0,dnorm(seq(qnorm(0.95), qnorm(.999), length.out = 20))), col = rgb(1,0,0,alpha = 0.5)) | |
segments(qnorm(0.95), 0, qnorm(0.95), 0.4, lwd = 2) | |
text(qnorm(0.95), 0.3, paste0("z = ", sprintf("%0.2f", qnorm(0.95))), pos = 4, cex = 1.5) | |
dev.print(pdf, file = "ztests.pdf", height = 5, width = 13) | |
dev.off() | |
shell("convert -density 300 ztests.pdf ztest.png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment