The data can be replicated w/o a spreadsheet using this code

```
treatment <- c("CAROT","CAROT","CAROT","CAROT","CAROT","CAROT","CAROT","CAROT","CAROT","CAROT",
"NO","NO","NO","NO","NO","NO","NO","NO","NO","NO")
PHA <- c(1.511,1.311,1.46,1.352,1.491,1.599,1.653,1.39,1.779,1.721,1.454,1.226,1.198,1.139,1.277,1.49,0.912,1.316,1.234,1.332)
SRBC <- c(2,2,3,4,5,4,8,5,7,4,4,2,3,4,3,0,3,4,2,1)
finches <- data.frame(treatment = treatment,
PHA = PHA,
SRBC = SRBC)
```

In lab we entered the data into excel and loaded the spreadsheet using **read.csv()**

```
# Set the working directoy
setwd("C:/Users/lisanjie2/Desktop/TEACHING/1_STATS_CalU/1_STAT_CalU_2016_by_NLB/Lab/Lab6_review")
#Load the data
finches <- read.csv("finchs.csv")
```

`dim(finches)`

`## [1] 20 4`

`head(finches)`

```
## X treatment PHA SRBC
## 1 1 CAROT 1.511 2
## 2 2 CAROT 1.311 2
## 3 3 CAROT 1.460 3
## 4 4 CAROT 1.352 4
## 5 5 CAROT 1.491 5
## 6 6 CAROT 1.599 4
```

`summary(finches)`

```
## X treatment PHA SRBC
## Min. : 1.00 CAROT:10 Min. :0.912 Min. :0.0
## 1st Qu.: 5.75 NO :10 1st Qu.:1.266 1st Qu.:2.0
## Median :10.50 Median :1.371 Median :3.5
## Mean :10.50 Mean :1.392 Mean :3.5
## 3rd Qu.:15.25 3rd Qu.:1.496 3rd Qu.:4.0
## Max. :20.00 Max. :1.779 Max. :8.0
```

The finch data has TWO columns of numeric response data. One column is for PHA (a measure of cell-mediated immunocompetence) and the 2nd column is for SRBC. Each row is one bird and the columns hold two separate response variables recorded for that bird.

To investigate these data, we work with each column of response data seperately. Its almost as if we have 2 datasets, one of PHA and one of SRBC

These boxplots command have idential structure, just one has “PHA ~” and the other has “SRBC ~”. The first tells R “make a boxplot with the PHA column from the finches dataset”, the 2nd says “make a boxplot with the SRBC column”.

```
# Boxplot of PHA data
boxplot(PHA ~ treatment, data = finches,
main = "PHA data")
```

```
# Boxplot of SRBC data
boxplot(SRBC ~ treatment, data = finches,
main = "SRBC data")
```

We can make a plot w/ both variables, SRBC and PHA on it, using the par() command. The “1,2” means “one row, two columns”

```
par(mfrow = c(1,2))
#First boxplot for PHA
boxplot(PHA ~ treatment,
data = finches,
main = "PHA data")
#2nd boxplot for SRBC
boxplot(SRBC ~ treatment,
data = finches,
main = "SRBC data")
```

We can calcualte means, sd etc for each column seperately using the tapply() command. We have to repeat it seperately for each column.

```
#t-apply on PHA
PHA.mean <- tapply(finches$PHA,
finches$treatment,
FUN = mean)
#t-apply on SRBC
SRBC.mean <- tapply(finches$SRBC,
finches$treatment,
FUN = mean)
```

Hust change “FUN = mean” to “FUN = sd” AND re-name the objects where the data are being saved

```
#t-apply on PHA
PHA.sd<- tapply(finches$PHA,
finches$treatment,
FUN = sd)
#t-apply on SRBC
SRBC.sd <- tapply(finches$SRBC,
finches$treatment,
FUN = sd)
```