-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path5_phylogeny.rmd
126 lines (101 loc) · 4.35 KB
/
5_phylogeny.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
5. phylogeny
===============================================
The realized, abiotic Hutchinsonian niche [@Hutchinson57], i.e. an n-dimensional
hypervolume whose dimensions are inferred from ecological niche modeling, is
maintained in ecological time. Whether it is conserved in evolutionary time
depends on the rate of niche evolution. If niche evolution is rapid enough,
species that are closely related might not resemble each other in terms of their
niches at all. Conversely, if niche evolution is slower, phylogenetic
conservatism of the niche can be demonstrated: closely related species have
similar niches.
Here we test the extent to which there is phylogenetic conservatism in the niche
of terrestrial Artiodactyla and Perissodactyla, i.e. the folk taxonomic group of
the Ungulates. The way we test this is by performing Mantel's permutation test
for the similarity of two distance matrices [@Mantel67]. The procedure shuffles
the distances in the second matrix many times and calculates the correlation
coefficient with respect to the first matrix each time. If the true correlation
between the two matrices is outside of the distribution obtained from the
permutations, then the two matrices are interrelated.
In the present case, the first matrix is the set of all pairwise patristic
distances among the Ungulates, e.g. as computed from a phylogenetic tree such
as [@BinindaEmonds07]. The second matrix is the set of all pairwise distances
in niche space, e.g. as computed by taking Schoener's D from the modeled niche
projections.
### Analysis pre-amble
We begin by loading the required packages and defining the global variables that
allow us to locate and reconcile our data:
```{r preamble}
library(ape)
library(strap)
library(cba)
# this should define the root folder of the local copy of the git repository at:
# https://github.com/naturalis/trait-geo-diverse-ungulates, which is
# automatically defined correctly if we run the present code from within a
# local clone of the repo and have set the working directory to the script
# source (in RStudio: Session > Set working directory > To source file location)
REPO_HOME <- paste(getwd(), "/../", sep = "")
```
### Load phylogeny
We now load the subtree for the Ungulates extracted from the mammal supertree of
[@BinindaEmonds07]. This is the complete subtree for the terrestrial
Artiodactyla and Perissodactyla, hence there are more tips in this tree then we
have niche data for. We will reconcile these data sets later on.
```{r supertree}
tree.file <- sprintf('%s/data/phylogeny/ungulates.tree',REPO_HOME)
#tree.file <- sprintf('%s/data/phylogeny/S21191.tree',REPO_HOME)
tree <- ape::collapse.singles(ape::read.tree(file = tree.file), root.edge = T)
# set the age of the root to absolute time
tree$root.time <- max(node.depth.edgelength(tree))
strap::geoscalePhylo(
tree,
units = "Epoch",
cex.age = 1,
cex.ts = 0.5,
boxes = T,
show.tip.label = F
)
```
### Load Schoener's D
Subsequently, we load the matrix of Schoener's D pairwise distances in niche
space. We read these distances from a file whose contents were pre-computed in
another [script](../script/Niche_Overlap.Rmd).
```{r distances}
# a triangular, inverse distance (i.e. overlap) matrix file
overlap.file <- paste(REPO_HOME, '/results/maxent/overlap.csv', sep = '')
overlap <- read.table(overlap.file, sep = ",")
# invert the inverse matrix to get distances
distances <- as.dist(1-overlap)
# compute and draw a dendrogram from the distances using neighbor joining
dendrogram <- ape::nj(distances)
ape::plot.phylo(
dendrogram,
type = "unrooted",
show.tip.label = F,
no.margin = T
)
```
### Perform Mantel test
Now we will reconcile the two data sets and perform the Mantel test on the
intersection of the two.
```{r mantel}
# prune the tree
tip.idx <- match(names(overlap),tree$tip.label)
tip.idx <- tip.idx[!is.na(tip.idx)]
tree.pruned <- ape::keep.tip(tree,tip.idx)
# prune the overlap matrix
overlap.pruned <- as.matrix(subset(as.dist(overlap),tree.pruned$tip.label))
overlap.pruned <- as.matrix(1 - overlap.pruned)
# make the tree into a distance matrix
tree.pruned.cophenetic <- ape::cophenetic.phylo(tree.pruned)
# do the test
result <- ape::mantel.test(
tree.pruned.cophenetic,
overlap.pruned,
graph = T,
nperm = 1000
)
```
So, is there phylogenetic conservatism in niches? In fact, no:
```{r result}
result$p < 0.05
```