par(mar = c(4, 1, 1, 1))
tobs <- 1.5; tcrit <- qnorm(0.95); mu1 <- 2.5
curve(dnorm(x), -3.5, 6.5, lwd = 3, col = "steelblue", axes = FALSE,
xlab = "T", ylab = "", ylim = c(0, 0.45))
curve(dnorm(x, mu1), add = TRUE, lwd = 3, col = "firebrick")
shade <- function(from, to, mean, col) {
xs <- seq(from, to, length.out = 200)
polygon(c(xs, rev(xs)), c(dnorm(xs, mean), rep(0, 200)), col = col, border = NA)
}
shade(tcrit, 6.5, mu1, adjustcolor("firebrick", 0.25)) # power
shade(tcrit, 6.5, 0, adjustcolor("steelblue", 0.45)) # alpha
shade(tobs, 6.5, 0, adjustcolor("gray30", 0.35)) # p-value
axis(1, at = c(0, tobs, tcrit, mu1),
labels = c("0", expression(t[obs]), expression(t[alpha]), expression(mu[1])))
abline(v = tcrit, lty = 2); abline(v = tobs, lty = 3)
text(-1.6, 0.30, expression(H[0]*": null distribution"), col = "steelblue")
text(4.3, 0.30, expression(H[1]*": alternative"), col = "firebrick")
text(2.0, 0.055, "p-value", pos = 4, cex = 0.9)
text(tcrit, 0.42, expression(alpha*" = type I error (blue tail)"), pos = 4, cex = 0.9)
text(3.3, 0.16, "power (red tail)", pos = 4, cex = 0.9)