Learn R Programming

Rdimtools (version 1.0.0)

do.mds: (Classical) Multidimensional Scaling

Description

do.mds performs a classical Multidimensional Scaling (MDS) using Rcpp and RcppArmadillo package to achieve faster performance than cmdscale.

Usage

do.mds(
  X,
  ndim = 2,
  preprocess = c("center", "scale", "cscale", "decorrelate", "whiten")
)

Arguments

X

an \((n\times p)\) matrix or data frame whose rows are observations and columns represent independent variables.

ndim

an integer-valued target dimension.

preprocess

an option for preprocessing the data. Default is "center". See also aux.preprocess for more details.

Value

a named list containing

Y

an \((n\times ndim)\) matrix whose rows are embedded observations.

trfinfo

a list containing information for out-of-sample prediction.

projection

a \((p\times ndim)\) whose columns are basis for projection.

References

kruskal_multidimensional_1964Rdimtools

Examples

Run this code
# NOT RUN {
## use iris data
data(iris)
X   = as.matrix(iris[,1:4])
lab = as.factor(iris$Species)

## 1. projection onto 2 dimension.
output1 <- do.mds(X,ndim=2)

## 2. different preprocessing leads to different results
output2 <- do.mds(X,ndim=2,preprocess="decorrelate")
output3 <- do.mds(X,ndim=2,preprocess="whiten")

## 3. visualize
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,3))
plot(output1$Y, col=lab, main="MDS::center")
plot(output2$Y, col=lab, main="MDS::decorrelate")
plot(output3$Y, col=lab, main="MDS::whiten")
par(opar)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab