Site vs. Count ANOVA
rm(list=ls())
setwd("C:/Users/April Mae Tabonda/Documents/MS Marine Science/Biostat/PLP/RMDs/PLP_11 Project")
getwd()
## [1] "C:/Users/April Mae Tabonda/Documents/MS Marine Science/Biostat/PLP/RMDs/PLP_11 Project"
sample.data<-read.csv("count.csv", header=TRUE, sep=";")
str(sample.data)
## 'data.frame': 213 obs. of 6 variables:
## $ ï..DATE: Factor w/ 5 levels "06/06/2017","07/06/2017",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ SITE : Factor w/ 8 levels "Balingasay","Cangaluyan",..: 8 8 8 8 8 8 8 8 8 8 ...
## $ DEPTH : Factor w/ 2 levels "Deep","Shallow": 1 1 1 1 1 1 1 1 2 2 ...
## $ METER : int 4 18 50 86 92 96 98 100 10 12 ...
## $ SPECIES: Factor w/ 2 levels "Drupella coralopila",..: 2 2 1 1 1 1 2 2 2 2 ...
## $ COUNT : int 2 1 2 1 3 4 1 1 2 4 ...
head(sample.data)
## ï..DATE SITE DEPTH METER SPECIES COUNT
## 1 06/06/2017 RDG Deep 4 Drupella cornus 2
## 2 06/06/2017 RDG Deep 18 Drupella cornus 1
## 3 06/06/2017 RDG Deep 50 Drupella coralopila 2
## 4 06/06/2017 RDG Deep 86 Drupella coralopila 1
## 5 06/06/2017 RDG Deep 92 Drupella coralopila 3
## 6 06/06/2017 RDG Deep 96 Drupella coralopila 4
tail(sample.data)
## ï..DATE SITE DEPTH METER SPECIES COUNT
## 208 12/07/2017 Lucero Shallow 92 Drupella cornus 2
## 209 12/07/2017 Lucero Shallow 94 Drupella cornus 2
## 210 12/07/2017 Lucero Shallow 94 Drupella coralopila 2
## 211 12/07/2017 Lucero Shallow 96 Drupella coralopila 1
## 212 12/07/2017 Lucero Shallow 98 Drupella coralopila 3
## 213 12/07/2017 Lucero Shallow 98 Drupella cornus 1
sample.data$SITE<-factor(sample.data$SITE, levels=c('RDG','Malwest','Cangaluyan','Caniogan','Cory','Magsaysay','Balingasay','Lucero'),ordered=F)
sample.data
## ï..DATE SITE DEPTH METER SPECIES COUNT
## 1 06/06/2017 RDG Deep 4 Drupella cornus 2
## 2 06/06/2017 RDG Deep 18 Drupella cornus 1
## 3 06/06/2017 RDG Deep 50 Drupella coralopila 2
## 4 06/06/2017 RDG Deep 86 Drupella coralopila 1
## 5 06/06/2017 RDG Deep 92 Drupella coralopila 3
## 6 06/06/2017 RDG Deep 96 Drupella coralopila 4
## 7 06/06/2017 RDG Deep 98 Drupella cornus 1
## 8 06/06/2017 RDG Deep 100 Drupella cornus 1
## 9 06/06/2017 RDG Shallow 10 Drupella cornus 2
## 10 06/06/2017 RDG Shallow 12 Drupella cornus 4
## 11 06/06/2017 RDG Shallow 14 Drupella cornus 2
## 12 06/06/2017 RDG Shallow 18 Drupella cornus 2
## 13 06/06/2017 RDG Shallow 20 Drupella cornus 2
## 14 06/06/2017 RDG Shallow 30 Drupella cornus 8
## 15 06/06/2017 RDG Shallow 32 Drupella cornus 3
## 16 06/06/2017 RDG Shallow 40 Drupella cornus 5
## 17 06/06/2017 RDG Shallow 48 Drupella cornus 2
## 18 06/06/2017 RDG Shallow 70 Drupella cornus 3
## 19 06/06/2017 RDG Shallow 82 Drupella coralopila 5
## 20 06/06/2017 RDG Shallow 86 Drupella coralopila 2
## 21 06/06/2017 Malwest Deep 8 Drupella cornus 2
## 22 06/06/2017 Malwest Deep 18 Drupella coralopila 1
## 23 06/06/2017 Malwest Deep 44 Drupella coralopila 3
## 24 06/06/2017 Malwest Deep 44 Drupella cornus 1
## 25 06/06/2017 Malwest Deep 46 Drupella coralopila 4
## 26 06/06/2017 Malwest Deep 56 Drupella coralopila 3
## 27 06/06/2017 Malwest Deep 58 Drupella cornus 2
## 28 06/06/2017 Malwest Shallow 8 Drupella coralopila 3
## 29 06/06/2017 Malwest Shallow 34 Drupella coralopila 10
## 30 06/06/2017 Malwest Shallow 34 Drupella cornus 1
## 31 06/06/2017 Malwest Shallow 66 Drupella coralopila 1
## 32 07/06/2017 Cangaluyan Deep 32 Drupella cornus 1
## 33 07/06/2017 Cangaluyan Deep 60 Drupella cornus 1
## 34 07/06/2017 Cangaluyan Shallow 92 Drupella cornus 1
## 35 07/06/2017 Cangaluyan Shallow 96 Drupella cornus 1
## 36 07/06/2017 Cory Deep 24 Drupella cornus 1
## 37 07/06/2017 Cory Deep 34 Drupella cornus 1
## 38 07/06/2017 Cory Deep 70 Drupella cornus 1
## 39 07/06/2017 Cory Deep 90 Drupella cornus 2
## 40 07/06/2017 Cory Deep 94 Drupella cornus 6
## 41 07/06/2017 Cory Deep 99 Drupella cornus 1
## 42 07/06/2017 Cory Shallow 42 Drupella cornus 1
## 43 07/06/2017 Cory Shallow 78 Drupella cornus 1
## 44 08/06/2017 Magsaysay Deep 10 Drupella cornus 3
## 45 08/06/2017 Magsaysay Deep 18 Drupella cornus 4
## 46 08/06/2017 Magsaysay Deep 20 Drupella cornus 7
## 47 08/06/2017 Magsaysay Deep 29 Drupella cornus 4
## 48 08/06/2017 Magsaysay Deep 38 Drupella cornus 1
## 49 08/06/2017 Magsaysay Deep 48 Drupella cornus 3
## 50 08/06/2017 Magsaysay Deep 54 Drupella cornus 1
## 51 08/06/2017 Magsaysay Deep 75 Drupella cornus 2
## 52 08/06/2017 Magsaysay Shallow 6 Drupella cornus 5
## 53 08/06/2017 Magsaysay Shallow 10 Drupella cornus 3
## 54 08/06/2017 Magsaysay Shallow 12 Drupella cornus 7
## 55 08/06/2017 Magsaysay Shallow 15 Drupella cornus 8
## 56 08/06/2017 Magsaysay Shallow 17 Drupella cornus 7
## 57 08/06/2017 Magsaysay Shallow 21 Drupella cornus 13
## 58 08/06/2017 Magsaysay Shallow 23 Drupella cornus 1
## 59 08/06/2017 Magsaysay Shallow 32 Drupella cornus 1
## 60 08/06/2017 Magsaysay Shallow 45 Drupella cornus 1
## 61 08/06/2017 Magsaysay Shallow 45 Drupella coralopila 2
## 62 08/06/2017 Magsaysay Shallow 50 Drupella cornus 2
## 63 08/06/2017 Magsaysay Shallow 52 Drupella cornus 2
## 64 08/06/2017 Magsaysay Shallow 54 Drupella cornus 3
## 65 08/06/2017 Magsaysay Shallow 58 Drupella cornus 2
## 66 08/06/2017 Magsaysay Shallow 65 Drupella cornus 3
## 67 08/06/2017 Magsaysay Shallow 68 Drupella cornus 1
## 68 08/06/2017 Magsaysay Shallow 77 Drupella cornus 1
## 69 08/06/2017 Magsaysay Shallow 79 Drupella cornus 1
## 70 08/06/2017 Caniogan Deep 70 Drupella cornus 1
## 71 08/06/2017 Caniogan Shallow 8 Drupella coralopila 3
## 72 08/06/2017 Caniogan Shallow 34 Drupella cornus 1
## 73 08/06/2017 Caniogan Shallow 34 Drupella coralopila 1
## 74 08/06/2017 Caniogan Shallow 56 Drupella cornus 19
## 75 08/06/2017 Caniogan Shallow 56 Drupella coralopila 1
## 76 08/06/2017 Caniogan Shallow 68 Drupella cornus 2
## 77 08/06/2017 Caniogan Shallow 88 Drupella cornus 23
## 78 08/06/2017 Caniogan Shallow 94 Drupella cornus 2
## 79 10/07/2017 Balingasay Deep 10 Drupella coralopila 16
## 80 10/07/2017 Balingasay Deep 12 Drupella cornus 1
## 81 10/07/2017 Balingasay Deep 14 Drupella cornus 2
## 82 10/07/2017 Balingasay Deep 18 Drupella cornus 3
## 83 10/07/2017 Balingasay Deep 20 Drupella cornus 1
## 84 10/07/2017 Balingasay Deep 22 Drupella coralopila 4
## 85 10/07/2017 Balingasay Deep 22 Drupella cornus 2
## 86 10/07/2017 Balingasay Deep 30 Drupella coralopila 8
## 87 10/07/2017 Balingasay Deep 34 Drupella cornus 2
## 88 10/07/2017 Balingasay Deep 40 Drupella cornus 1
## 89 10/07/2017 Balingasay Deep 40 Drupella coralopila 1
## 90 10/07/2017 Balingasay Deep 50 Drupella coralopila 24
## 91 10/07/2017 Balingasay Deep 62 Drupella coralopila 3
## 92 10/07/2017 Balingasay Deep 72 Drupella cornus 3
## 93 10/07/2017 Balingasay Deep 78 Drupella cornus 1
## 94 10/07/2017 Balingasay Deep 86 Drupella cornus 4
## 95 10/07/2017 Balingasay Deep 86 Drupella coralopila 2
## 96 10/07/2017 Balingasay Deep 88 Drupella coralopila 13
## 97 10/07/2017 Balingasay Deep 92 Drupella coralopila 1
## 98 10/07/2017 Balingasay Deep 94 Drupella cornus 1
## 99 10/07/2017 Balingasay Deep 96 Drupella cornus 2
## 100 10/07/2017 Balingasay Deep 98 Drupella cornus 2
## 101 10/07/2017 Balingasay Shallow 4 Drupella cornus 5
## 102 10/07/2017 Balingasay Shallow 6 Drupella cornus 1
## 103 10/07/2017 Balingasay Shallow 8 Drupella cornus 1
## 104 10/07/2017 Balingasay Shallow 12 Drupella cornus 1
## 105 10/07/2017 Balingasay Shallow 12 Drupella coralopila 4
## 106 10/07/2017 Balingasay Shallow 18 Drupella coralopila 1
## 107 10/07/2017 Balingasay Shallow 20 Drupella coralopila 2
## 108 10/07/2017 Balingasay Shallow 20 Drupella cornus 3
## 109 10/07/2017 Balingasay Shallow 30 Drupella cornus 38
## 110 10/07/2017 Balingasay Shallow 30 Drupella coralopila 9
## 111 10/07/2017 Balingasay Shallow 44 Drupella cornus 3
## 112 10/07/2017 Balingasay Shallow 48 Drupella cornus 5
## 113 10/07/2017 Balingasay Shallow 50 Drupella cornus 7
## 114 10/07/2017 Balingasay Shallow 50 Drupella coralopila 2
## 115 10/07/2017 Balingasay Shallow 62 Drupella cornus 1
## 116 10/07/2017 Balingasay Shallow 66 Drupella cornus 1
## 117 10/07/2017 Balingasay Shallow 72 Drupella cornus 3
## 118 10/07/2017 Balingasay Shallow 74 Drupella coralopila 3
## 119 10/07/2017 Balingasay Shallow 78 Drupella cornus 3
## 120 10/07/2017 Balingasay Shallow 78 Drupella coralopila 3
## 121 10/07/2017 Balingasay Shallow 82 Drupella cornus 5
## 122 10/07/2017 Balingasay Shallow 84 Drupella coralopila 14
## 123 10/07/2017 Balingasay Shallow 86 Drupella coralopila 8
## 124 10/07/2017 Balingasay Shallow 92 Drupella coralopila 4
## 125 10/07/2017 Balingasay Shallow 94 Drupella cornus 2
## 126 10/07/2017 Balingasay Shallow 96 Drupella cornus 1
## 127 12/07/2017 Lucero Deep 4 Drupella coralopila 7
## 128 12/07/2017 Lucero Deep 12 Drupella cornus 1
## 129 12/07/2017 Lucero Deep 14 Drupella cornus 1
## 130 12/07/2017 Lucero Deep 16 Drupella coralopila 2
## 131 12/07/2017 Lucero Deep 20 Drupella coralopila 2
## 132 12/07/2017 Lucero Deep 22 Drupella cornus 2
## 133 12/07/2017 Lucero Deep 26 Drupella cornus 1
## 134 12/07/2017 Lucero Deep 30 Drupella cornus 1
## 135 12/07/2017 Lucero Deep 32 Drupella coralopila 3
## 136 12/07/2017 Lucero Deep 34 Drupella cornus 10
## 137 12/07/2017 Lucero Deep 44 Drupella cornus 1
## 138 12/07/2017 Lucero Deep 48 Drupella cornus 2
## 139 12/07/2017 Lucero Deep 50 Drupella cornus 1
## 140 12/07/2017 Lucero Deep 54 Drupella cornus 1
## 141 12/07/2017 Lucero Deep 54 Drupella coralopila 1
## 142 12/07/2017 Lucero Deep 62 Drupella coralopila 1
## 143 12/07/2017 Lucero Deep 64 Drupella cornus 2
## 144 12/07/2017 Lucero Deep 68 Drupella cornus 5
## 145 12/07/2017 Lucero Deep 72 Drupella coralopila 2
## 146 12/07/2017 Lucero Deep 76 Drupella coralopila 11
## 147 12/07/2017 Lucero Deep 76 Drupella cornus 1
## 148 12/07/2017 Lucero Deep 78 Drupella coralopila 5
## 149 12/07/2017 Lucero Deep 88 Drupella cornus 2
## 150 12/07/2017 Lucero Deep 90 Drupella cornus 1
## 151 12/07/2017 Lucero Deep 90 Drupella coralopila 3
## 152 12/07/2017 Lucero Deep 96 Drupella cornus 5
## 153 12/07/2017 Lucero Shallow 4 Drupella cornus 5
## 154 12/07/2017 Lucero Shallow 6 Drupella cornus 4
## 155 12/07/2017 Lucero Shallow 8 Drupella cornus 4
## 156 12/07/2017 Lucero Shallow 10 Drupella cornus 5
## 157 12/07/2017 Lucero Shallow 12 Drupella coralopila 3
## 158 12/07/2017 Lucero Shallow 14 Drupella coralopila 3
## 159 12/07/2017 Lucero Shallow 14 Drupella cornus 1
## 160 12/07/2017 Lucero Shallow 16 Drupella coralopila 2
## 161 12/07/2017 Lucero Shallow 18 Drupella coralopila 5
## 162 12/07/2017 Lucero Shallow 18 Drupella cornus 4
## 163 12/07/2017 Lucero Shallow 20 Drupella cornus 1
## 164 12/07/2017 Lucero Shallow 20 Drupella coralopila 2
## 165 12/07/2017 Lucero Shallow 22 Drupella coralopila 3
## 166 12/07/2017 Lucero Shallow 22 Drupella cornus 1
## 167 12/07/2017 Lucero Shallow 24 Drupella coralopila 5
## 168 12/07/2017 Lucero Shallow 26 Drupella coralopila 9
## 169 12/07/2017 Lucero Shallow 26 Drupella cornus 5
## 170 12/07/2017 Lucero Shallow 28 Drupella cornus 2
## 171 12/07/2017 Lucero Shallow 30 Drupella cornus 3
## 172 12/07/2017 Lucero Shallow 30 Drupella coralopila 1
## 173 12/07/2017 Lucero Shallow 32 Drupella coralopila 7
## 174 12/07/2017 Lucero Shallow 32 Drupella cornus 1
## 175 12/07/2017 Lucero Shallow 34 Drupella cornus 3
## 176 12/07/2017 Lucero Shallow 34 Drupella coralopila 9
## 177 12/07/2017 Lucero Shallow 36 Drupella coralopila 4
## 178 12/07/2017 Lucero Shallow 36 Drupella cornus 1
## 179 12/07/2017 Lucero Shallow 38 Drupella coralopila 3
## 180 12/07/2017 Lucero Shallow 42 Drupella coralopila 4
## 181 12/07/2017 Lucero Shallow 44 Drupella coralopila 6
## 182 12/07/2017 Lucero Shallow 46 Drupella cornus 1
## 183 12/07/2017 Lucero Shallow 48 Drupella cornus 1
## 184 12/07/2017 Lucero Shallow 48 Drupella coralopila 4
## 185 12/07/2017 Lucero Shallow 50 Drupella cornus 1
## 186 12/07/2017 Lucero Shallow 52 Drupella cornus 1
## 187 12/07/2017 Lucero Shallow 54 Drupella cornus 3
## 188 12/07/2017 Lucero Shallow 56 Drupella cornus 1
## 189 12/07/2017 Lucero Shallow 60 Drupella cornus 1
## 190 12/07/2017 Lucero Shallow 62 Drupella cornus 4
## 191 12/07/2017 Lucero Shallow 62 Drupella coralopila 7
## 192 12/07/2017 Lucero Shallow 64 Drupella coralopila 6
## 193 12/07/2017 Lucero Shallow 64 Drupella cornus 2
## 194 12/07/2017 Lucero Shallow 66 Drupella coralopila 17
## 195 12/07/2017 Lucero Shallow 66 Drupella cornus 6
## 196 12/07/2017 Lucero Shallow 68 Drupella cornus 2
## 197 12/07/2017 Lucero Shallow 72 Drupella cornus 1
## 198 12/07/2017 Lucero Shallow 72 Drupella coralopila 1
## 199 12/07/2017 Lucero Shallow 74 Drupella coralopila 2
## 200 12/07/2017 Lucero Shallow 76 Drupella coralopila 4
## 201 12/07/2017 Lucero Shallow 78 Drupella coralopila 5
## 202 12/07/2017 Lucero Shallow 78 Drupella cornus 4
## 203 12/07/2017 Lucero Shallow 82 Drupella cornus 2
## 204 12/07/2017 Lucero Shallow 82 Drupella coralopila 4
## 205 12/07/2017 Lucero Shallow 84 Drupella cornus 2
## 206 12/07/2017 Lucero Shallow 88 Drupella cornus 1
## 207 12/07/2017 Lucero Shallow 88 Drupella coralopila 8
## 208 12/07/2017 Lucero Shallow 92 Drupella cornus 2
## 209 12/07/2017 Lucero Shallow 94 Drupella cornus 2
## 210 12/07/2017 Lucero Shallow 94 Drupella coralopila 2
## 211 12/07/2017 Lucero Shallow 96 Drupella coralopila 1
## 212 12/07/2017 Lucero Shallow 98 Drupella coralopila 3
## 213 12/07/2017 Lucero Shallow 98 Drupella cornus 1
boxplot(COUNT~SITE, data=sample.data)

