[R] Plotting MDS (multidimensional scaling)

Jari Oksanen jari.oksanen at oulu.fi
Sun Apr 3 08:22:12 CEST 2011


Daniel Malter <daniel <at> umd.edu> writes:

> 
> Let's say I have an equilateral triangle. Then, the three Euclidean
> distances between points A, B, and C  are all equal. That is,
> dist(AB)=dist(AC)=dist(BC). Let the points A, B, and C have
> (x,y)-coordinates  (0,0), (2,0), and (1,sqrt(3)). Then, MDS should reproduce
> an equilateral triangle, which it does if there are only three points. 
> 
> require(MASS)
> x=c(0,2,1,0,0,sqrt(3))
> dim(x)=c(3,2)
> d1=dist(x)
> fit1<-isoMDS(d1)
> plot(fit1$points, xlab="Coordinate 1", ylab="Coordinate 2", 
>   main="Metric MDS",type="n")
> text(fit1$points, labels = c('A','B','C'), cex=1)
> 
> So far so good, until I add more points. Now assume, I add a fourth point D
> at {0,2*sqrt(3)}. This produces the rectangular triangle ABD with
> hypothenuse BD that encompasses the smaller triangle ABC such that C lies in
> the middle between B and D. Then, MDS should reproduce the rectangular
> triangle ABD and the equilateral triangle ABC within it. However, even
> though distance matrix d2 below still indicates that ABC is an equilateral
> triangle, the plot of the MDS does not confirm this.
> 
> x=c(0,2,1,0,0,0,sqrt(3),2*sqrt(3))
> dim(x)=c(4,2)
> d2=dist(x)
> fit2<-isoMDS(d2)
> plot(fit2$points, xlab="Coordinate 1", ylab="Coordinate 2", 
>   main="Metric MDS",type="n")
> text(fit2$points, labels = c('A','B','C','D'), cex=1)
> 
Daniel,

Mario Valle already told you about asp=1 in plot() to force equal aspect 
ratio, and MASS also has eqscplot() function for plots with geometrically 
equal scaling. However, your example above hints that there is 
something else you should take care of: You label your plot as 
"Metric MDS", but isoMDS does not do metric MDS. The title in its 
documentation reads "Kruskal's Non-metric Multidimensional Scaling". 
In this case you happened to have metric MDS, because isoMDS uses 
metric scaling as its default starting configuration, and in this case 
that starting configuration is a perfect fit (stress = 0), and isoMDS() 
makes no iterations to change the starting configuration. If you want 
to work with metric MDS, use cmdscale() which does metric MDS.

Cheers, jari Oksanen

> The reason for this is that the dimension of the plot is automatically
> scaled to fit the points. This distorts the visual impression of the
> distances, angular relationships, and relative locations. If you plot on a
> square pane, however, peace and order are restored in the galaxy.
> 
> plot(fit2$points, xlab="Coordinate 1", ylab="Coordinate 2", 
>   main="Metric MDS",type="n",xlim=c(-3,3),ylim=c(-3,3))
> text(fit2$points, labels = c('A','B','C','D'), cex=1)
> 
> Best,
> Daniel
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Plotting-MDS-multidimensional-
scaling-tp3422670p3422670.html
> Sent from the R help mailing list archive at Nabble.com.
> 
>



More information about the R-help mailing list