[R] about isoMDS method

Gavin Simpson gavin.simpson at ucl.ac.uk
Mon Aug 31 00:18:47 CEST 2009

```On Sun, 2009-08-30 at 09:40 -0700, Grzes wrote:
> Yes, I'm using euclidean distances

Sorry I deleted the original. Here a some responses;

First, to be concrete, here is a reproducible example...

set.seed(123)
D <- data.frame(matrix(rnorm(100), ncol = 10))
Dij <- dist(D)
require(MASS)
Dnmds <- isoMDS(Dij, k = 2)

Now look at structure of Dnmds:

> str(Dnmds)
List of 2
\$ points: num [1:10, 1:2] -0.356 1.058 -2.114 -0.177 0.575 ...
..- attr(*, "dimnames")=List of 2
.. ..\$ : NULL
.. ..\$ : NULL
\$ stress: num 12.2

The second matrix you talk about is component \$points of the object
returned by isoMDS.

1) The rows of \$points pertain to your n samples. In the example I give,
there are 10 rows as we have ten samples. Row 1 is the location of
sample 1 in the 2d nMDS solution. Likewise for Row 2.

2) Why do you think that? nMDS aims to preserve the rank correlation of
dissimilarities, not of the actual dissimilarities. You are also working
with a 2D solution of the nMDS fit to your full dissimilarity matrix.
There will be some level of approximation going on.

You can look at how the well dissimilarities in the nMDS solution
reflect the original distances using function Shepard:

## continuing from the above
S <- Shepard(Dij, Dnmds\$points)
plot(S)
lines(yf ~ x, data = S, type = "S", col = "blue", lwd = 2)

You can also compute some measures to help understand how well the nMDS
distances reflect the original distances.

## Note, these are taken from function stressplot in the vegan package
## written by Jari Oksanen, which uses isoMDS from package MASS
## internally.
## you might want to look at metaMDSiter() in that package to do random
## starts to check you haven't converged to a sub-optimal local solution
(stress <- sum((S\$y - S\$yf)^2) / sum(S\$y^2)) ## intermediate calc
(rstress <- 1 - stress) ## non-metric fit, R^2
(ralscal <- cor(S\$y, S\$yf)^2) ## Linear fit, R2
(stress <- sqrt(stress) * 100)
## compare with
Dnmds\$stress ## statistic minimised in nMDS algorithm

In this example, the stress is quite low, hence quite a good fit.

HTH

G
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

```