# This script generates a plot that shows the alpha and beta propability when comparing two means of normal distributed populations # for more R-scripts: www.random-stuff.de pdf("beta-error.pdf", width=10, height=7) par(bty="n", mar=c(6, 6, 2, 2.5)) x <- seq(-7,4, length=600) y <- dnorm(x, mean=-3, sd=1) x2 <- seq(-7,4, length=600) y2 <- dnorm(x2, mean=0, sd=1) plot(x,y, type="l", ylim=c(0,0.45), xlim=c(-7,4), xlab="deviation from the mean", ylab="density", lwd=2, xaxp=c(-7,4,11), lty="dashed") lines(x2, y=y2, type="l", lwd=2) lines(c(0,0), c(0,0.4)) lines(c(0,0), y=c(-0.009,0.425), lwd=1.5, col="#9E9E9E") text(0, 0.44, labels=expression(mu[0]), lwd=1.5, col="#9E9E9E") lines(c(-3,-3), y=c(-0.009,0.425), lwd=1.5, col="#9E9E9E") text(-3, 0.44, labels=expression(mu[1]), lwd=1.5, col="#9E9E9E") polygon(c(-1.65,x2[1:292],-1.65), y=c(0.00013, y2[1:292], 0.00013), col="#F2F2F2", lwd=1.5) polygon(c(-1.63,x[292:600],-1.63), y=c(0.00013, y[292:600], 0.00013), density=c(5, 20), angle=c(-60, 45), lwd=1.5, lty="dashed") lines(c(-2,-2), y=c(-0.009,0.312), lwd=1.5, col="#9E9E9E") text(-2, 0.33, labels=expression(bar(x)[1]), lwd=1.5, col="#9E9E9E") lines(c(-1.2,-1.2), y=c(-0.009,0.312), lwd=1.5, col="#9E9E9E") text(-1.2, 0.33, labels=expression(bar(x)[2]), lwd=1.5, col="#9E9E9E") lines(c(-1.3,-0.6), y=c(0.04,0.13), lwd=1.5) text(-0.48, 0.14, labels=expression(beta)) lines(c(-1.8,-2.5), y=c(0.04,0.13), lwd=1.5) text(-2.63, 0.14, labels=expression(alpha)) box(which = "inner", lty = "solid") #quartz.save("beta-error.pdf", type="pdf") # for Mac PCs dev.off() print(paste("Plot was saved in:", getwd()))