[R] Help: Strange MDS behavior
Youngser Park
youngser at jhu.edu
Thu Nov 13 19:52:49 CET 2003
Hi!
I have a dissimilarity matrix X and try to compare it with X' =
dist(cmdscsale(X,k)).
If I increase k, I should expect that the error (or fit) should
monotonically decrease, right.
Here is a sample code;
library(mva)
set.seed(12345)
x <- as.matrix(dist(matrix(rnorm(100),ncol=10,byrow=T)))
# x[1,2]<-x[2,1]<-1000 ## <<--** 1
# x[5,6]<-x[6,5]<-1000 ## <<--** 2
fit <- NULL
for(k in 1:9)
{
mds <- cmdscale(x,k,add=T)
xprime <- as.matrix(dist(mds$points))
fit[k] <- sum((x-xprime)^2)/sum(x^2)
}
plot(fit)
When I run this example, it gives a nice "good" plot. However, with
those two commented lines added, the plot is opposite, that is, the fit
is increasing as k grows!
I really don't understand this behavior. The reason why I added those
two lines is because my real input data is not an Euclidean distance
matrix, but a dissimilarity matrix calculated from my own metric.
So, does this mean that the matrix X *must* be an Euclidean distance
matrix in this example?
Thanks in advance.
- Youngser
More information about the R-help
mailing list