[R-sig-eco] 2 questions about NMDS in vegan

Jari Oksanen jari.oksanen at oulu.fi
Tue Mar 10 20:28:01 CET 2009


Hello Gavin, Manuel and others,

Thank you for bringing this to our attention. There really seems to be  
a bug in metaMDS: it was geared for handling only typical community  
dissimilarity values (the "recommended" ones) which have maximum value  
of 1 when there is nothing in common between compared units. I'll fix  
that in R-Forge ASAP (the function already is half aware of those open- 
ended dissimilarities with no fixed maximum: it counts correctly the  
number of pairs with no shared species, but it doesn't handle them  
correctly in stepacross). I'll fix this.

Labelling of entries in plot.envfit is indeed a bit trickier, at least  
if we try to do that in the canonical R way, where the labels are  
given as an argument of the plot() command. It would be easier to  
change labels in the envfit but then they would be permanently saved  
with the fitted object. Gavin, if you think this can be done cleanly  
and in an R way, please go on. I don't know yet a snappy solution.

Cheers, jari oksanen
On 10/03/2009, at 21:01 PM, Gavin Simpson wrote:

> On Sun, 2009-03-08 at 08:46 -0600, Manuel Spínola wrote:
>> Dear list members,
>>
>> I am trying to run an NMDS with 9 standardized variables regarding to
>> water quality and I got the following message:
>>
>>> aguae.mds <- metaMDS(aguae, dist="euclidean", k=2, zerodist="add")
>> Using step-across dissimilarities:
>> Too long or NA distances: 564 out of 666 (84.7%)
>> Stepping across 666 dissimilarities...
>> Error in isoMDS(dist, k = k, trace = isotrace) :
>> an initial configuration must be supplied with NA/Infs in 'd'
>> In addition: Warning messages:
>> 1: In metaMDSdist(comm, distance = distance, autotransform =
>> autotransform,  :
>> Zero dissimilarities changed into 0.0759809585356366
>> 2: In stepacross(dis, trace = trace, ...) :
>> Disconnected data: Result will contain NAs
>> 3: In metaMDSdist(comm, distance = distance, autotransform =
>> autotransform,  :
>> Data are disconnected, results may be meaningless
>
> I'm guessing as I don;t have your data, but...
>
>> 1) Should I do not standardize the variables?
>
> This has nothing to do with it (or perhaps only tangentially). Your  
> data
> have triggered the use of step-across distances (?stepacross) because
> 10% of your samples do not share any "species" (here your water  
> quality
> variables).
>
> stepacross then tries to find a dissimilarity between these samples  
> that
> do not share any species, by replacing all distances greater than 1  
> with
> NA and then trying to fill them back in using the shortest path  
> method.
> See ?stepacross.
>
> Of course, toolong = 1, the argument controlling which distances are
> replaced with NA, which defaults to 1, is far too small for Euclidean
> distances which have no upper bound. The output shows that 85% of your
> dissimilarities were replaced by NA and they it tried to fill them  
> back
> in using the remaining 15%. It failed to achieve this, hardly
> surprisingly, so told you that NA's were in the result. isoMDS can;t
> operate with NA's in the input dissimilarities without an initial
> configuration being supplied; something metaMDS does not do, hence it
> borked and threw the error.
>


This really is a bug in metaMDS: it is so stupid that it only expects  
"normal" dissimilarities with maximum of 1 when there is nothing in  
common between rows. It is only half-witty: it is prepared for open- 
ended dissimilarities when it counts
> Either 1) read everything on ?metaMDS and ?stepacross at least twice  
> and
> then read the associated references so you understand what is going on
> --- I'm only vaguely aware of what all this code does --- then come  
> back
> and set the various arguments to metaMDS and stepacross to be more
> appropriate for your data and dissimilarities and try again, or
>
> 2) turn off step-across dissimilarities by setting no.shared = 1 in  
> your
> call to metaMDS and see if that helps.
>
>>
>> 2) In a plot for a nmds with fitted environmental variables (function
>> envfit) how can I change the name of the labels of the vectors  
>> (arrows)?
>
> Changes the names of your original data and refit - it takes the  
> labels
> from names(my_data) where my_data is your data object originally.
>
> Or, look at the code being the plot method for plot.envfit:
>
> https://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/vegan/R/plot.envfit.R?rev=570&root=vegan&view=markup
>
> copy/paste that into your editor, and then towards the bottom, find:
>
>    if (!is.null(vect)) {
>        arrows(at[1], at[2], vect[, 1], vect[, 2], len = 0.05,
>               col = col)
>        text(vtext, rownames(x$vectors$arrows), col = col, ...)
>    }
>    if (!is.null(x$factors)) {
>        text(x$factors$centroids[, choices, drop = FALSE], rownames(x 
> $factors$centroids),
>             col = col, ...)
>    }
>
> This sets the labels for the arrows/centroids (top if is arrows,  
> bottom
> centroids). Change the rownames(x$FOO$BAR) bits to be the vector of
> labels you want for the arrows/centroids. You need to provide all  
> labels
> and you need them to be in the correct order. After making that  
> change,
> paste back into R and use it as normal.
>
> I could change plot.envfit directly in vegan to allow arbitrary labels
> (it should be easy, but it is slightly complicated because you can  
> have
> two types of things drawn) supplied by user via a 'labels = NULL'
> argument to this plot method. But as Jari authored this we should
> probably ask him if such a change would be warranted? He's CC'd here.
>
>>
>> Thank you very much in advance.
>
> You're welcome, hope it helps,
>
> G
>
>> Best,
>>
>> Manuel Spínola
>>
> -- 
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
> ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
> Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
> Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
> UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>



More information about the R-sig-ecology mailing list