---
# System prepended metadata

title: "BI377 Excercise#1 \nOliver Wen"
tags: [Assignment, BI377]

---

BI377 Excercise#1 
Oliver Wen
===

## Table of Contents

[TOC]

---

## **Problem #1**
Using the ChickWeights dataset, create boxplots showing log10 weights only on the first, tenth, and last days of the experiment.

![](https://hackmd.io/_uploads/Sy_8E_UZs.jpg)

---
```
ChickWeight$log10weight <- log10(ChickWeight$weight)

days1 <- ChickWeight[which(ChickWeight$days
                           == c(0, 10, 21)),]
days2 <- ChickWeight[which(ChickWeight$days
                           == c(21)),]
total <- rbind(days1, days2)

boxplot(total$log10weight ~ total$days, 
        main="Log10weight on Days 0,10,21",
        xlab="Day", 
        ylab="Log10(weight)")

```
---

## **Challenge #1a**
Have the figure display results for each diet separately.
![](https://hackmd.io/_uploads/H1z7sOIZi.jpg)

```
library(ggplot2)
p <- ggplot(total, aes(x=diet, y=weight)) + geom_boxplot()
p

```

---

## **Challenge #1b**
With the figure features above, communicate both the individual values and the distribution of those values to a viewer.

```
summary(total)

one.way <- aov(weight ~ Diet, data = total)

summary(one.way)

p <- ggplot(total, aes(x=Diet, y=weight)) + 
  theme_bw() +  
  geom_violin(colour="black", size=1, trim = FALSE, alpha = 0.75,
              draw_quantiles = 0.5) +  
  geom_jitter(position = position_jitter(width = 0.2, height = 0), 
              colour = "red", size=3, alpha = 0.8) +
  ggtitle("Weights of chicks based on different diets") +
  xlab("Diet Trial") +
  ylab("Chick Weight") 
p
```
![](https://hackmd.io/_uploads/rkKPpOyfi.png)
Min, Median, Mean, and Max of the dataset

![](https://hackmd.io/_uploads/r1ld6dJMj.png)
Anova Analysis of weight in different diet trials

![](https://hackmd.io/_uploads/S10uRuyzi.png)
Violin Distribution graph of different diet trails

There are four different trails of diet conducted on 50 different individuals. The data are roughly normal distributed. The weight of the individuals are recorded every 24 hours. From the graph above, we can see the four different diets conducted. The minimum weight recorded is in the first diet, and the maximum weight recorded is in the thir diet. From the result, the first diet is the most successful one in terms of weight lose and the third diet has the least effect. 

---


## **Problem #2**
Randomly generate two vectors of 100 values each. Plot them against one another and draw a linear trend line through the group of points.
![](https://hackmd.io/_uploads/rJSUkKI-o.jpg)

---

```
b <- runif(n = 100, min = -100, max = 100)
c <- runif(n = 100, min = -100, max = 100)
plot(b, c)
abline(lm(c~b))

```
---

## **Challenge #2a**
Find the slope of the line you’ve drawn above. 

The slope is 0.1628051

```
fit.lm <-lm(c ~ b)
slope <- coef(fit.lm)
slope

```

---

## **Challenge #2b**
Add text to the plot, showing the slope.
![](https://hackmd.io/_uploads/HyzgZtLZo.jpg)


```
fit.lm <-lm(c ~ b)
slope <- coef(fit.lm)
slope
text(7, 4, expression(slope == 0.1628051))

```

###### tags: `Assignment` `BI377`