library(ggplot2)
site.bp<-ggplot(sample.data,
aes(y=COUNT, x=SITE, fill=SITE)) +
geom_boxplot()
site.bp

site.bp + ggtitle("Drupella abundance per site")

library(ggplot2)
site.bp<-ggplot(sample.data,
aes(y=COUNT, x=DEPTH, fill=SITE)) +
geom_boxplot()
site.bp

plot(tapply(sample.data$COUNT, sample.data$SITE,mean),
+tapply(sample.data$COUNT, sample.data$SITE,var))

sample.data.aov<-aov(COUNT~SITE, data=sample.data)
plot(sample.data.aov)




anova(sample.data.aov)
## Analysis of Variance Table
##
## Response: COUNT
## Df Sum Sq Mean Sq F value Pr(>F)
## SITE 7 195.6 27.939 1.5457 0.1536
## Residuals 205 3705.3 18.075
pacman::p_load(multcomp)
fit1<-summary(glht(sample.data.aov,linfct=mcp(SITE="Tukey")))
## Warning in RET$pfunction("adjusted", ...): Completion with error > abseps
## Warning in RET$pfunction("adjusted", ...): Completion with error > abseps
fit1
##
## Simultaneous Tests for General Linear Hypotheses
##
## Multiple Comparisons of Means: Tukey Contrasts
##
##
## Fit: aov(formula = COUNT ~ SITE, data = sample.data)
##
## Linear Hypotheses:
## Estimate Std. Error t value Pr(>|t|)
## Malwest - RDG == 0 0.06818 1.59590 0.043 1.000
## Cangaluyan - RDG == 0 -1.75000 2.32861 -0.752 0.994
## Caniogan - RDG == 0 3.13889 1.70647 1.839 0.560
## Cory - RDG == 0 -1.00000 1.77851 -0.562 0.999
## Magsaysay - RDG == 0 0.63462 1.26449 0.502 1.000
## Balingasay - RDG == 0 1.97917 1.13150 1.749 0.622
## Lucero - RDG == 0 0.49138 1.05428 0.466 1.000
## Cangaluyan - Malwest == 0 -1.81818 2.48231 -0.732 0.995
## Caniogan - Malwest == 0 3.07071 1.91088 1.607 0.717
## Cory - Malwest == 0 -1.06818 1.97548 -0.541 0.999
## Magsaysay - Malwest == 0 0.56643 1.52917 0.370 1.000
## Balingasay - Malwest == 0 1.91098 1.42117 1.345 0.863
## Lucero - Malwest == 0 0.42320 1.36049 0.311 1.000
## Caniogan - Cangaluyan == 0 4.88889 2.55480 1.914 0.509
## Cory - Cangaluyan == 0 0.75000 2.60347 0.288 1.000
## Magsaysay - Cangaluyan == 0 2.38462 2.28339 1.044 0.961
## Balingasay - Cangaluyan == 0 3.72917 2.21252 1.685 0.666
## Lucero - Cangaluyan == 0 2.24138 2.17404 1.031 0.963
## Cory - Caniogan == 0 -4.13889 2.06583 -2.003 0.448
## Magsaysay - Caniogan == 0 -2.50427 1.64423 -1.523 0.769
## Balingasay - Caniogan == 0 -1.15972 1.54430 -0.751 0.994
## Lucero - Caniogan == 0 -2.64751 1.48865 -1.778 0.602
## Magsaysay - Cory == 0 1.63462 1.71888 0.951 0.977
## Balingasay - Cory == 0 2.97917 1.62355 1.835 0.563
## Lucero - Cory == 0 1.49138 1.57070 0.949 0.977
## Balingasay - Magsaysay == 0 1.34455 1.03525 1.299 0.883
## Lucero - Magsaysay == 0 -0.14324 0.95023 -0.151 1.000
## Lucero - Balingasay == 0 -1.48779 0.76441 -1.946 0.486
## (Adjusted p values reported -- single-step method)
fit2<-aov(lm(COUNT~SITE, data=sample.data))
tukeyfit3<-TukeyHSD(fit2)
plot(tukeyfit3,las=1,col="red")

