This function collapses nodes and geographic ranges based on species' divergence times at various time depths.
collapse_range(
x,
tree,
n,
species = "species",
grids = "grids",
format = "wide"
)
A community matrix or data frame.
A phylogenetic tree.
Time depth to slice the phylogenetic tree (often in millions of years for dated trees).
If format =
“long” (the default),
the column with the species name.
The column with the sites or grids if format =
“long”.
Format of the community composition data: “long” or “wide” with species as columns and sites as rows.
Two community data frames: the collapsed community data
and
original community data
Daru, B.H., Farooq, H., Antonelli, A. & Faurby, S. (2020) Endemism patterns are scale dependent. Nature Communications 11: 2115.
library(ape)
tr1 <- read.tree(text ="(((a:2,(b:1,c:1):1):1,d:3):1,e:4);")
com <- matrix(c(1,0,1,1,0,0,
1,0,0,1,1,0,
1,1,1,1,1,1,
1,0,1,1,0,1,
0,0,0,1,1,0), 6, 5,
dimnames=list(paste0("g",1:6), tr1$tip.label))
collapse_range(com, tr1, n=1)
#> $collapsed_com
#> grids species
#> 1 g1 a
#> 4 g1 d
#> 6 g3 a
#> 8 g3 d
#> 9 g4 a
#> 12 g4 d
#> 13 g4 e
#> 16 g5 e
#> 18 g6 d
#> 2 g1 b
#> 5 g2 b
#> 7 g3 b
#> 10 g4 b
#> 14 g5 b
#> 17 g6 b
#>
#> $original_com
#> grids species
#> 1 g1 a
#> 2 g1 b
#> 3 g1 c
#> 4 g1 d
#> 5 g2 c
#> 6 g3 a
#> 7 g3 c
#> 8 g3 d
#> 9 g4 a
#> 10 g4 b
#> 11 g4 c
#> 12 g4 d
#> 13 g4 e
#> 14 g5 b
#> 15 g5 c
#> 16 g5 e
#> 17 g6 c
#> 18 g6 d
#>