Power calculation
If you find the usual formulae confusing, here is a power calculation done from 'first-principles'.
The following code gives the power of a 2-tailed Z test, given a known treatment effect (muA - mu0):
Gave:
Note:
- We have used arbitrary values of these parameters, except mu0 is zero for most tests.
- When muA=mu0 the 'power' is 0.05
- For a 1-tailed test (where alpha=0.05) the critical value is either:
- cvL=qnorm(alpha, mu0, SE0) # Lower quantile
OR:
- cvU=qnorm(1-alpha, mu0, SE0) # Upper quantile
And the power is either:
- pnorm(cvL, muA, SEA)
OR:
1-pnorm(cvU, muA, SEA)
- Obviously this code contains all sorts of 'redundant' calculations, which can be removed by algebraic rearrangement - but that tends to obscure the inner workings. Because the workings of our code are explicit it is much easier to modify, for instance if you wanted to use it for a test statistic whose distribution is 'known' but not normal.
Given a few moments thought, you should also be able to modify this code so it calculates the power of a Z-test when your treatment changes the variance of your Z-statistic (SE0 ≠ SEA).
|