In: Statistics and Probability
SOLVE USING R. COPY AND PASTE R INPUT AND OUTPUT.
Fifteen turkey hens were randomly assigned to three groups of five. One group was given diet A, the second group diet B, and the third group diet C. We wish to know if there is a difference in the weight of eggs produced by the birds on these diets, and if so, which diet results in the largest eggs. The data are the mean weights of ten eggs from each bird. Check the normality and homogeneity assumptions first to see if you can use ANOVA.
Diet A 124 118 120 127 115
Diet B 98 100 95 102 105
Diet C 116 97 100 89 98
(a) Create a data frame called turkey where the first column is the Diet and the second column is the EggWeights.
(b) Test the normality assumption by running the Shapiro-Wilk Normality Test
shapiro.test(turkey.mod$residuals)
Is the normality assumption violated? Explain.
(c) Test the homogeneity assumption by running the Bartlett
Test
bartlett.test(EggWeights ~ Diet, data=turkey)
Is the homogeneity assumption violated? Explain.
(d) Run an appropriate test (ANOVA or Kruskal-Wallis test, whichever is most appro- priate) to test your appropriate null hypothesis. (Note: make sure you explicitly state what the null hypothesis is before running your anova and make sure that you explicitly state your conclusions with explanation!).
(a)
R output:
Diet EggWeights
1 Diet_A 124
2 Diet_A 118
3 Diet_A 120
4 Diet_A 127
5 Diet_A 115
6 Diet_B 98
7 Diet_B 100
8 Diet_B 95
9 Diet_B 102
10 Diet_B 105
11 Diet_C 116
12 Diet_C 97
13 Diet_C 100
14 Diet_C 89
15 Diet_C 98
(b)
R output:
Shapiro-Wilk normality test
data: residuals
W = 0.93485, p-value = 0.322
Since p-value>0.05, normality assumption holds i.e. residuals are normally distributed.
(c) R code:
Bartlett test of homogeneity of variances
data: EggWeights by Diet
Bartlett's K-squared = 3.733, df = 2, p-value = 0.1547
Since p-value = 0.1547>0.05, assumption of equal variance
holds.
(d)
From (b) and (c), we see that assumption of normality and equal variance hold, so we can use One way ANOVA to test H0.
One way ANOVA:
Df Sum Sq Mean Sq F value Pr(>F)
Diet 2 1442.1 721.1 16.06 0.000405 ***
Residuals 12 538.8 44.9
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
p-value=0.0004<0.05, we reject H0 at 5% level of
significance. Hence there is sufficient evidence to conclude that
there is a significant difference in the weight of eggs produced by
the birds on these diets.
R code:
Diet_A=c(124,118,120,127,115)
Diet_B=c(98,100,95,102,105)
Diet_C=c(116,97,100,89,98)
EggWeights=
c(124,118,120,127,115,98,100,95,102,105,116,97,100,89,98)
Diet=c(rep("Diet_A",5), rep("Diet_B",5), rep("Diet_C",5))
turkey= data.frame(Diet,EggWeights)
turkey#(a)
model=lm(EggWeights ~ Diet, data=turkey)
residuals=resid(model)
shapiro.test(residuals)#(b)
bartlett.test(EggWeights ~ Diet, data=turkey)#(c)
anova_one_way <- aov(EggWeights ~ Diet, data=turkey)
summary(anova_one_way)#(d)