There is a function called LINKTREE
in PRIMER where a tree is created based on community dissimilarity, but each breakpoint must correspond to a threshold in one or more environmental (constraining) variables.
Is there an equivalent function in R? hclust
creates trees based on dissimilarity matrices, but I haven't figured out a way to "constrain" it using a second data frame.
Data to play with:
library(vegan)
comm <- data.frame(oak = c(4,10,3), birch = c(3,6,1), maple = c(9,6,3),
row.names = c('site 1','site 2','site 3'))
comm.dist <- dist(comm)
env <- data.frame(temp = c(35,39,31), rain = c(103,85,80),
row.names = c('site 1','site 2','site 3'))
tree <- hclust(comm.dist)
plot(tree)
cca <- cca(comm ~ ., data = env)
plot(cca, display = c('sp', 'bp'))
The desired output would be a tree where the first breakpoint would separate site 2 from 1 and 3 because it is most dissimilar, but it would also be labeled 'temp>37', because site 2 is the only site with a temperature above 37. The breakpoint between 1 and 3 would be 'temp>33' and/or 'rain>95'