Hi,
I just encountered what I thought was strange behavior in MDS. However, it
turned out that the mistake was mine. The lesson learned from my mistake is
that one should plot on a square pane when plotting results of an MDS. Not
doing so can be very misleading. Follow the example of an equilateral
triangle below to see what I mean. I hope this helps others to avoid this
kind of headache.
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)
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.
Plotting MDS (multidimensional scaling)
4 messages · Mario Valle, Jari Oksanen, Daniel Malter
Also try the asp parameter in plot.
plot(fit2$points, xlab="Coordinate 1", ylab="Coordinate 2",main="Metric
MDS",type='n',asp=1)
text(fit2$points, labels = c('A','B','C','D'), cex=1)
Hope it helps
mario
On 02-Apr-11 22:07, Daniel Malter wrote:
Hi,
I just encountered what I thought was strange behavior in MDS. However, it
turned out that the mistake was mine. The lesson learned from my mistake is
that one should plot on a square pane when plotting results of an MDS. Not
doing so can be very misleading. Follow the example of an equilateral
triangle below to see what I mean. I hope this helps others to avoid this
kind of headache.
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)
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.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Ing. Mario Valle Data Analysis and Visualization Group | http://www.cscs.ch/~mvalle Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82
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.
The header "metric mds" was actually a leftover because I initially used cmdscale and did not bother changing it for the example. Thanks, Daniel -- View this message in context: http://r.789695.n4.nabble.com/Plotting-MDS-multidimensional-scaling-tp3422670p3424135.html Sent from the R help mailing list archive at Nabble.com.