On Thu, Dec 15, 2011 at 10:47 AM, Lorenzo Isella <lorenzo.ise...@gmail.com> wrote: > Thanks a lot! > Precisely what I had in mind. > One last question (an extension of the previous one): can this be extended > to points in 3D? Once again, given the distance matrix, can I reconstruct a > set of coordinates (among many possible) for the points in three-dimensional > space? > Cheers > > Lorenzo
Yes, you need to specify argument 'k=3' to cmdscale which instructs it to 'scale' the input into 3 dimensions (the default is 2). nPoints = 10; nDim = 3; set.seed(10); points = matrix(runif(nPoints * nDim), nPoints, nDim); # Their distance: dst = dist(points) # Classical multidimensional scaling mds = cmdscale(dst, k=nDim); # Distance of the points calculated by mds dst2 = dist(mds); # The two distances are equal all.equal(as.vector(dst), as.vector(dst2)) HTH Peter ______________________________________________ R-help@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.