I really need helps to figure out:
Suppose we are testing H0: µ = 5 against H1: µ < 5 for a normal population with σ = 1. A random sample of size n = 9 is available from this population. The z test is used with α = 0.05. The rejection region region for this test is 1.645, x bar is 4.45.
1) On the same graph, use R to plot the sampling distribution of the test statistic when µ = 5 and when µ = 4.2.
2) On your graph, shade and label the area that represents the probability of type I error.
3) On your graph, shade and label the area that represents the probability of type II error.
4) Compute the probability of type II error when µ = 4.2. Provide the appropriate R codes.
I could figure out only 1):
z1 = (4.45 - 5)/(1/sqrt(9))
z1
k1 = seq(from=-1.65, to=+1.65, by=.05)
dens1 = dnorm(k1)
plot(k1, dens1, type="l")
par(new =TRUE)
z2 = (4.45 - 4.2)/(1/sqrt(9))
z2 k2 = seq(from=-.75, to=+0.75, by=.05)
dens2 = dnorm(k2)
p = plot(k2, dens2, type="l", xlab="", ylab="")
Some approximation to the graph (1) is:
curve(dnorm(x,5 ,sqrt(1/9)), xlim=c(0, 14), ylab='', lwd=2, col='blue')
curve(dnorm(x,4.2,sqrt(1/9)), add=T, lwd=2)
curve(dnorm(x,5,1), add=T, col='blue')
curve(dnorm(x,4.2,1), add=T)
legend('topright', c('Samp. dist. for mu=5','Samp. dist. for mu=4.2',
'N(5,1)','N(4.2,1)'),
bty='n', lwd=c(2,2,1,1), col=c(4,1,4,1))