Markdown Author: Jessie Bell, 2023
Libraries Used: none
Answers: green
caffeineData <- read.csv("caffeine.csv")
level_1 <- caffeineData$exer[caffeineData$caff == 'yes']
level_2 <- caffeineData$exer[caffeineData$caff == 'no']
If you are not able to get the data to read into your environment, double check your working directory under Session.
hist(level_1, col="#c77cff")
a <- caffeineData$caff #this pulls out the caffeine column in the caffeineData
b <- caffeineData$exer #this pulls out the exercise column in the caffeineData
stripchart(b~a, vertical=T, col="#00bfc4") #you can also do this the way that is shown in the lab handout.
boxplot(b ~ a, vertical=T, col="#e68613")
# the code for this given in the lab did not work. This problem will not be counted against you.
boxplot(caffeineData$exer ~ caffeineData$caff, col="#ff68a1")
islandData <- read.csv("island.csv")
algalDensity <- islandData$AlgalDensity
face <- islandData$Face
island <- islandData$Island
tapply(algalDensity, face, FUN = "mean") #This is actually increadibly useful! It allows you to create a quick table where you call out the column in the data you would like to summarize, then you call out how to separate/categorize the data, then you tell FUN what function you would like to apply to the data
## North South West
## 47.43733 42.11800 42.23533
tapply(algalDensity, face, FUN="sd") #tells you the SD really quick.
## North South West
## 4.288589 8.727338 8.173183
barplot(tapply(algalDensity, island, FUN = "mean"), col="#8494ff")
finchData <- read.csv("kenyanfinches.csv")
head(finchData)#tells you headers
## species mass beaklength
## 1 WB.SPARW 40 10.6
## 2 WB.SPARW 43 10.8
## 3 WB.SPARW 37 10.9
## 4 WB.SPARW 38 11.3
## 5 WB.SPARW 43 10.9
## 6 WB.SPARW 33 10.1
summary(finchData) #tells you data type, species is listed as character data. This is categorical, mass and beaklength are numerical.
## species mass beaklength
## Length:45 Min. : 6.00 Min. : 6.700
## Class :character 1st Qu.: 8.00 1st Qu.: 7.600
## Mode :character Median :16.00 Median : 8.000
## Mean :20.44 Mean : 8.744
## 3rd Qu.:36.00 3rd Qu.:10.700
## Max. :43.00 Max. :11.400
#you can do this in many ways. I will try to show you two ways.
whitebrow <- subset(finchData, species=="WB.SPARW")
crimson <- subset(finchData, species=="CRU.WAXB")
cutthroat <- subset(finchData, species=="CUTTHROA")
#THE LONG WAY TO DO SUMMARY STATS
whitebrow_mean_mass <- mean(whitebrow$mass, na.rm = F)
whitebrow_mean_beak <- mean(whitebrow$beaklength, na.rm = F)
whitebrow_sd_mass <- sd(whitebrow$mass, na.rm = F)
whitebrow_sd_beak <- sd(whitebrow$beaklength, na.rm = F)
crimson_mean_mass <- mean(crimson$mass, na.rm = F)
crimson_mean_beak <- mean(crimson$beaklength, na.rm = F)
crimson_sd_mass <- sd(crimson$mass, na.rm = F)
crimson_sd_beak <- sd(crimson$beaklength, na.rm = F)
cutthroat_mean_mass <- mean(cutthroat$mass, na.rm = F)
cutthroat_mean_beak <- mean(cutthroat$beaklength, na.rm = F)
cutthroat_sd_mass <- sd(cutthroat$mass, na.rm = F)
cutthroat_sd_beak <- sd(cutthroat$beaklength, na.rm = F)
#THE SHORTER WAY
mean_mass <- tapply(finchData$mass, finchData$species, FUN="mean")
sd_mass <- tapply(finchData$mass, finchData$species, FUN="sd")
cv_mass <- sd_mass/mean_mass #this is the coefficient of variation for finch mass
summarystatstable <- cbind(mean_mass, sd_mass, cv_mass) #bind your tapply data together from above using cbind() function
summarystatstable #print out your table.
## mean_mass sd_mass cv_mass
## CRU.WAXB 7.529412 0.6242643 0.08291010
## CUTTHROA 15.416667 1.2401124 0.08043972
## WB.SPARW 37.937500 3.1084562 0.08193624
hist(whitebrow$mass, breaks = "sturges", main = "Distribution of whitebrow finch mass", xlab = "mass", col="#00a9ff")
hist(crimson$mass, main = "Distribution of crimson finch mass", xlab = "mass", col="#f8766d")
hist(cutthroat$mass, main = "Distribution of cutthroat finch mass", xlab = "mass", col="#aba300")
IQR_whitebrow <- IQR(whitebrow$mass) * 1.5
# the range is on both sides of the median. So the upper range is
median(whitebrow$mass)+IQR_whitebrow #are there datapoints outside of this range? If yes ,its an outlier. If no, no outliers.
## [1] 43.375
# now lets look at teh lower quartile
median(whitebrow$mass)-IQR_whitebrow #are there any data points for whitebrow mass that lay outside of this range? if so, its an outlier!
## [1] 30.625
IQR_cutthroat <- IQR(cutthroat$mass)*1.5
median(cutthroat$mass)+IQR_cutthroat
## [1] 17.5
median(cutthroat$mass)-IQR_cutthroat
## [1] 14.5
# there are 3 values of 7 in the mass column for cutthroat finches. These are all outliers.
boxplot(whitebrow$mass, col="#00a9ff")
boxplot(crimson$mass, col="#f8766d")
boxplot(cutthroat$mass, col="#aba300")