Below are the solutions to these exercises on Conducting Power Analysis for Experimental Design.

#################### # # # Exercise 1 # # # #################### install.packages('pwr', dependencies = TRUE)

## Error in contrib.url(repos, "source"): trying to use CRAN without setting a mirror

require(pwr)

#################### # # # Exercise 2 # # # #################### pwr.t.test(n = , d = 0.3 , sig.level = 0.05, power = 0.8, type = "two.sample")

## ## Two-sample t test power calculation ## ## n = 175.3847 ## d = 0.3 ## sig.level = 0.05 ## power = 0.8 ## alternative = two.sided ## ## NOTE: n is number in *each* group

#################### # # # Exercise 3 # # # #################### pwr.t.test(n = 50 , d = , sig.level = 0.05, power = 0.8, type = "two.sample")

## ## Two-sample t test power calculation ## ## n = 50 ## d = 0.565858 ## sig.level = 0.05 ## power = 0.8 ## alternative = two.sided ## ## NOTE: n is number in *each* group

#################### # # # Exercise 4 # # # #################### pwr.t.test(n = 50 , d = 0.3 , sig.level = 0.05, power = , type = "two.sample")

## ## Two-sample t test power calculation ## ## n = 50 ## d = 0.3 ## sig.level = 0.05 ## power = 0.3178022 ## alternative = two.sided ## ## NOTE: n is number in *each* group

#################### # # # Exercise 7 # # # #################### # Power analysis for one-way balanced anova pwr.anova.test(k = 6,n = 50,f = 0.2,sig.level = 0.05,)

## ## Balanced one-way analysis of variance power calculation ## ## k = 6 ## n = 50 ## f = 0.2 ## sig.level = 0.05 ## power = 0.7595078 ## ## NOTE: n is number in each group

#################### # # # Exercise 8 # # # #################### # Load PlantGrowth data data("PlantGrowth") # Run an anova anova(lm(weight ~ group, data = PlantGrowth))

## Analysis of Variance Table ## ## Response: weight ## Df Sum Sq Mean Sq F value Pr(>F) ## group 2 3.7663 1.8832 4.8461 0.01591 * ## Residuals 27 10.4921 0.3886 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#Use the PlantGrowth data to calculate effect size 'f' for anova numerator = ((1/3)*(mean(PlantGrowth$weight[PlantGrowth$group=='ctrl'])- mean(PlantGrowth$weight))^2) + ((1/3)*(mean(PlantGrowth$weight[PlantGrowth$group=='trt1'])- mean(PlantGrowth$weight))^2) + ((1/3)*(mean(PlantGrowth$weight[PlantGrowth$group=='trt2'])- mean(PlantGrowth$weight))^2) denominator = 0.3886 # This comes from the anova() command under the Mean Sq coloum for Residuals f = sqrt(numerator/denominator) print(f)

## [1] 0.5683917

#################### # # # Exercise 9 # # # #################### pwr.anova.test(k = 3,n = 10,f = 0.568,sig.level = 0.05,)

## ## Balanced one-way analysis of variance power calculation ## ## k = 3 ## n = 10 ## f = 0.568 ## sig.level = 0.05 ## power = 0.7528697 ## ## NOTE: n is number in each group

#################### # # # Exercise 10 # # # #################### ?pwr

## Leave a Reply