-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lamb et al 2020_Gecko morpho markdown.Rmd
356 lines (266 loc) · 11.8 KB
/
Lamb et al 2020_Gecko morpho markdown.Rmd
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
---
title: "Gecko Ecomorphology"
author: "April Lamb, Alex Dornburg, and Dan Warren"
date: "23 September 2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
### Comparing ecomophology in two gecko species
We will be running the following analyses on these nine traits:
Post-orbital Width, Temporalis Width, Head Length, Jaw Length, Head Height, Front Upper Leg, Front Lower Leg, Hind Upper Leg, Hind Lower Leg
```{r}
# Set working directory
setwd("/Users/April/Documents/More gecko stuff/Gecko morphology Linear Regression") #Path will need to be updated
# Load packages
library(vegan) # contains all common ordination methods - pca, cca, decorana, nmds
library(MASS)
library(ggplot2)
library(RColorBrewer)
library(ellipse)
library(geomorph)
library(sm)
library(ape)
library(geiger)
library(phytools)
# Read in data (file path will need to be updated)
length.data <- read.csv("Morpho MDS R data.csv")
morphogeckologic.AL <- read.csv("Morpho MDS R data logic.csv", header = TRUE)
```
#### Isolate traits by species
```{r}
h <- rep("Hemidactylus",79)
p <- rep("Phyllodactylus",57)
Species <- c(h,p)
measurements <- length.data[,2:12]
SVL <- length.data[,1]
name.l <-morphogeckologic.AL[,1]
name.l <- as.character(name.l)
trait2 <- cbind(name.l,SVL, measurements)
hemi <- trait2[which(trait2$name.l=="Hemidactylus "),]
phyllo <- trait2[which(trait2[1][,1]=="Phyllodactylus "),]
hSVL <- hemi[,2]
hmeasurements <- hemi[,3:13]
hname2 <- hemi[,1]
pSVL <- phyllo[,2]
pmeasurements <- phyllo[,3:13]
pname2 <- phyllo[,1]
raw_data <- rbind(hemi,phyllo)
```
#### ANCOVA
```{r}
h <- rep("Hemidactylus",79)
p <- rep("Phyllodactylus",57)
Species <- c(h,p)
# Post-orbital Width
POW <- aov(log(Post.Orbit.W) ~ Species*log(SVL), raw_data); summary(POW)
# Temporalis Width
TW <- aov(log(Temporalis.W) ~Species*log(SVL), raw_data); summary (TW)
# Head Length
HL <-aov(log(Head.L) ~Species*log(SVL), raw_data); summary(HL)
# Jaw Length
JL <- aov(log(Jaw.L) ~Species*log(SVL), raw_data); summary(JL)
# Head Height
HH <- aov(log(Head.H) ~Species*log(SVL), raw_data); summary(HH)
# Front Upper Limb
FUL <-aov(log(F_upper_limb) ~Species*log(SVL), raw_data); summary(FUL)
# Front Lower Limb
FLL <- aov(log(F_lower_limb) ~Species*log(SVL), raw_data); summary(FLL)
# Hind Upper Limb
HU <- aov(log(Hind_upper) ~Species*log(SVL), raw_data); summary(HU)
# Hind Lower Limb
HL <- aov(log(Hind_lower) ~Species*log(SVL), raw_data); summary(HL)
# Total Front Limb
TFL <- aov(log(Total_front_limb) ~Species*log(SVL), raw_data); summary(TFL)
# Total Hind Limb
THL <- aov(log(Total_hind_limb) ~Species*log(SVL), raw_data); summary(THL)
```
#### Linear regressions
```{r}
# Post-orbital Width
reg1 <- lm(log(Post.Orbit.W)~log(SVL), hemi); summary(reg1) # *hemidactylus*
reg2 <- lm(log(Post.Orbit.W)~log(SVL), phyllo); summary(reg2) # *phyllodactylus*
plot(log(Post.Orbit.W)~log(SVL), raw_data, type='n')
points(log(hemi$SVL),log(hemi$Post.Orbit.W), pch=20, col="blue")
points(log(phyllo$SVL),log(phyllo$Post.Orbit.W), pch=20, col = "orange")
abline(reg1, lty=1, col = "blue")
abline(reg2, lty=2, col = "orange")
legend("bottomright", c("Hemidactylus","Phyllodactylus"), lty=c(1,2), pch=c(20,1), col = c("blue", "orange"))
# Temporalis Width
reg3 <- lm(log(Temporalis.W)~log(SVL), hemi); summary(reg3) # *hemidactylus*
reg4 <- lm(log(Temporalis.W)~log(SVL), phyllo); summary(reg4) # *phyllodactylus*
plot(log(Temporalis.W)~log(SVL), raw_data, type='n')
points(log(hemi$SVL),log(hemi$Temporalis.W), pch=20, col="blue")
points(log(phyllo$SVL),log(phyllo$Temporalis.W), pch=20, col="orange")
abline(reg3, lty=1, col = "blue")
abline(reg4, lty=2, col = "orange")
legend("bottomright", c("Hemidactylus","Phyllodactylus"), lty=c(1,2), pch=c(20,1), col = c("blue", "orange"))
# Head Length
reg5 <- lm(log(Head.L)~log(SVL), hemi); summary(reg5) # *hemidactylus*
reg6 <- lm(log(Head.L)~log(SVL), phyllo); summary(reg6) # *phyllodactylus*
plot(log(Head.L)~log(SVL), raw_data, type='n')
points(log(hemi$SVL),log(hemi$Head.L), pch=20, col="blue")
points(log(phyllo$SVL),log(phyllo$Head.L), pch=20, col="orange")
abline(reg5, lty=1, col = "blue")
abline(reg6, lty=2, col = "orange")
legend("bottomright",c("Hemidactylus","Phyllodactylus"), lty=c(1,2), pch=c(20,1), col = c("blue", "orange"))
# Jaw Length
reg7 <- lm(log(Jaw.L)~log(SVL), hemi); summary(reg7) # *hemidactylus*
reg8 <- lm(log(Jaw.L)~log(SVL), phyllo); summary(reg8) # *phyllodactylus*
plot(log(Jaw.L)~log(SVL), raw_data, type='n')
points(log(hemi$SVL),log(hemi$Jaw.L), pch=20, col="blue")
points(log(phyllo$SVL),log(phyllo$Jaw.L), pch=20, col="orange")
abline(reg7, lty=1, col = "blue")
abline(reg8, lty=2, col = "orange")
legend("bottomright", c("Hemidactylus","Phylodactylus"), lty=c(1,2), pch=c(20,1), col = c("blue", "orange"))
# Head Height
reg9 <- lm(log(Head.H)~log(SVL), hemi); summary(reg9) # *hemidactylus*
reg10 <- lm(log(Head.H)~log(SVL), phyllo); summary(reg10) # *phylodactylus*
plot(log(Head.H)~log(SVL), raw_data, type='n')
points(log(hemi$SVL),log(hemi$Head.H), pch=20, col="blue")
points(log(phyllo$SVL),log(phyllo$Head.H), pch=20, col="orange")
abline(reg9, lty=1, col = "blue")
abline(reg10, lty=2, col = "orange")
legend("bottomright", c("Hemidactylus","Phylodactylus"), lty=c(1,2), pch=c(20,1), col = c("blue", "orange"))
# Front Upper Limb
reg11 <- lm(log(F_upper_limb)~log(SVL), hemi); summary(reg11) # *hemidactylus*
reg12 <- lm(log(F_upper_limb)~log(SVL), phyllo); summary(reg12) # *phylodactylus*
plot(log(F_upper_limb)~log(SVL), raw_data, type='n')
points(log(hemi$SVL),log(hemi$F_upper_limb), pch=20, col="blue")
points(log(phyllo$SVL),log(phyllo$F_upper_limb), pch=20, col="orange")
abline(reg11, lty=1, col = "blue")
abline(reg12, lty=2, col = "orange")
legend("bottomright", c("Hemidactylus","Phylodactylus"), lty=c(1,2), pch=c(20,1), col = c("blue", "orange"))
# Front Lower Limb
reg13 <- lm(log(F_lower_limb)~log(SVL), hemi); summary(reg13) # *hemidactylus*
reg14 <- lm(log(F_lower_limb)~log(SVL), phyllo); summary(reg14) # *phyllodactylus*
plot(log(F_lower_limb)~log(SVL), raw_data, type='n')
points(log(hemi$SVL),log(hemi$F_lower_limb), pch=20, col="blue")
points(log(phyllo$SVL),log(phyllo$F_lower_limb), pch=20, col="orange")
abline(reg13, lty=1, col = "blue")
abline(reg14, lty=2, col = "orange")
legend("bottomright", c("Hemidactylus","Phyllodactylus"), lty=c(1,2), pch=c(20,1), col = c("blue", "orange"))
# Hind Upper Limb
reg15 <- lm(log(Hind_upper)~log(SVL), hemi); summary(reg15) # *hemidactylus*
reg16 <- lm(log(Hind_upper)~log(SVL), phyllo); summary(reg16) # *phyllodactylus*
plot(log(Hind_upper)~log(SVL), raw_data, type='n')
points(log(hemi$SVL),log(hemi$Hind_upper), pch=20, col="blue")
points(log(phyllo$SVL),log(phyllo$Hind_upper), pch=20, col="orange")
abline(reg15, lty=1, col = "blue")
abline(reg16, lty=2, col = "orange")
legend("bottomright", c("Hemidactylus","Phyllodactylus"), lty=c(1,2), pch=c(20,1), col = c("blue", "orange"))
# Hind Lower Limb
reg17 <- lm(log(Hind_lower)~log(SVL), hemi); summary(reg17) # *hemidactylus*
reg18 <- lm(log(Hind_lower)~log(SVL), phyllo); summary(reg18) # *phyllodactylus*
plot(log(Hind_lower)~log(SVL), raw_data, type='n')
points(log(hemi$SVL),log(hemi$Hind_lower), pch=20, col="blue")
points(log(phyllo$SVL),log(phyllo$Hind_lower), pch=20, col="orange")
abline(reg17, lty=1, col = "blue")
abline(reg18, lty=2, col = "orange")
legend("bottomright", c("Hemidactylus","Phyllodactylus"), lty=c(1,2), pch=c(20,1), col = c("blue", "orange"))
# Total Front Limb
reg19 <- lm(log(Total_front_limb)~log(SVL), hemi); summary(reg19) # *hemidactylus*
reg20 <- lm(log(Total_front_limb)~log(SVL), phyllo); summary(reg20) # *phyllodactylus*
plot(log(Total_front_limb)~log(SVL), raw_data, type='n')
points(log(hemi$SVL),log(hemi$Total_front_limb), pch=20, col="blue")
points(log(phyllo$SVL),log(phyllo$Total_front_limb), pch=20, col="orange")
abline(reg19, lty=1, col = "blue")
abline(reg20, lty=2, col = "orange")
legend("bottomright", c("Hemidactylus","Phyllodactylus"), lty=c(1,2), pch=c(20,1), col = c("blue", "orange"))
# Total Hind Limb
reg21 <- lm(log(Total_hind_limb)~log(SVL), hemi); summary(reg21) # *hemidactylus*
reg22 <- lm(log(Total_hind_limb)~log(SVL), phyllo); summary(reg22) # *phyllodactylus*
plot(log(Total_hind_limb)~log(SVL), raw_data, type='n')
points(log(hemi$SVL),log(hemi$Total_hind_limb), pch=20, col="blue")
points(log(phyllo$SVL),log(phyllo$Total_hind_limb), pch=20, col="orange")
abline(reg19, lty=1, col = "blue")
abline(reg20, lty=2, col = "orange")
legend("bottomright", c("Hemidactylus","Phyllodactylus"), lty=c(1,2), pch=c(20,1), col = c("blue", "orange"))
```
#### PCA
```{r}
# Regress traits again for dataset containing both species
r1 <- lm(Post.Orbit.W~SVL, data=raw_data); summary(r1)
r2 <- lm(Temporalis.W~SVL, data=raw_data); summary(r2)
r3 <- lm(Head.L~SVL, data=raw_data); summary(r3)
r4 <- lm(Head.H~SVL, data=raw_data); summary(r4)
r5 <- lm(Jaw.L~SVL, data=raw_data);summary(r5)
r6 <- lm(F_lower_limb~SVL, data=raw_data); summary(r6)
r7 <- lm(F_upper_limb~SVL, data=raw_data); summary(r7)
r8 <- lm(Hind_upper~SVL, data=raw_data); summary(r8)
r9 <- lm(Hind_lower~SVL, data=raw_data); summary(r9)
# Get residuals
p1 <- residuals(r1)
p2 <- residuals(r2)
p3 <- residuals(r3)
p4 <- residuals(r4)
p5 <- residuals(r5)
p6 <- residuals(r6)
p7 <- residuals(r7)
p8 <- residuals(r8)
p9 <- residuals(r9)
trait <- cbind(p1,p2,p3,p4,p5,p6,p7,p8,p9)
# Regular prcomp funtion. We have to use absoulte values here to account for negative loadings.
hp <- prcomp(trait)
hp$rotation
aload <- abs(hp$rotation)
sweep(aload, 2, colSums(aload), "/")
loadings2 <- hp$x
# Standard deviation of each principal component
std_dev <- hp$sdev
# Variance
pr_var <- std_dev^2
pr_var[1:9]
# Proportion of variance explained by each component
prop_varex <- pr_var/sum(pr_var)
prop_varex[1:9]
```
#### PC1 vs. PC2
```{r}
Z <- data.frame(loadings2[,1],loadings2[,2])
X1 <- data.frame(loadings2[1:79,1],loadings2[1:79,2])
X2 <- data.frame(loadings2[80:136,1], loadings2[80:136,2])
plot(loadings2[,1],loadings2[,2], cex = 1, col="White")
points(loadings2[1:79,1],loadings2[1:79,2], cex=1.5,col="blue", pch=16) # Hemidactylus
points(loadings2[80:136,1],loadings2[80:136,2], cex=1.2,col="gray", pch=17) # Phylodactylus
##get convex hull
hpts <- chull(X1)
hpts <- c(hpts, hpts[1])
lines(X1[hpts, ],col="Blue")
hpts2 <- chull(X2)
hpts2 <- c(hpts2, hpts2[1])
lines(X2[hpts2, ], col = "Gray")
```
#### PC1 v. PC3
```{r}
Z1 <- data.frame(loadings2[,1],loadings2[,3])
X3 <- data.frame(loadings2[1:79,1],loadings2[1:79,3])
X4 <- data.frame(loadings2[80:136,1], loadings2[80:136,3])
plot(loadings2[,1],loadings2[,3], cex = 1, col="White")
points(loadings2[1:79,1],loadings2[1:79,3], cex=1.5,col="blue", pch=16) # Hemidactylus
points(loadings2[80:136,1],loadings2[80:136,3], cex=1.2,col="gray", pch=17) # Phylodactylus
##get convex hull
hpts <- chull(X3)
hpts <- c(hpts, hpts[1])
lines(X3[hpts, ],col="Blue")
hpts2 <- chull(X4)
hpts2 <- c(hpts2, hpts2[1])
lines(X4[hpts2, ], col = "Gray")
```
#### PC2 v. PC3
```{r}
Z2 <- data.frame(loadings2[,2],loadings2[,3])
X5 <- data.frame(loadings2[1:79,2],loadings2[1:79,3])
X6 <- data.frame(loadings2[80:136,2], loadings2[80:136,3])
plot(loadings2[,2],loadings2[,3], cex = 1, col="White")
points(loadings2[1:79,2],loadings2[1:79,3], cex=1.5,col="blue", pch=16) # Hemidactylus
points(loadings2[80:136,2],loadings2[80:136,3], cex=1.2,col="gray", pch=17) # Phylodactylus
##get convex hull
hpts <- chull(X5)
hpts <- c(hpts, hpts[1])
lines(X5[hpts, ],col="Blue")
hpts2 <- chull(X6)
hpts2 <- c(hpts2, hpts2[1])
lines(X6[hpts2, ], col = "Gray")
```