How to best display graphically type II (beta) error, power and sample size?

I’m asked to write an introduction to statistics and I’m struggling how to graphically show the way p-value and power relate. I’ve come up with this graph:

Two Gauss curves interacting

My question: Is there a better way of displaying this?

Here is my R code

x <- seq(-4, 4, length=1000)
hx <- dnorm(x, mean=0, sd=1)

plot(x, hx, type="n", xlim=c(-4, 8), ylim=c(0, 0.5), 
ylab = "",
xlab = "",
main= expression(paste("Type II (", beta, ") error")), axes=FALSE)
axis(1, at = c(-qnorm(.025), 0, -4), 
     labels = expression("p-value", 0, -infinity ))

shift = qnorm(1-0.025, mean=0, sd=1)*1.7
xfit2 <- x + shift
yfit2 <- dnorm(xfit2, mean=shift, sd=1)

# Print null hypothesis area
col_null = "#DDDDDD"
polygon(c(min(x), x,max(x)), c(0,hx,0), col=col_null)
lines(x, hx, lwd=2)

# The alternative hypothesis area

## The red - underpowered area
lb <- min(xfit2)
ub <- round(qnorm(.975),2)
col1 = "#CC2222"

i <- xfit2 >= lb & xfit2 <= ub
polygon(c(lb,xfit2[i],ub), c(0,yfit2[i],0), col=col1)

## The green area where the power is
col2 = "#22CC22"
i <- xfit2 >= ub
polygon(c(ub,xfit2[i],max(xfit2)), c(0,yfit2[i],0), col=col2)

# Outline the alternative hypothesis
lines(xfit2, yfit2, lwd=2)

axis(1, at = (c(ub, max(xfit2))), labels=c("", expression(infinity)), 
    col=col2, lwd=1, lwd.tick=FALSE)


legend("topright", inset=.05, title="Color",
   c("Null hypoteses","Type II error", "True"), fill=c(col_null, col1, col2), horiz=FALSE)

abline(v=ub, lwd=2, col="#000088", lty="dashed")

arrows(ub, 0.45, ub+1, 0.45, lwd=3, col="#008800")
arrows(ub, 0.45, ub-1, 0.45, lwd=3, col="#880000")

Update


Thank you for the terrific answers. I’ve changed some of the code:

# Print null hypothesis area
col_null = "#AAAAAA"
polygon(c(min(x), x,max(x)), c(0,hx,0), col=col_null, lwd=2, density=c(10, 40), angle=-45, border=0)
lines(x, hx, lwd=2, lty="dashed", col=col_null)

...
legend("topright", inset=.015, title="Color",
   c("Null hypoteses","Type II error", "True"), fill=c(col_null, col1, col2), 
       angle=-45,
       density=c(20, 1000, 1000), horiz=FALSE)

I like the dashed, slightly vague picture of the null hypothesis because it signals that it’s not truly there. I’ve thought about the transparency and adding the alfa but I worry about getting too much information into one picture and have therefore chosen not to.

enter image description here

The limitations of printed articles doesn’t allow me to do let the readers experiment. I’ve chosen the @Greg Snow’s reply with TeachingDemos as my answer since I love the idea with the two errors not overlapping.

Answer

I have played around with similar plots and found that it works better when the 2 curves don’t block each other, but are rather vertically offset (but still on the same x-axis). This makes it clear that one of the curves represents the null hypothesis and the other represents a given value for the mean under the alternative hypothesis. The power.examp function in the TeachingDemos package for R will create these plots and the run.power.examp function (same package) allows you to interactively change the arguments and update the plot.

Attribution
Source : Link , Question Author : Max Gordon , Answer Author : Greg Snow

Leave a Comment