[R] Vegan R^2 and tau values for metaMDS

Gavin Simpson gavin.simpson at ucl.ac.uk
Mon Apr 14 23:24:48 CEST 2008


On Mon, 2008-04-14 at 17:00 -0400, Sarah Goslee wrote:
> On Mon, Apr 14, 2008 at 4:47 PM, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:
> 
> >  Note that the default is to produce a bray-curtis dissimilarity matrix
> >  from the input species data. As such, I reproduce this dissimilarity
> >  matrix as arg 1 to cor and then take the Euclidean distances of the
> >  coordinates on nMDS axes 1:2 (this example is a 2D solution but scales
> >  to n-dimensions) as the second argument to cor:
> >
> >  cor(vegdist(dune), dist(sol$points))^2
> >
> >  In this example, the "R^2" is 0.899222
> >
> >  If you already have jaccard for your species data, then substitute this
> >  for 'vegdist(dune)' and sol for whatever your nMDS object is called.
> 
> Good point. I forgot to clarify that you should use the same dissimilarity
> metric for your original data that was used in constructing the ordination.
> Euclidean distances should be used for the NMDS configuration, though.

Yes - here I use dist(sol$points) which defaults to Euclidean distances.

> 
> >  However, this assumes a linear relationship between the original
> >  distances and the nMDS distances. The relationship need not be linear,
> >  just monotonic if I recall the details correctly.
> 
> If you (the original querent) are interested in the monotonic rather than
> strictly linear relationship, you could use the "spearman" option to
> cor().

I forgot about that, thanks for the reminder Sarah. This correlation
(using method = "spearman") is different to the ones used in stressplot.
I peeked inside the code of that function and the following should
reproduce the linear fit R^2 shows on the plot produced by stressplot:

## continuing the example from my previous email
require(MASS) # for Shepard()
shep <- Shepard(vegdist(dune), sol$points)
cor(shep$y, shep$yf)^2

The last line yields = 0.9250712.

The non-metric fit is 1 - stress and this can be calculated using:

1 - (sum((shep$y - shep$yf)^2)/sum(shep$y^2))

So now you have 4 different R^2 values to choose from Stephen...

HTH

G

> 
> Sarah
> 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 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-help mailing list