##### Calculating Power Functions: ## Example 1 from Section 10.4: Test Ho: mu = 500 vs. Ha: mu > 500 # Rejection rule was: Reject H0 if (ybar-500)/(97.4/sqrt(80)) > 1.645 # that is, Reject H0 if ybar > 517.91 possible.mus <- seq(475,575,by=.2) power.for.mu <- pnorm(517.91, mean=possible.mus, sd=97.4/sqrt(80), lower=F) plot(possible.mus, power.for.mu, type='l', xlab='mu', ylab='power', main="Power Function, Example 1") # Significance level: power.for.mu[possible.mus==500] ################################################################################# ## Example 1 (altered) from Section 10.4: Test Ho: mu = 500 vs. Ha: mu =/= 500 # Rejection rule is: Reject H0 if (ybar-500)/(97.4/sqrt(80)) > 1.96 or (ybar-500)/(97.4/sqrt(80)) < -1.96 # that is, Reject H0 if xbar > 521.34 or xbar < 478.66 possible.mus <- seq(440,560,by=.2) power.for.mu <- pnorm(521.34, mean=possible.mus, sd=97.4/sqrt(80), lower=F) + pnorm(478.66, mean=possible.mus, sd=97.4/sqrt(80), lower=T) plot(possible.mus, power.for.mu, type='l', xlab='mu', ylab='power', main="Power Function, Example 4(b)") # Significance level: power.for.mu[possible.mus==500] ################################################################################# # Note the effect of the sample size on the power functions: ## Power functions for an example z-test, FOR SEVERAL VALUES OF n: # Suppose we reject H0 if (xbar-5)/sqrt(1/n) > 1.645 # that is, Reject H0 if xbar > 1.645*sqrt(1/n) + 5 possible.mus <- seq(4.5,5.5,by=.02) plot(possible.mus, seq(0,1,length=length(possible.mus)), type='n', xlab='mu', ylab='power', main="Power Functions for varying n") for (n in c(5,10,20,50,100)){ power.for.mu <- pnorm(1.645*sqrt(1/n) + 5, mean=possible.mus, sd=sqrt(1/n), lower=F) lines(possible.mus, power.for.mu, lwd=n/10) } abline(h=.05,lty=3) # Lines are thicker for the larger values of n