loading...

Perform a PCoA (`type = "metric"). or other forms of MDS.

mds(
  dist,
  k = 2,
  type = c("metric", "nonmetric", "cmdscale", "wcmdscale", "sammon", "isoMDS", "monoMDS",
    "metaMDS"),
  p = 2,
  ...
)

# S3 method for mds
plot(x, y, ...)

# S3 method for mds
autoplot(object, labels, col, ...)

# S3 method for mds
chart(data, labels, col, ..., type = NULL, env = parent.frame())

shepard(dist, mds, p = 2)

# S3 method for shepard
plot(
  x,
  y,
  l.col = "red",
  l.lwd = 1,
  xlab = "Observed Dissimilarity",
  ylab = "Ordination Distance",
  ...
)

# S3 method for shepard
autoplot(
  object,
  alpha = 0.5,
  l.col = "red",
  l.lwd = 1,
  xlab = "Observed Dissimilarity",
  ylab = "Ordination Distance",
  ...
)

# S3 method for shepard
chart(
  data,
  alpha = 0.5,
  l.col = "red",
  l.lwd = 1,
  xlab = "Observed Dissimilarity",
  ylab = "Ordination Distance",
  ...,
  type = NULL,
  env = parent.frame()
)

# S3 method for mds
augment(x, data, ...)

# S3 method for mds
glance(x, ...)

Arguments

dist

A dist object from stats::dist() or other compatible functions like vegan::vegdist(), or a Dissimilarity object, see dissimilarity().

k

The dimensions of the space for the representation, usually k = 2 (by default). It should be possible to use also k = 3 with extra care and custom plots.

type

Not used

p

For types "nonmetric", "metaMDS", "isoMDS", "monoMDS" and "sammon", a Shepard plot is also precalculated. pis the power for Minkowski distance in the configuration scale. By default, p = 2. Leave it like that if you don't understand what it means see MASS::Shepard().

...

More arguments (see respective types or functions)

x

Idem

y

Not used

object

An mds object

labels

Points labels on the plot (optional)

col

Points color (optional)

data

A data frame to augment with columns from the MDS analysis

env

Not used

mds

Idem

l.col

Color of the line in the Shepard's plot (red by default)

l.lwd

Width of the line in the Shepard"s plot (1 by default)

xlab

Label for the X axis (a default value exists)

ylab

Idem for the Y axis

alpha

Alpha transparency for points (0.5 by default, meaning 50% transparency)

Value

A mds object, which is a list containing all components from the corresponding function, plus possibly Shepard if the Shepard plot is precalculated.

Examples

library(chart)
data(iris, package = "datasets")
iris_num <- iris[, -5] # Only numeric columns
iris_dis <- dissimilarity(iris_num, method = "euclidean")

# Metric MDS
iris_mds <- mds$metric(iris_dis)
chart(iris_mds, labels = 1:nrow(iris), col = iris$Species)
#> Warning: ggrepel: 126 unlabeled data points (too many overlaps). Consider increasing max.overlaps


# Non-metric MDS
iris_nmds <- mds$nonmetric(iris_dis)
#> Run 0 stress 0.02525035 
#> Run 1 stress 0.04185238 
#> Run 2 stress 0.03646415 
#> Run 3 stress 0.03102098 
#> Run 4 stress 0.02682867 
#> Run 5 stress 0.04509293 
#> Run 6 stress 0.03197036 
#> Run 7 stress 0.0405996 
#> Run 8 stress 0.0463685 
#> Run 9 stress 0.0355157 
#> Run 10 stress 0.03205658 
#> Run 11 stress 0.04144916 
#> Run 12 stress 0.03079773 
#> Run 13 stress 0.0355425 
#> Run 14 stress 0.04175937 
#> Run 15 stress 0.03329719 
#> Run 16 stress 0.02525381 
#> ... Procrustes: rmse 0.0004851916  max resid 0.003683924 
#> ... Similar to previous best
#> Run 17 stress 0.04495317 
#> Run 18 stress 0.03629813 
#> Run 19 stress 0.03211867 
#> Run 20 stress 0.04058738 
#> *** Best solution repeated 1 times
chart(iris_nmds, labels = 1:nrow(iris), col = iris$Species)
#> Warning: ggrepel: 126 unlabeled data points (too many overlaps). Consider increasing max.overlaps

glance(iris_nmds) # Good R^2
#> # A tibble: 1 × 2
#>   linear_R2 nonmetric_R2
#>       <dbl>        <dbl>
#> 1     0.998        0.999
iris_sh <- shepard(iris_dis, iris_nmds)
chart(iris_sh) # Excellent matching + linear -> metric MDS is OK here