Last active
April 1, 2017 01:50
-
-
Save rBatt/7faba570cfe1b31b4ce6416d9414833f to your computer and use it in GitHub Desktop.
If all species occupy only 1 site, does beta diversity depend on whether they occupy different sites or overlap?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nspp <- 10 | |
nsites <- 10 | |
Y_1sppPer <- diag(x=1, nrow=nspp, ncol=nsites) | |
Y_allSpp1Site <- rbind(rep(1,nspp), matrix(rep(0,nspp*nsites-nspp),nrow=nsites-1)) | |
# euclidean distance | |
euc <- function(x){ | |
sum(scale(x,scale=FALSE)^2)/(nrow(x)-1) | |
} | |
euc(Y_1sppPer) # 1 | |
euc(Y_allSpp1Site) # 1 | |
# jaccard | |
jaccard <- function(x){ | |
n <- nrow(x) | |
d <- ade4::dist.binary(x, method=1) # need package ade4 | |
sstot <- sum(d^2)/n | |
sstot/(n-1) | |
} | |
jaccard(Y_1sppPer) # 0.5 | |
jaccard(Y_allSpp1Site) # NaN | |
# hellinger | |
hellinger <- function(x){ | |
n <- nrow(x) | |
Y <- vegan::decostand(x, "hellinger") # requires vegan package | |
s <- scale(Y, center=TRUE, scale=FALSE)^2 | |
sum(s) /(n-1) | |
} | |
hellinger(Y_1sppPer) # 1 | |
hellinger(Y_allSpp1Site) # 0.1 | |
Author
rBatt
commented
Mar 31, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment