[R] question on isoMDS

Jari Oksanen jarioksa at sun3.oulu.fi
Tue Apr 13 07:32:30 CEST 2004

Helmut Kudrnovsky,

This issue was discussed on this list recently:  Search for messages
with Subject: "Fwd: MDS problems" at and after 26 March. Brief answer to
your question is: no, you cannot run isoMDS in MASS if you have zero or
negative dissimilarities. You should remove identical cases. After all,
you know that in isoMDS, identical cases will be identical even after
NMDS and you can locate your removed points over remaining points in the
plot (there is a subtle weighting issue, though).

The canonical solution is to remove the duplicates before calculating

test.bc <- dist(unique(test)) 

(or you can use vegdist in place of dist, like you seemingly did

An alternative discussed previously would be to remove the offending
dissimilarities. The following simple-minded function seems to do the

unique.dist <-
function (x, incomparables = FALSE, ...)
    if (!is.logical(incomparables) || incomparables)
        .NotYetUsed("incomparables != FALSE")
    is.na(x) <- x <= 0
    x <- as.matrix(x)
    x[upper.tri(x)] <- 0
    take <- complete.cases(x)

If test.bc is your dist structure, you can make it `unique' with:

test.bcuniq <- unique(test.bc)

The name of the function may be confusing: what's `unique' in removing
zeros? However, the following seems to hold:

dist(unique(x)) == unique(dist(x))

which would justify the name.

The previous discussion mentioned some dirty tricks, too.

cheers, jari oksanen

On Mon, 2004-04-12 at 15:21, Helmut Kudrnovsky wrote:

> I have a question on isoMDS.
> My data set (of vegetation) with 210 samples is in this way:
>                Rotfoehrenau Lavendelweidenau Silberweidenau ....
> 067_Breg.7               0                2              0         ....
> 071_Dona.4              0                2              6          ....
> ...
> I want to do an isoMDS-analysis with the dissimilarity index "bray/curtis" 
> as discribed in the help-files of the package vegan:
> mds.test <- isoMDS(test.bc, initMDS(test.bc), maxit=200, trace=FALSE, tol=1e-7)
> Then I get following error message:
> "Error in isoMDS(test.bc, initMDS(test.bc), maxit = 200, trace = FALSE,  :
>          zero or negative distance between objects 19 and 20"
> The objects 19 and 20 have the same variables in the same way and therefore 
> they have a zero distance.
> My question is: Is it possible to perform an isoMDS with a data set where 
> some samples have the same variables in the same way?

J.Oksanen, Oulu, Finland.
"Object-oriented programming is an exceptionally bad idea which could
only have originated in California." E. Dijkstra

More information about the R-help mailing list