Tasks

Task 1

getwd()
## [1] "C:/Users/Caleb/Documents/Civil Engineering degree coursework/Applied Statistical Methods/Labs/Lab 1"

Task 2

Read in DDT data set

ddt <- read.csv("DDT-1.csv")
head(ddt,6)
##   RIVER MILE  SPECIES LENGTH WEIGHT DDT
## 1   FCM    5 CCATFISH   42.5    732  10
## 2   FCM    5 CCATFISH   44.0    795  16
## 3   FCM    5 CCATFISH   41.5    547  23
## 4   FCM    5 CCATFISH   39.0    465  21
## 5   FCM    5 CCATFISH   50.5   1252  50
## 6   FCM    5 CCATFISH   52.0   1255 150

Task 3

Variables

names(ddt)
## [1] "RIVER"   "MILE"    "SPECIES" "LENGTH"  "WEIGHT"  "DDT"

RIVER is qualitative

MILE is quantitative

SPECIES is qualitative

LENGTH is quantitative

WEIGHT is quantitative

DDT is quantitative

table(ddt$SPECIES)
## 
##  CCATFISH    LMBASS SMBUFFALO 
##        96        12        36

There are 3 species in the ddt data set.

with(ddt, ddt[WEIGHT>800 & SPECIES=="LMBASS",])
##     RIVER MILE SPECIES LENGTH WEIGHT DDT
## 141   TRM  345  LMBASS     30    856 2.2
## 144   TRM  345  LMBASS     36   1433 1.9
with(ddt, ddt[RIVER=="SCM" & DDT>4.0,])
##    RIVER MILE  SPECIES LENGTH WEIGHT DDT
## 16   SCM    1 CCATFISH     45    984 9.1
## 17   SCM    1 CCATFISH     43    965 7.8
## 18   SCM    1 CCATFISH     45   1084 4.1

Clicker Questions

Q.1

Find the mean length of fish in the ddt data frame!

summary(ddt$LENGTH)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   17.50   40.50   45.00   42.81   47.50   52.00

The mean length of fish in the ddt data frame is 42.81.

Q.2

What is the standard deviation of the weight of fish in the ddt data frame?

sd(ddt$WEIGHT)
## [1] 376.5461

The standard deviation of the weight of the fish in the ddt data frame is 376.5461.

Q.3

Is this the plot of LENGTH vs WEIGHT from the ddt data frame?

No, it is not. The plot below is the correct plot.

plot(ddt$WEIGHT, ddt$LENGTH)

Q.4

If v=1:20 what is the last value of v/20?

v=1:20
v/20
##  [1] 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75
## [16] 0.80 0.85 0.90 0.95 1.00

The last value of v/20 is 1.00.

Task 4

tab <- table(ddt$RIVER)
tab
## 
## FCM LCM SCM TRM 
##   6   6   6 126
barplot(tab, col=1:4, main="Rivers")

spriv=with(ddt,table(SPECIES,RIVER))
spriv
##            RIVER
## SPECIES     FCM LCM SCM TRM
##   CCATFISH    6   6   6  78
##   LMBASS      0   0   0  12
##   SMBUFFALO   0   0   0  36
barplot(spriv,legend=TRUE,ylim = c(0,200),beside=TRUE,col=1:3)

Task 5

pie(table(ddt$SPECIES), main="Pie Chart of Fish Species")

pie(table(ddt$RIVER), main="Pie Chart of Rivers")

Task 6

boxplot(summary(ddt$DDT),main="Boxplot of DDT" )

boxplot(ddt$WEIGHT,main="Boxplot of Weight" )

boxplot(ddt$LENGTH,main="Boxplot of Length")

Task 7

fishcol=with(ddt,ifelse(SPECIES=="CCATFISH","Red",
                        ifelse(SPECIES=="SMBUFFALO","Blue","Green")))
coplot(LENGTH~WEIGHT|RIVER,data=ddt,col=fishcol, rows=1)

coplot(DDT~WEIGHT|SPECIES,data=ddt, rows=1)

Task 8

library(ggplot2)
b = ggplot(ddt, aes(x = SPECIES, y = WEIGHT))
 b = b + geom_boxplot(aes(fill= RIVER)) + 
  theme(axis.text.x = element_text(angle=0, vjust=0.6)) + 
  labs(title="Caleb Gray")

b

library(ggplot2)
b = ggplot(ddt, aes(x = RIVER, y = LENGTH))
 b = b + geom_violin(aes(fill= SPECIES)) + 
  theme(axis.text.x = element_text(angle=0, vjust=0.6)) + 
  labs(title="Caleb Gray")

b

library(ggplot2)
g = ggplot(ddt, aes(x = WEIGHT, y = LENGTH )) + 
  geom_point(aes( col = SPECIES)) + 
  theme(axis.text.x = element_text(angle=0, vjust=0.6)) + 
  labs(title="Caleb Gray")
g