Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Morisita index error in vegdist #444

Closed
amc228 opened this issue Oct 24, 2021 · 3 comments
Closed

Morisita index error in vegdist #444

amc228 opened this issue Oct 24, 2021 · 3 comments

Comments

@amc228
Copy link

amc228 commented Oct 24, 2021

I am trying to calculate a Morisita index using vegdist, using a species abundance matrix that looks like so:

sp1 sp2 sp3 sp4
0 4 0 1
0 3 2 1
1 3 1 6

When I run distm<-vegdist(df, method='morisita') I get the following error:

"Warning message: In vegdist(x, method = "morisita", na.rm = TRUE) : missing values in results "

The output looks like so:

1 2 3 4 5 6
NaN

summary(distm) says that all values in the distance matrix generated are NAs:

Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
0 0 0 0 123873

Checks so far:

  • all values in the species abundance matrix are integers (as I understand the morisita index requires this)
  • there are no 'NAs' or negative values in the species abundance matrix. There are no 'missing values'.
  • changing na.rm to FALSE produces the same result
  • all other indicies work - it is only morisita that produces this error

Happy to share the real data if anyone is interested - I'm really confused as to what could be causing this error.

@jarioksa
Copy link
Contributor

jarioksa commented Oct 24, 2021

Yes, this can happen. I have known this since implementing the function in 2001, and I thought I had warned about this in the help page, but there seems to be no warning. I'll add a warning.

If you have (several) species with only one occurrence, the correction term (λ) with x (x-1) becomes zero and you end up with a division with zero, and that's NaN. It is just written in the formula so it is the destiny, and you cannot use Morisita index for such data.

@jarioksa
Copy link
Contributor

A reproducible way of triggering this behaviour is

library(vegan)
data(BCI)
m <- as.matrix(BCI)
vegdist(pmax(m-24, 0), "morisita")

@jarioksa
Copy link
Contributor

jarioksa commented Nov 3, 2021

I cannot reproduce the problem with your data:

library(vegan)
m <- matrix(c(0,0,1,4,3,3,0,2,1,1,1,6), 3, 4)
m
#     [,1] [,2] [,3] [,4]
#[1,]    0    4    0    1
#[2,]    0    3    2    1
#[3,]    1    3    1    6
vegdist(m, "morisita") ## this will be OK:
#          1         2
#2 0.0000000          
#3 0.2941176 0.1326531

I know Morisita will fail sometimes (just look at its formula: it must fail sometimes), but it works with your example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants