Packages used in this chapter
The following commands will install these packages
if they are not already installed:
if(!require(pwr)){install.packages("pwr")}
See the Handbook for information on these topics.
Examples
Power analysis for binomial test
###
--------------------------------------------------------------
### Power analysis, binomial test, pea color, p. 43
### --------------------------------------------------------------
P0 = 0.75
P1 = 0.78
H = ES.h(P0,P1) # This calculates
effect size
library(pwr)
pwr.p.test(
h=H,
n=NULL, # NULL tells the function
to
sig.level=0.05, # calculate this
power=0.90, # 1 minus Type II
probability
alternative="two.sided")
n = 2096.953 # Somewhat different than in Handbook
# # #
Power analysis for unpaired t-test
###
--------------------------------------------------------------
### Power analysis, t-test, student height, pp. 43–44
### --------------------------------------------------------------
M1 = 66.6 # Mean for sample 1
M2 = 64.6 # Mean for sample 2
S1 = 4.8 # Std dev for
sample 1
S2 = 3.6 # Std dev for
sample 2
Cohen.d = (M1 - M2)/sqrt(((S1^2) + (S2^2))/2)
library(pwr)
pwr.t.test(
n = NULL, # Observations in
_each_ group
d = Cohen.d,
sig.level = 0.05, # Type I
probability
power = 0.80, # 1 minus Type II
probability
type = "two.sample", # Change
for one- or two-sample
alternative = "two.sided"
)
Two-sample t test power calculation
n = 71.61288
NOTE: n is number in *each* group 71.61288
# # #
Methods are shown in the previous examples.