Chapter 2: #33
mydata <- read.csv("http://whitlockschluter.zoology.ubc.ca/wp-content/data/chapter02/chap02q33BirthMonthADHD.csv")
head(mydata)
## birthMonth diagnosis frequencies
## 1 January ADHD 2219
## 2 January no ADHD 36917
## 3 December ADHD 2870
## 4 December no ADHD 36107
str(mydata)
## 'data.frame': 4 obs. of 3 variables:
## $ birthMonth : Factor w/ 2 levels "December","January": 2 2 1 1
## $ diagnosis : Factor w/ 2 levels "ADHD","no ADHD": 1 2 1 2
## $ frequencies: int 2219 36917 2870 36107
mydataMat <- matrix(mydata$frequencies, byrow = FALSE, nrow = 2)
colnames(mydataMat) <- c("January Birth", "December Birth")
rownames(mydataMat) <- c("ADHD", "no ADHD")
mosaicplot(t(mydataMat),
col = c("burlywood2", "coral"),
sub = "Birth Month",
ylab = "Relative Frequency",
cex.axis = 1.1,
main = "")

Chapter 2: #35
foodData <- read.csv("http://whitlockschluter.zoology.ubc.ca/wp-content/data/chapter02/chap02q35FoodReductionLifespan.csv")
head(foodData)
## sex foodTreatment lifespan
## 1 female reduced 16.5
## 2 female reduced 18.9
## 3 female reduced 22.6
## 4 female reduced 27.8
## 5 female reduced 30.2
## 6 female reduced 30.7
str(foodData)
## 'data.frame': 34 obs. of 3 variables:
## $ sex : Factor w/ 2 levels "female","male": 1 1 1 1 1 1 1 1 1 1 ...
## $ foodTreatment: Factor w/ 2 levels "control","reduced": 2 2 2 2 2 2 2 1 1 1 ...
## $ lifespan : num 16.5 18.9 22.6 27.8 30.2 30.7 35.9 23.7 24.5 24.7 ...
table(foodData$foodTreatment)
##
## control reduced
## 17 17
table(foodData$sex)
##
## female male
## 15 19
par(bty = "l")
boxplot(lifespan ~ foodTreatment*sex,
data = foodData,
col = "lightblue3",
boxwex = 0.5,
whisklty = 1,
outcol = "black",
outcex = 1,
outlty = "blank",
las = 1,
xlab="Diet/Sex Groupings",
ylab = "Lifespan")

- Lifespan varied more greatly between the sexes than between the diet groups.