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

Problem with diversity() #292

Closed
btp7rr opened this issue Sep 26, 2018 · 5 comments
Closed

Problem with diversity() #292

btp7rr opened this issue Sep 26, 2018 · 5 comments

Comments

@btp7rr
Copy link

btp7rr commented Sep 26, 2018

Hi,

I'm attempting to run shannon diversity index on the attached data files but I am getting the error "Error in diversity(tidyrgcfield1, index = "shannon") :
input data must be non-negative"
Help would be appreciated. Data file is attached.

I tried deleting contents of cell A1 that I had seen in a previous thread on the site but no luck.

Thanks in advance!

@eduardszoecs
Copy link
Contributor

I can't see any attached data. Have you investigated the problem the error message mentioned? Is there any negative value in your data?

@btp7rr
Copy link
Author

btp7rr commented Sep 26, 2018

tidyrgcfield1.txt
There is the attached data - sorry it must have failed the first time.
I've tried investigating the error mention to no success and there are no negative values in the data.

@jarioksa
Copy link
Contributor

jarioksa commented Sep 26, 2018

It seems that x < 0 is TRUE when x is a character string starting with an empty space (" 1.0"). This happens with your case. You should have a regular data with rows for observations (plots or what ever) and a column for each species, and the elements giving the abundance of a species in a row.

@btp7rr
Copy link
Author

btp7rr commented Sep 26, 2018

Thanks for the help. I checked the data set and I am not seeing anything cell of data with an empty space as you had mentioned.

This data set was also gathered and separated using tidyr from an original data set that was formatted in a way that you mention. Is there no way to use diversity() on a data set structure the same way as the one I had attached previously?

@btp7rr btp7rr closed this as completed Sep 27, 2018
jarioksa pushed a commit that referenced this issue Sep 28, 2018
This was raised as a github issue #292: input contained character
data and we tested against negative entries with x < 0, which
was true for empty string " " < 0. Try with diversity(dune.env).
jarioksa pushed a commit that referenced this issue Oct 3, 2018
Initially this started as a response to github issue #292: a user had
messy tidyverse data instead of clean data, and assumed diversity()
would work on that. However, when such messy data were transformed to
a matrix, it was all promoted to character, and diversity failed.
Such messy data are becoming more common because of tidyverse that
mixes various non-data variables with clean data.  The error message
was very confusing: diversity() detected "negative data",
because it used comparison x < 0, and this is TRUE for " " < 0 or
characters with initial blanks. Now we check that data are numeric
after as.matrix(). In the same process, I also checked several other
functions using dune.env data with factor variables, and fixed those
functions that silently accepted such data and gave misleading results,
and those that gave similar confusing error messages. In this process,
I also streamlined vegdist() that uses now less time in its R code.
jarioksa pushed a commit that referenced this issue Oct 3, 2018
This was raised as a github issue #292: input contained character
data and we tested against negative entries with x < 0, which
was true for empty string " " < 0. Try with diversity(dune.env).

(cherry picked from commit ade6555)
@jarioksa jarioksa mentioned this issue Oct 17, 2018
@jarioksa
Copy link
Contributor

issue #284 may be a duplicate of this issue.

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

3 participants