install.packages("DescTools", repos = "http://cran.us.r-project.org")
## 
## The downloaded binary packages are in
##  /var/folders/lq/q4b5f6yj44l8z66cd61zxhm40000gn/T//RtmpS4Dzqx/downloaded_packages
data("chickwts")
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(DescTools)
library(tidyverse)
## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6     ✔ purrr   0.3.4
## ✔ tibble  3.1.8     ✔ stringr 1.4.1
## ✔ tidyr   1.2.0     ✔ forcats 0.5.2
## ✔ readr   2.1.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()

Exercise 1

Create a boxplot that shows the association between the type of feed and the six-week weight of the chicks. In, addition, summarize the data by feed groups showing mean and standard deviation of weight gain, and number of chicks in each treatment group.

chickwts %>%
  group_by(., feed) %>%
  summarize(mean.weight = mean(weight), var.weight = var(weight), n=n()) %>%
  arrange(., desc(mean.weight)) %>%
  print.data.frame(., digits=3)
##        feed mean.weight var.weight  n
## 1 sunflower         329       2385 12
## 2    casein         324       4152 12
## 3  meatmeal         277       4212 11
## 4   soybean         246       2930 14
## 5   linseed         219       2729 12
## 6 horsebean         160       1492 10
ggplot(data=chickwts, aes(x=feed, y=weight, fill=feed)) + geom_boxplot() + 
  labs(title="Type of Feed vs. Weight of Six Week Chicks") +
  theme_minimal()

Exercise 1 Response

The boxplot above suggests that feeding Casein and Sunflower to six week chicks resulted in higher recorded weights. Significant outliers in the Sunflower feed resulted in a higher mean weight when compared to the Casien mean weight. Furthermore, the lowest recorded weight was associated with the Horsebean feed.

Exercise 2

Let the parameters μi represent the population mean weight for chicks fed each of the supplements. State the null and alternative hypotheses (no code required, just write down H0 and Ha).

Exercise 2 Response

For this experiment, the null and alternative hypothesis are as follows: H0 = All mean weights are equal Ha = Not all mean weights are equal

Exercise 3

Conduct a hypothesis test to address the question of interest. Use summary(aov()) to compute the F-statistic and p-value. Interpret the p-value, assuming your desired experiment wise error is α=0.05.

summary( weight.model <- aov(weight~feed, data=chickwts))
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## feed         5 231129   46226   15.37 5.94e-10 ***
## Residuals   65 195556    3009                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Exercise 3 Response

From the data above, we know that the p-value lies in a range between [0, 0.001]. Therefore, we reject the null hypothesis that all mean weights are equal.

Exercise 4

Confirm that the model residuals nearly normal (Shapiro-Wilk test). Is the data “normal enough?”

shapiro.test(weight.model$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  weight.model$residuals
## W = 0.98616, p-value = 0.6272

Exercise 4 Response

H0 = The data is distributed normally Ha = The data is not distrubuted normally

Given that the calculated p-value is 0.6272 (greater than 0.05), we fail to reject the null hypothesis. In this test, the data provides sufficient evidence so we can conclude the data is “normal enough”.

Exercise 5

Confirm that the variability across the groups is about equal (Bartlett’s test). Do the groups have roughly the same variances?

bartlett.test(weight ~ feed, data=chickwts)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  weight by feed
## Bartlett's K-squared = 3.2597, df = 5, p-value = 0.66

Exercise 5 Response

H0 = The group variances are roughly the same Ha = The group variances are not roughly the same

Given that the calculated p-value is 0.66 (greater than 0.5), we fail to reject the null hypothesis. In this test, the data provides sufficient evidence so we can conclude that the group variances are roughly the same.

Exercise 6

Complete the analysis using post hoc comparisons. use PostHocTests() with the “bonferroni” option and at least one other to check for consistent post hoc results. The exact p-values given will not match exactly from test to test, but small values should match small values, and large should match large. Are the results consistent?

PostHocTest(weight.model, method = "bonferroni", conf.level = NA, ordered = FALSE)
## 
##   Posthoc multiple comparisons of means : Bonferroni 
## 
## $feed
##           casein  horsebean linseed meatmeal soybean
## horsebean 3.1e-08 -         -       -        -      
## linseed   0.00022 0.22833   -       -        -      
## meatmeal  0.68350 0.00011   0.20218 -        -      
## soybean   0.00998 0.00487   1.00000 1.00000  -      
## sunflower 1.00000 1.2e-08   9.3e-05 0.39653  0.00447
PostHocTest(weight.model, method = "scheffe", conf.level = NA, ordered = FALSE)
## 
##   Posthoc multiple comparisons of means: Scheffe Test 
## 
## $feed
##           casein  horsebean linseed meatmeal soybean
## horsebean 6.1e-07 -         -       -        -      
## linseed   0.00168 0.29942   -       -        -      
## meatmeal  0.53228 0.00094   0.27888 -        -      
## soybean   0.03570 0.02061   0.89365 0.86041  -      
## sunflower 0.99996 2.6e-07   0.00080 0.40644  0.01929

Exercise 6 Response

From both tests, we can conclude that the mean weight for Sunflower and Casein feed differs significantly from the mean weight for Horsebean, Linseed, and Soybean. Likewise, the Horsebean feed differs significantly from Meatmeal and Soybean. Both results are consistent with one another and the data.

Exercise 7

Look at the boxplot and summary statistics from Exercise 1. Which feed supplement gives the greatest average weight gain? Which gives the worst? Is there any other supplement which is comparable to the best one? Use the post hoc test results from Exercise 6 to find treatments that are different (small p-values, <0.05) or similar (large p-values, >0.05).

Exercise 7 Response

The boxplot suggests that Casein feed and Sunflower feed yield the highest weight, and are therefore comparable to one another. Nevertheless, the summary statistics indicates that the Sunflower feed has the greatest average weight gain. From the boxplot, we can conclude that the mean weight for Sunflower feed is higher than the Casein feed due to significant outliers. Additionally, the boxplot suggests that Horsebean feed yields the lowest weight. Finally, from the Posthoc test we can conclude that Sunflower and Casein are found to be the best supplements for weight (p value > 0.05), whereas Horsebean is the worst supplement for weight (p value generally < 0.05)