pacman::p_load(agricolae)
fit4<-aov(COUNT~SITE, data=sample.data)
HSD.test(fit4,"SITE")
outfit4<-HSD.test(fit4, "SITE", group=TRUE)
outfit4
## $statistics
## MSerror Df Mean CV
## 18.07483 205 3.539906 120.1006
##
## $parameters
## test name.t ntr StudentizedRange alpha
## Tukey SITE 8 4.331046 0.05
##
## $means
## COUNT std r Min Max Q25 Q50 Q75
## Balingasay 4.729167 6.677175 48 1 38 1 3.0 4.25
## Cangaluyan 1.000000 0.000000 4 1 1 1 1.0 1.00
## Caniogan 5.888889 8.652232 9 1 23 1 2.0 3.00
## Cory 1.750000 1.752549 8 1 6 1 1.0 1.25
## Lucero 3.241379 2.753288 87 1 17 1 2.0 4.00
## Magsaysay 3.384615 2.913100 26 1 13 1 2.5 4.00
## Malwest 2.818182 2.600699 11 1 10 1 2.0 3.00
## RDG 2.750000 1.743409 20 1 8 2 2.0 3.25
##
## $comparison
## NULL
##
## $groups
## COUNT groups
## Caniogan 5.888889 a
## Balingasay 4.729167 a
## Magsaysay 3.384615 a
## Lucero 3.241379 a
## Malwest 2.818182 a
## RDG 2.750000 a
## Cory 1.750000 a
## Cangaluyan 1.000000 a
##
## attr(,"class")
## [1] "group"