Skip to content

Commit 4f67860

Browse files
committed
Merge branch 'morisita'
2 parents 79a3122 + ff78d5f commit 4f67860

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

R/vegdist.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
if (method %in% c(7, 13, 15) && !isTRUE(all.equal(x, round(x))))
5656
warning("results may be meaningless with non-integer data in method ",
5757
dQuote(inm))
58+
if (method %in% 7 && round(max(x)) == 1) # morisita
59+
warning("results may be meaningless with largest integer 1 in method ",
60+
dQuote(inm))
5861
d <- .Call(do_vegdist, x, as.integer(method), PACKAGE = "vegan")
5962
d[d < ZAP] <- 0
6063
if (any(is.na(d)))

man/vegdist.Rd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@
226226
in the species present at site \eqn{j} that occur with only one
227227
individual in site \eqn{k} (Chao et al. 2005).
228228
229-
Morisita index can be used with genuine count data (integers) only. Its
229+
Morisita index can be used with genuine count data (integers) only. It
230+
is based on the idea of resampling without replacement and should not
231+
be used with presence/absence data, but may give meaningless results
232+
if compared sampling units (rows) have largest integer 1. Its
230233
Horn--Morisita variant is able to handle any abundance data.
231234
232235
Mahalanobis distances are Euclidean distances of a matrix where

src/vegdist.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,13 @@ static double veg_kulczynski(double *x, int nr, int nc, int i1, int i2)
352352
return dist;
353353
}
354354

355-
/* Morisita index. Can only be used with integer data, and may still
356-
* fail with unfortunate pairs of species occurring only once.
355+
/* Morisita index. Can only be used with non-negative integer data
356+
* (counts) and is hardly meaningful for presence/absence data or
357+
* comparisons where largest integer is 1. Function involves terms
358+
* tlam1, tlam2 which for x=1 are x*(x-1) = 0 and if both are 0 this
359+
* will give sim/0 which for sim > 0 is -Inf (made to 0), and for sim
360+
* == 0 is NaN (made to 1). While this technically works, this is not
361+
* very meaningful.
357362
*/
358363

359364
static double veg_morisita(double *x, int nr, int nc, int i1, int i2)
@@ -380,8 +385,11 @@ static double veg_morisita(double *x, int nr, int nc, int i1, int i2)
380385
i2 += nr;
381386
}
382387
if (count==0) return NA_REAL;
383-
dist = 1 - 2*sim/(tlam1/t1/(t1-1) + tlam2/t2/(t2-1))/t1/t2;
384-
if (dist < 0)
388+
if (sim <= 0)
389+
dist = 1;
390+
else
391+
dist = 1 - 2*sim/(tlam1/t1/(t1-1) + tlam2/t2/(t2-1))/t1/t2;
392+
if (dist < 0) /* round-off error or sim > 0 && tlam1+tlam2 == 0 */
385393
dist = 0;
386394
return dist;
387395
}

0 commit comments

Comments
 (0)