An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130624/f760826c/attachment.pl>
Error with metaMDS
5 messages · suparna mitra, Sarah Goslee, Gavin Simpson
Hi, What do you expect the dissimilarity between a site with no species and a site with some species to be? If you want to use Bray-Curtis dissimilarity, you need to drop the sites with no species, as the error message suggests. But if you can answer my first question, you may be able to select a different dissimilarity metric that matches your expectations numerically. Sarah On Mon, Jun 24, 2013 at 7:33 AM, Suparna Mitra
<suparna.mitra.sm at gmail.com> wrote:
H
ello R-experts,
I want to do ordination plots using vegan metaMDS.
I have a where many cells have zero values.
Data structure:
X[1:10,1:14]
Height.1 Height.2 Height.3 Height.4 Height.5 Height.6 Height.7
Height.8 Height.9 Height.10 Height.11 Height.12 Height.13
D30I1A 46 0 0 0 0 0 0
0 0 0 39 0 98
D30I1B 46 0 0 0 0 0 0
0 0 0 39 0 98
D30I1C 70 0 0 0 0 0 0
0 0 0 0 85 0
D30I2A 47 0 0 0 0 0 0
0 0 0 49 0 105
D30I2B 68 0 0 0 0 0 0
0 0 0 83 0 214
D30I2C 0 75 0 0 0 0 0
0 0 0 0 83 0
D30I3A 48 0 0 0 0 0 0
0 0 0 42 0 107
D30I3B 64 0 0 0 0 0 0
0 0 0 72 0 177
D30I3C 72 0 0 0 0 0 0
0 0 0 0 96 0
D30M1A 60 0 0 0 0 0 0
0 0 0 74 0 169
Another data structure
Genus_data[1:10,1:14]
Sample Acanthamoeba Acidianus Aegilops Alphapapillomavirus Asfivirus
Brassica Buchnera Coprinellus Diaphorobacter Hartmannella Ignicoccus
1 HS1_S1 0 0 0 0 0
0 0 0 0 0 0
2 HS2_S2 0 1 1 0 0
0 0 0 0 1 0
3 HS3_S3 0 0 0 1 0
0 1 1 1 0 0
4 HS4_S4 0 0 0 0 1
0 0 0 0 0 0
5 HS13_S5 0 0 0 0 0
0 0 0 0 0 0
6 HS14_S6 0 0 0 0 0
1 0 0 0 0 0
7 HS15_S7 0 0 0 0 0
0 0 0 0 0 0
8 HS16_S8 0 0 0 0 0
0 0 0 0 0 1
9 HS25_S9 1 0 0 0 0
0 0 0 0 0 0
I am having two different kind of errors for these two data...
Error 1
ord1 <- metaMDS(
X
="bray")
Square root transformation
Wisconsin double standardization
Error in if (any(dist < -sqrt(.Machine$double.eps))) warning("some
dissimilarities are negative -- is this intentional?") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In distfun(comm, method = distance, ...) :
you have empty rows: their dissimilarities may be meaningless in method
?bray?
2: In distfun(comm, method = distance, ...) : missing values in results
Error 2
ord.data= metaMDS(data, distance="bray")
Error in if (any(autotransform, noshare > 0, wascores) && any(comm < 0)) {
:
missing value where TRUE/FALSE needed
In addition: Warning message:
In Ops.factor(left, right) : < not meaningful for factors
I searched all the details of metaMDS where it is suggested to avail the
argument 'zerodist'
So I tried both
X.dist1 <- metaMDSdist(X, method="bray",zerodist = "ignore")
X.dist2 <- metaMDSdist(X, method="bray",zerodist = "add")
Can Please help me with this.
Thanks,
Mitra
Sarah Goslee http://www.functionaldiversity.org
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130625/6aaff44c/attachment.pl>
Hi, On Mon, Jun 24, 2013 at 12:04 PM, Suparna Mitra
<suparna.mitra.sm at gmail.com> wrote:
Dear Sarah, Thanks for your reply. But I don't have any site where all the species are 0.
Well, that's what this says:
1: In distfun(comm, method = distance, ...) : you have empty rows: their dissimilarities may be meaningless in method ?bray?
Is there anyway to calculate the dissimilarity between sites where it computes only the non-zero species values. Excluding all the zero event will result a big loss in species data. I don't want to delete the cases where may be 5out of 8 sites have species info, only 3 don't have.
There's no reason to delete those. Bray-Curtis and similar metrics consider only joint presences, not joint absences. If you have a lot of sites with no species in common, it can also cause problems. That's what vegan::stepacross is intended to deal with.
Should I replace zero with a very small number. What is the best thing to do in such cases?
The best thing to do in such cases is to provide a reproducible example to R-help. At the very least, str(X) str(data) # called in metaMDS() but not described; also, don't call your data data and double-check to make sure you don't have any all-zero rows or NA values in your data. Sarah
On 24 June 2013 21:24, Sarah Goslee <sarah.goslee at gmail.com> wrote:
Hi, What do you expect the dissimilarity between a site with no species and a site with some species to be? If you want to use Bray-Curtis dissimilarity, you need to drop the sites with no species, as the error message suggests. But if you can answer my first question, you may be able to select a different dissimilarity metric that matches your expectations numerically. Sarah On Mon, Jun 24, 2013 at 7:33 AM, Suparna Mitra <suparna.mitra.sm at gmail.com> wrote:
H
ello R-experts,
I want to do ordination plots using vegan metaMDS.
I have a where many cells have zero values.
Data structure:
X[1:10,1:14]
Height.1 Height.2 Height.3 Height.4 Height.5 Height.6 Height.7
Height.8 Height.9 Height.10 Height.11 Height.12 Height.13
D30I1A 46 0 0 0 0 0 0
0 0 0 39 0 98
D30I1B 46 0 0 0 0 0 0
0 0 0 39 0 98
D30I1C 70 0 0 0 0 0 0
0 0 0 0 85 0
D30I2A 47 0 0 0 0 0 0
0 0 0 49 0 105
D30I2B 68 0 0 0 0 0 0
0 0 0 83 0 214
D30I2C 0 75 0 0 0 0 0
0 0 0 0 83 0
D30I3A 48 0 0 0 0 0 0
0 0 0 42 0 107
D30I3B 64 0 0 0 0 0 0
0 0 0 72 0 177
D30I3C 72 0 0 0 0 0 0
0 0 0 0 96 0
D30M1A 60 0 0 0 0 0 0
0 0 0 74 0 169
Another data structure
Genus_data[1:10,1:14]
Sample Acanthamoeba Acidianus Aegilops Alphapapillomavirus
Asfivirus
Brassica Buchnera Coprinellus Diaphorobacter Hartmannella Ignicoccus
1 HS1_S1 0 0 0 0
0
0 0 0 0 0 0
2 HS2_S2 0 1 1 0
0
0 0 0 0 1 0
3 HS3_S3 0 0 0 1
0
0 1 1 1 0 0
4 HS4_S4 0 0 0 0
1
0 0 0 0 0 0
5 HS13_S5 0 0 0 0
0
0 0 0 0 0 0
6 HS14_S6 0 0 0 0
0
1 0 0 0 0 0
7 HS15_S7 0 0 0 0
0
0 0 0 0 0 0
8 HS16_S8 0 0 0 0
0
0 0 0 0 0 1
9 HS25_S9 1 0 0 0
0
0 0 0 0 0 0
I am having two different kind of errors for these two data...
Error 1
ord1 <- metaMDS(
X
="bray")
Square root transformation
Wisconsin double standardization
Error in if (any(dist < -sqrt(.Machine$double.eps))) warning("some
dissimilarities are negative -- is this intentional?") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In distfun(comm, method = distance, ...) :
you have empty rows: their dissimilarities may be meaningless in
method
?bray?
2: In distfun(comm, method = distance, ...) : missing values in results
Error 2
ord.data= metaMDS(data, distance="bray")
Error in if (any(autotransform, noshare > 0, wascores) && any(comm < 0))
{
:
missing value where TRUE/FALSE needed
In addition: Warning message:
In Ops.factor(left, right) : < not meaningful for factors
I searched all the details of metaMDS where it is suggested to avail the
argument 'zerodist'
So I tried both
X.dist1 <- metaMDSdist(X, method="bray",zerodist = "ignore")
X.dist2 <- metaMDSdist(X, method="bray",zerodist = "add")
Can Please help me with this.
Thanks,
Mitra
Sarah Goslee http://www.functionaldiversity.org
On Mon, 2013-06-24 at 19:33 +0800, Suparna Mitra wrote:
H ello R-experts, I want to do ordination plots using vegan metaMDS. I have a where many cells have zero values.
<snip />
I am having two different kind of errors for these two data... Error 1
ord1 <- metaMDS(
X ="bray")
That is fundamentally wrong - you are setting argument `X` to the
character vector `"bray"`, that is not how you call metaMDS(). Hence I
suspect you didn't bother to include the full code...!
Let's assume you cal actually call metaMDS() correctly...
The first set of warnings (not the error) come `vegdist()`. The first is
from :
if (method > 2 && any(rowSums(x, na.rm = TRUE) == 0))
and hence if you do
which(rowSums(X, na.rm = TRUE) == 0)
you'll see which rows (samples) have no counts at all. The second
warning in the first set comes from
if (any(is.na(d)))
warning("missing values in results")
hence by the time vegdist has computed the dissimilarity, those
computation ended up generating one or more `NA` values. Things go
downhill from there as the error generated from within metaMDS() is
because we are comparing the distances with the smallest representable
number and any comparison with `NA` yields `NA` and hence the first
Error you see. We should probably catch that but I don't have a
reproducible example to see why we don't...
Square root transformation
Wisconsin double standardization
Error in if (any(dist < -sqrt(.Machine$double.eps))) warning("some
dissimilarities are negative -- is this intentional?") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In distfun(comm, method = distance, ...) :
you have empty rows: their dissimilarities may be meaningless in method
bray
2: In distfun(comm, method = distance, ...) : missing values in results
Error 2
ord.data= metaMDS(data, distance="bray")
Error in if (any(autotransform, noshare > 0, wascores) && any(comm < 0)) {
:
missing value where TRUE/FALSE needed
In addition: Warning message:
In Ops.factor(left, right) : < not meaningful for factors
Look at `str(data)` and if any of the columns are factors, change them to be numeric or find out why R thinks they are factors - it wouldn't normally convert numeric data to a factor when reading the data in. What is `data`? You only refer to `Genus_data`. Please try to be specific about exactly what you did - i.e. include the actual code. I suspect the things you try below are pointless as it is not zero distances that are the problem but sites for which no observations were recorded. G
I searched all the details of metaMDS where it is suggested to avail the argument 'zerodist' So I tried both X.dist1 <- metaMDSdist(X, method="bray",zerodist = "ignore") X.dist2 <- metaMDSdist(X, method="bray",zerodist = "add") Can Please help me with this. Thanks, Mitra [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Gavin Simpson, PhD [t] +1 306 337 8863 Adjunct Professor, Department of Biology [f] +1 306 337 2410 Institute of Environmental Change & Society [e] gavin.simpson at uregina.ca 523 Research and Innovation Centre [tw] @ucfagls University of Regina Regina, SK S4S 0A2, Canada