This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(ggplot2)
data("chickwts")
chickwts
## weight feed
## 1 179 horsebean
## 2 160 horsebean
## 3 136 horsebean
## 4 227 horsebean
## 5 217 horsebean
## 6 168 horsebean
## 7 108 horsebean
## 8 124 horsebean
## 9 143 horsebean
## 10 140 horsebean
## 11 309 linseed
## 12 229 linseed
## 13 181 linseed
## 14 141 linseed
## 15 260 linseed
## 16 203 linseed
## 17 148 linseed
## 18 169 linseed
## 19 213 linseed
## 20 257 linseed
## 21 244 linseed
## 22 271 linseed
## 23 243 soybean
## 24 230 soybean
## 25 248 soybean
## 26 327 soybean
## 27 329 soybean
## 28 250 soybean
## 29 193 soybean
## 30 271 soybean
## 31 316 soybean
## 32 267 soybean
## 33 199 soybean
## 34 171 soybean
## 35 158 soybean
## 36 248 soybean
## 37 423 sunflower
## 38 340 sunflower
## 39 392 sunflower
## 40 339 sunflower
## 41 341 sunflower
## 42 226 sunflower
## 43 320 sunflower
## 44 295 sunflower
## 45 334 sunflower
## 46 322 sunflower
## 47 297 sunflower
## 48 318 sunflower
## 49 325 meatmeal
## 50 257 meatmeal
## 51 303 meatmeal
## 52 315 meatmeal
## 53 380 meatmeal
## 54 153 meatmeal
## 55 263 meatmeal
## 56 242 meatmeal
## 57 206 meatmeal
## 58 344 meatmeal
## 59 258 meatmeal
## 60 368 casein
## 61 390 casein
## 62 379 casein
## 63 260 casein
## 64 404 casein
## 65 318 casein
## 66 352 casein
## 67 359 casein
## 68 216 casein
## 69 222 casein
## 70 283 casein
## 71 332 casein
## a
ggplot (chickwts, aes(x = feed, y = weight, fill = feed )) + geom_boxplot() + labs(
title = "chicken weight based on feed",
x = "feed",
y = "weight"
)+
scale_fill_brewer(palette = "Pastel2")+
theme_minimal()
## the preliminary observations about the feeds is that feeds sunflower and casian have a higher weight because there medians are higher but to prove it it would require further investigation.
##b
##shaperio test
stest <- by(chickwts$weight, chickwts$feed, shapiro.test)
stest
## chickwts$feed: casein
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.91663, p-value = 0.2592
##
## ------------------------------------------------------------
## chickwts$feed: horsebean
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.93758, p-value = 0.5264
##
## ------------------------------------------------------------
## chickwts$feed: linseed
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.96931, p-value = 0.9035
##
## ------------------------------------------------------------
## chickwts$feed: meatmeal
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.97914, p-value = 0.9612
##
## ------------------------------------------------------------
## chickwts$feed: soybean
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.9464, p-value = 0.5064
##
## ------------------------------------------------------------
## chickwts$feed: sunflower
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.92809, p-value = 0.3603
##q-q plot
par(mfrow = c(2, 3))
for (feed_type in unique(chickwts$feed)) {
qqnorm(chickwts$weight[chickwts$feed == feed_type], main = paste("q-q plot:", feed_type))
qqline(chickwts$weight[chickwts$feed == feed_type])}
##c
anova <- aov(weight ~ feed, data = chickwts)
summary(anova)
## 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
## the p value in this case is far lower then the significance value of 0.05. This means we reject the null hypothesis because the p value indicates there is a high significance of difference between the feeds.
##d
tukey <- TukeyHSD(anova)
tukey
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = weight ~ feed, data = chickwts)
##
## $feed
## diff lwr upr p adj
## horsebean-casein -163.383333 -232.346876 -94.41979 0.0000000
## linseed-casein -104.833333 -170.587491 -39.07918 0.0002100
## meatmeal-casein -46.674242 -113.906207 20.55772 0.3324584
## soybean-casein -77.154762 -140.517054 -13.79247 0.0083653
## sunflower-casein 5.333333 -60.420825 71.08749 0.9998902
## linseed-horsebean 58.550000 -10.413543 127.51354 0.1413329
## meatmeal-horsebean 116.709091 46.335105 187.08308 0.0001062
## soybean-horsebean 86.228571 19.541684 152.91546 0.0042167
## sunflower-horsebean 168.716667 99.753124 237.68021 0.0000000
## meatmeal-linseed 58.159091 -9.072873 125.39106 0.1276965
## soybean-linseed 27.678571 -35.683721 91.04086 0.7932853
## sunflower-linseed 110.166667 44.412509 175.92082 0.0000884
## soybean-meatmeal -30.480519 -95.375109 34.41407 0.7391356
## sunflower-meatmeal 52.007576 -15.224388 119.23954 0.2206962
## sunflower-soybean 82.488095 19.125803 145.85039 0.0038845
## The results of the tukey tesy show that there is a large difference in each of the feeds. the type of feed that causes the greatest gtoeth is casein.
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.