Skip to content

Instantly share code, notes, and snippets.

@arcaravaggi
Created September 21, 2017 12:59
Show Gist options
  • Save arcaravaggi/0b829257f41c3554cbbff8b1017ba6b1 to your computer and use it in GitHub Desktop.
Save arcaravaggi/0b829257f41c3554cbbff8b1017ba6b1 to your computer and use it in GitHub Desktop.
Metrics for quantifying the similarity among ecological niche models
# The modOverlap function calculates three metrics:
# Shoener’s D for niche overlap
# Hellinger distance between probability distributions
# Warren's I similarity statistic
#
# This function is also found in the fuzzysim package
#
# From https://modtools.wordpress.com/2015/10/30/modoverlap/
modOverlap <- function (pred1, pred2, na.rm = TRUE)
{
p1 <- pred1/sum(pred1, na.rm = na.rm)
p2 <- pred2/sum(pred2, na.rm = na.rm)
SchoenerD <- 1 - 0.5 * sum(abs(p1 - p2), na.rm = na.rm)
HellingerDist <- sqrt(sum((sqrt(p1) - sqrt(p2))^2, na.rm = na.rm))
WarrenI <- 1 - ((HellingerDist^2)/2)
list(SchoenerD = SchoenerD, WarrenI = WarrenI, HellingerDist = HellingerDist)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment