[R] isoMDS and stress

Stéphane Deraco deraco at ipsogen.com
Mon Apr 14 18:26:33 CEST 2003


Hi all,

I try to calculate the stress of a configuration using the formula in
the isoMDS help, 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
> stress(swiss.dist, delta.dist)
[1] 0.4196349
>


Any idea ?
Thanks

--
Stephane



More information about the R-help mailing list