[R] isoMDS and stress

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Apr 14 18:33:23 CEST 2003


On Mon, 14 Apr 2003, Stéphane Deraco wrote:

> I try to calculate the stress of a configuration using the formula in
> the isoMDS help, 

You used a very different formula than the description on that page (which
does not contain a formula).

> but I don't have the same result than the stress
> returned by isoMDS :
> 
> > library(mva)
> > library(MASS)
> > data(swiss)
> > swiss.x <- as.matrix(swiss[,-1])
> > swiss.dist <- dist(swiss.x)
> > swiss.mds <- isoMDS(swiss.dist)
> initial  value 2.979731 
> iter   5 value 2.431486
> iter  10 value 2.343353
> final  value 2.338839 
> Converged
> > 
> > delta.x <- swiss.mds$points
> > delta.dist <- dist(delta.x)
> >
> > stress <- function(avant, apres) {
> + 	l <- length(avant)
> + 	num <- 0
> + 	denum <- 0
> + 
> + 	for (i in 1:l) {
> + 		num <- num + (avant[i] - apres[i])^2
> + 		denum <- denum + apres[i]
> + 	}
> + 
> + 	sqrt(num / denum)
> + }
> > 
> > swiss.mds$stress
> [1] 2.338839

The help page says that is a *percentage*.

> > stress(swiss.dist, delta.dist)
> [1] 0.4196349
> >
> 
> 
> Any idea ?

Use the right formula:

     However, the input distances are allowed a monotonic
     transformation.

and you haven't allowed one.  You have also forgotten to multiply by 100.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list