-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdamselcoral.R
250 lines (194 loc) · 7.51 KB
/
damselcoral.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#Set working directory
setwd("C:/Users/Francisca/Documents/USYD/MARS5007")
library(ggplot2)
library(ordinal)
library(car)
library(RVAideMemoire)
#Open the file
damsel<-read.csv("OTI combined data2.csv", sep=';', header=TRUE)
#View just the first 6 rows
head(damsel)
tail(damsel)
attach(damsel)
#Boxplot Humbug
ggplot(damsel, aes(x = coral, y = nHumbug)) +
geom_boxplot(aes(colour= location)) +
labs(colour="Location")+
xlab("Coral") +
ylab("Number of fish")+
ggtitle("Boxplot of number of Humbug fish per coral genra") +
theme_bw() +
theme(plot.title = element_text(hjust=0.5, vjust=0.5,size = 14, family = "Helvetica", face = "bold" ),
text = element_text(size = 12, family = "Helvetica"),
axis.title = element_text(face="bold"),
axis.text.x=element_text(size = 11, angle=90),
) +
facet_grid(. ~ location)
#BoxPlot Humbug per volume
ggplot(damsel, aes(x = coral, y = pVMHumbug)) +
geom_boxplot(aes(colour= location)) +
labs(colour="Location")+
xlab("Coral") +
ylab("Number of fish per volume of coral")+
ggtitle("Boxplot of number of Humbug fish per volume of coral") +
theme_bw() +
theme(plot.title = element_text(hjust=0.5, vjust=0.5,size = 14, family = "Helvetica", face = "bold" ),
text = element_text(size = 12, family = "Helvetica"),
axis.title = element_text(face="bold"),
axis.text.x=element_text(size = 11, angle=90),
) +
facet_grid(. ~ location)
#Boxplot Humbug per location
ggplot(damsel, aes(x = location, y = pVCMHumbug)) +
geom_boxplot(aes(colour= location)) +
labs(colour="Location")+
xlab("Location") +
ylab("Number of fish per location")+
ggtitle("Boxplot of Humbug fish per location") +
theme_bw() +
theme(plot.title = element_text(hjust=0.5, vjust=0.5,size = 14, family = "Helvetica", face = "bold" ),
text = element_text(size = 12, family = "Helvetica"),
axis.title = element_text(face="bold"),
axis.text.x=element_text(size = 11, angle=90),
)
#Boxplot Humbug per coral
ggplot(damsel, aes(x = coral, y =pVMHumbug)) +
geom_boxplot(aes(colour= coral)) +
labs(colour="Coral")+
xlab("Coral") +
ylab("Number of fish per coral volume")+
ggtitle("Boxplot of Humbug fish per coral volume") +
theme_bw() +
theme(plot.title = element_text(hjust=0.5, vjust=0.5,size = 14, family = "Helvetica", face = "bold" ),
text = element_text(size = 12, family = "Helvetica"),
axis.title = element_text(face="bold"),
axis.text.x=element_text(size = 11, angle=90),
)
#Boxplot Lemon
ggplot(damsel, aes(x = coral, y = nLemon)) +
geom_boxplot(aes(colour= location, )) +
labs(colour="Location")+
xlab("Coral") +
ylab("Number of fish")+
ggtitle("Boxplot of number of Lemon fish per coral species ") +
theme_bw() +
theme(plot.title = element_text(hjust=0.5, vjust=0.5,size = 14, family = "Helvetica", face = "bold" ),
text = element_text(size = 12, family = "Helvetica"),
axis.title = element_text(face="bold"),
axis.text.x=element_text(size = 11, angle=90),
) +
facet_grid(. ~ location)
#BoxPlot Lemon per volume
ggplot(damsel, aes(x = coral, y = pVMLemon)) +
geom_boxplot(aes(colour= location)) +
labs(colour="Location")+
xlab("Coral") +
ylab("Number of fish per volume of coral")+
ggtitle("Boxplot of number of Lemon fish per volume of coral") +
theme_bw() +
theme(plot.title = element_text(hjust=0.5, vjust=0.5,size = 14, family = "Helvetica", face = "bold" ),
text = element_text(size = 12, family = "Helvetica"),
axis.title = element_text(face="bold"),
axis.text.x=element_text(size = 11, angle=90),
) +
facet_grid(. ~ location)
#Boxplot Lemon per location
ggplot(damsel, aes(x = location, y = pVMLemon)) +
geom_boxplot(aes(colour= location)) +
labs(colour="Location")+
xlab("Location") +
ylab("Number of fish per location")+
ggtitle("Boxplot of Lemon fish per location") +
theme_bw() +
theme(plot.title = element_text(hjust=0.5, vjust=0.5,size = 14, family = "Helvetica", face = "bold" ),
text = element_text(size = 12, family = "Helvetica"),
axis.title = element_text(face="bold"),
axis.text.x=element_text(size = 11, angle=90),
)
#Boxplot Lemon per coral
ggplot(damsel, aes(x = coral, y =pVMLemon)) +
geom_boxplot(aes(colour= coral)) +
labs(colour="Coral")+
xlab("Coral") +
ylab("Number of fish per coral volume")+
ggtitle("Boxplot of Lemon fish per coral volume") +
theme_bw() +
theme(plot.title = element_text(hjust=0.5, vjust=0.5,size = 14, family = "Helvetica", face = "bold" ),
text = element_text(size = 12, family = "Helvetica"),
axis.title = element_text(face="bold"),
axis.text.x=element_text(size = 11, angle=90),
)
ggplot(damsel, aes(x = domColor, y = pVMHumbug)) +
geom_boxplot()
xlab("Coral") +
ylab("Number of fish per volume of coral")+
ggtitle("Boxplot of number of Lemon fish per volume of coral") +
theme_bw() +
theme(plot.title = element_text(hjust=0.5, vjust=0.5,size = 14, family = "Helvetica", face = "bold" ),
text = element_text(size = 12, family = "Helvetica"),
axis.title = element_text(face="bold"),
axis.text.x=element_text(size = 11, angle=90),
) +
facet_grid(. ~ location)
ggplot(damsel, aes(x = domColor, y = pVMLemon)) +
geom_boxplot()
xlab("Coral") +
ylab("Number of fish per volume of coral")+
ggtitle("Boxplot of number of Lemon fish per volume of coral") +
theme_bw() +
theme(plot.title = element_text(hjust=0.5, vjust=0.5,size = 14, family = "Helvetica", face = "bold" ),
text = element_text(size = 12, family = "Helvetica"),
axis.title = element_text(face="bold"),
axis.text.x=element_text(size = 11, angle=90),
) +
facet_grid(. ~ location)
##STATISTICS FROM THIS POINT##
#Histogram **With this we can infere that the data does not have a normal distribution*
par(mfrow=c(1,2))
hist(pVMHumbug)
hist(pVMLemon)
#Homocedasticity
bartlett.test(pVMHumbug~location)
#ANOVA
summary(aov(pVMHumbug~location))
#Normal Distribution test
shapiro.test((aov(pVMHumbug~location))$residuals)
shapiro.test((aov(pVMHumbug~coral))$residuals)
#Plots
par(mfrow=c(2,2))
plot(aov(pVMHumbug~location))
#Non-parametric test
kruskal.test(pVMHumbug~location)
kruskal.test(pVMLemon~location)
kruskal.test(pVMHumbug~coral)
kruskal.test(pVMLemon~coral)
kruskal.test(pVMHumbug~domColor)
kruskal.test(pVMLemon~domColor)
#Wilcox test
pairwise.wilcox.test(pVMHumbug, location,
p.adjust.method = "BH")
pairwise.wilcox.test(pVMHumbug, coral,
p.adjust.method = "BH")
pairwise.wilcox.test(pVMHumbug, domColor,
p.adjust.method = "BH")
pairwise.wilcox.test(pVMLemon, location,
p.adjust.method = "BH")
pairwise.wilcox.test(pVMLemon, coral,
p.adjust.method = "BH")
#Cumulative Link Model and two-way ANOVA
##HUMBUG##
model = clm(factor_humbug ~ location + coral + location:coral,
data = damsel,
threshold="symmetric")
damsel$factor_humbug<-as.factor(damsel$pVCMHumbug)
str(damsel)
Anova(model,
type = "II")
##LEMON##
model2 = clm(factor_lemon~ location + coral + location:coral,
data = damsel,
threshold="symmetric")
damsel$factor_lemon<-as.factor(damsel$pVCMLemon)
str(damsel)
Anova(model2,
type = "II")