cmdscale(d, k = 2, eig = FALSE, add = FALSE, x.ret = FALSE,
list. = eig || add || x.ret)
dist
or a full symmetric matrix containing the dissimilarities.list
should be
returned or just the \(n \times k\) matrix, see ‘Value:’..list
is false (as per default), a matrix with k
columns whose rows give the coordinates of the points chosen to
represent the dissimilarities. Otherwise, a list
containing the following components.
k
columns whose rows give the
coordinates of the points chosen to represent the dissimilarities.eig
is true. NB: versions of R before 2.12.1
returned only k
but were documented to return \(n - 1\).x.ret
is true.0
if add = FALSE
.cmdscale
follows
the analysis of Mardia (1978), and returns the best-fitting
\(k\)-dimensional representation, where \(k\) may be less than the
argument k
. The representation is only determined up to location (cmdscale
takes the column means of the configuration to be at the origin),
rotations and reflections. The configuration returned is given in
principal-component axes, so the reflection chosen may differ between
R platforms (see prcomp
). When add = TRUE
, a minimal additive constant \(c*\) is
computed such that the dissimilarities \(d_{ij} + c*\) are Euclidean and hence can be represented in n - 1
dimensions. Whereas S (Becker et al, 1988) computes this
constant using an approximation suggested by Torgerson, R uses the
analytical solution of Cailliez (1983), see also Cox and Cox (2001).
Note that because of numerical errors the computed eigenvalues need
not all be non-negative, and even theoretically the representation
could be in fewer than n - 1
dimensions.dist
. isoMDS
and sammon
in package https://CRAN.R-project.org/package=MASS provide alternative methods of
multidimensional scaling.require(graphics)
loc <- cmdscale(eurodist)
x <- loc[, 1]
y <- -loc[, 2] # reflect so North is at the top
## note asp = 1, to ensure Euclidean distances are represented correctly
plot(x, y, type = "n", xlab = "", ylab = "", asp = 1, axes = FALSE,
main = "cmdscale(eurodist)")
text(x, y, rownames(loc), cex = 0.6)
Run the code above in your browser using DataLab