##### Demonstration Script #3a ##### MATH322 ##### ##### Power Curves ##### ##### This covers power curves when ##### the functional form is known. ### The Rayleigh Distribution # This distribution is used to model magnitudes of # two-dimensional vectors. This means it is used to # model wind speeds and complex numbers. # # As expected, it is based on the Normal distribution. In # fact, it is defined as the cartesian distance between the # origin and the point whose x- and y-coordinates are Normal # Define X and Y x = rnorm(1e6) y = rnorm(1e6) # Calculate distance r = sqrt(x^2 + y^2) # The standard Rayleigh pdf hist(r) ### The Beta curve for Height example # The Beta curve is known exactly. So, this is just an # example of using R to plot a function. mu = seq(50, 68, length=1e4) beta = 1-pnorm(66.355-mu) plot(mu,beta) ### Power Curve # The Power curve is known exactly here. So, this is # another example of using R to plot a function. PWR = 1-beta plot(mu,PWR) ##### Sample Size # How do we determine the minimum sample size needed to attain # a necessary power level? ## See notes mu0 = 68 # H0 mu = 67.5 # Reality alpha = 0.05 # Selected sig2 = 3 # From trial experiment n = seq(1, 100) # Possible n values # Power function: pwr = pnorm( (mu0-mu)/(sqrt(sig2/n)) + qnorm(alpha) ) # Plot plot(n,pwr) # Which power belongs to which sample size? cbind(n,pwr) # So, if reality is mu = 67.5, then we would need a sample size # of at least 75 to have an 80% chance of determining that the # null hypothesis is not correct.