## Power function for Example 2, Section 2.4 notes: # Decision rule is: Reject H0 if T <= 6 possible.ps <- seq(0,1,by=.01) power.for.p <- pbinom(6, size=20, prob=possible.ps) plot(possible.ps, power.for.p, type='l', xlab='p', ylab='power', main="Power Function, Example 2") # Significance level: power.for.p[possible.ps==.5] ######################################################### ## Power function for Example 4(a), Section 2.4 notes: # Decision rule is: Reject H0 if (xbar-5)/sqrt(1/100) > 1.645 # that is, Reject H0 if xbar > 5.1645 possible.mus <- seq(4,6,by=.02) power.for.mu <- pnorm(5.1645, mean=possible.mus, sd=sqrt(1/100), lower=F) plot(possible.mus, power.for.mu, type='l', xlab='mu', ylab='power', main="Power Function, Example 4(a)") # Significance level: power.for.mu[possible.mus==5] ######################################################### ## Power function for Example 4(b), Section 2.4 notes: # Decision rule is: Reject H0 if (xbar-5)/sqrt(1/100) > 1.96 or (xbar-5)/sqrt(1/100) < -1.96 # that is, Reject H0 if xbar > 5.196 or xbar < 4.804 possible.mus <- seq(4,6,by=.02) power.for.mu <- pnorm(5.196, mean=possible.mus, sd=sqrt(1/100), lower=F) + pnorm(4.804, mean=possible.mus, sd=sqrt(1/100), 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==5] ######################################################### ## Power functions for Example 4(a), Section 2.4 notes, FOR SEVERAL VALUES OF n: # Decision rule is: 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)), xlab='mu', ylab='power', main="Power Function, Example 4(a)", type='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) } # Lines are thicker for the larger values of n