Skip to contents

Perform Classical Multidimensional Scaling on the matrix, adding MDS coordinates to metadata and optionally storing the distance matrix and result.

Usage

compute_mds(
  x,
  name = NULL,
  k = 2,
  store = TRUE,
  dist_method = "euclidean",
  eig = FALSE,
  ...
)

Arguments

x

A tidymatrix object

name

Name for this analysis. Default is "row_mds" or "column_mds" depending on active component.

k

Number of dimensions for MDS embedding. Default is 2.

store

If TRUE, stores the MDS result for later retrieval with get_analysis(). Default is TRUE.

dist_method

Distance method for dist(). Default is "euclidean". Options: "euclidean", "maximum", "manhattan", "canberra", "binary", "minkowski".

eig

If TRUE, return eigenvalues and GOF statistics (passed to cmdscale).

...

Additional arguments passed to stats::dist() or stats::cmdscale()

Value

A tidymatrix object with MDS coordinates added to metadata

Details

This function wraps stats::cmdscale() and stats::dist().

Examples

mat <- matrix(rnorm(500), nrow = 50, ncol = 10)
row_data <- data.frame(id = 1:50)
tm <- tidymatrix(mat, row_data)

# MDS on rows
tm <- tm |>
  activate(rows) |>
  compute_mds(k = 2)

# Now row_data has row_mds_1, row_mds_2 columns

# Get MDS result
mds_obj <- get_analysis(tm, "row_mds")