non-metric MDS comparison - vegan vs. ecodist packages
On 20/02/2012, at 22:01 PM, Gavin Simpson wrote:
On Mon, 2012-02-20 at 14:30 -0500, Sarah Goslee wrote:
References are given in the help for nmds. In particular, nmds() uses Kruskal's formulation.
And you can read the code. Look at nmds, at the top of the function body is an inline function sstress() which does the relevant computation, IIUC.
Unfortunately reading the code is not always quite easy in R, but you have to decipher the logic of the whole function instead of single easy pieces. The inline function sstress() gives the formula, but you have to read further down to see what are the actual variables used in sstress(). If you do so, you see that the ecodist::nmds stress is defined as: sum((dmat - dist)^2)/sum(dmat^2) where 'dmat' are the input dissimilarities and 'dist' are the distances among points in the ordination configuration. This is *not* Kruskal's stress, at least not like he defined it in his 1964 papers in Psychometrika. In vegan::monoMDS and in MASS::isoMDS Kruskal stress (stress=1 in vegan::monoMDS) we define squared stress as: sum((dist-dhat)^2)/sum(dist^2) where 'dhat' are the fitted distances from the monotone regression, and 'dist' the distances among points in ordination configuration (like above). So the stresses do differ, and that is sufficient to explain the differences. Cheers, Jari Oksanen
Sarah On Feb 20, 2012 1:48 PM, "Gian Maria Niccol Benucci" < gian.benucci at gmail.com> wrote:
Dear Gavin and Sarah, I've found how metaMDS() calculate the stress [using monoMDS() of vegan], but I do not find how nmds() of ecodist do it so. Could you please link me the page or where I can find it, maybe it escapes me... Thank you very much for your aid, Gian 2012/2/20 Gavin Simpson <gavin.simpson at ucl.ac.uk>
On Mon, 2012-02-20 at 17:24 +0100, Gian Maria Niccol Benucci wrote:
Dear Gavin, Thank you very much. I tried with your advice but the result is almost unchanged...
Any further advice??
Yeah, what Sarah said. Read the documentation; the two functions use different definitions of stress. You could always do a procrustes rotation on the two configurations to see how well they compare. G
Gian 2012/2/20 Gavin Simpson <gavin.simpson at ucl.ac.uk>
On Mon, 2012-02-20 at 16:28 +0100, Gian Maria Niccol Benucci wrote:
Hi r-sig-ecology Members, I would please you to examine the differences I found in metaMDS()
and
nmds() outputs and possibly draw some conclusions. As I wrote in
past
emails I have 24 samples of ectomycorrhizal fungi grouped into two different communities (12 natural and 12 cultivated). here is the code:
metaMDS(data_matrix2, distance="bray", k=2, autotransform=F) ->
metaMDS
metaMDS
Call: metaMDS(comm = data_matrix2, distance = "bray", k = 2,
autotransform
= F)
global Multidimensional Scaling using monoMDS Data: data_matrix2 Distance: bray Dimensions: 2 *Stress: 0.04536661 * Stress type 1, weak ties No convergent solutions - best solution after 20 tries
Perhaps you could try running metaMDS with random starts until it
does
find convergent solutions?! Why expect metaMDS() to do better in 20 tries than nmds() with 100 random tries? add `trymax = 100` and `halfchange = FALSE` to try to make the two functions more comparable. HTH G
Scaling: centring, PC rotation, halfchange scaling Species: expanded scores based on data_matrix2
nmds <- nmds(dist_bray, mindim = 2, maxdim = 2, nits = 100)
Using random start configuration Using random start configuration ...
nmds_min
X1 X2 1 -0.66226262 0.16392824 2 -0.68844987 -0.20891993 3 -0.47717515 0.55323693 4 -0.67213392 -0.09195847 5 0.03305172 0.41844232 6 0.31992006 0.53887910 7 -0.61944875 0.34411146 8 0.07013849 0.65723057 9 0.53053436 0.37444633 10 0.26704705 0.39849341 11 -0.20981416 0.70391983 12 -0.61620355 -0.43568743 13 0.14219660 -0.69571194 14 0.42365981 -0.43308767 15 0.15840330 -0.12872863 16 -0.00492407 -0.06889680 17 -0.20513513 -0.58052156 18 0.46546214 0.12019775 19 0.36753709 -0.25048256 20 -0.09446486 -0.61943616 21 0.15010553 -0.31995009 22 0.41540872 -0.29507200 23 0.42573367 -0.12321584 24 0.48081354 -0.02121688
min(nmds$stress)
[*1] 0.2787161*
nmds$r2[which.min(nmds$stress)]
[1] 0.6338372 Is it possible I got so different stress values?? Thanks for replying,
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% 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 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
*----- Do not print this email unless you really need to. Save paper
and
protect the environment! -----*
[[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% 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 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
[[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
[[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% 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 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Jari Oksanen, Dept Biology, Univ Oulu, 90014 Finland jari.oksanen at oulu.fi, Ph. +358 400 408593, http://cc.oulu.fi/~jarioksa