normMDS: Normalized Non-Metric Multidimensional Scaling

View source: R/normMDS.R

normMDSR Documentation

Normalized Non-Metric Multidimensional Scaling

Description

A function to compare implied 2D topologies based on different distance matrices for the same data points

Usage

normMDS(dists, xy = NULL, id = "ID", ax = 1:2, chir = 3, x = "x", y = "y", ...)

Arguments

dists

A list (named, ideally) of distance matrices with the same points

xy

(Optional) The points in geographic space. This can be a data.frame, data.table, SpatVect, or SpatialPointsDataFrame object. If provided, axes orientations and chirality will be taken with respect to xy.

id

Character. The name of the column in xy containing the unique name or id for each observation. Default is xy = 'ID'.

ax

The index (if numeric) or Unique ID (if character) of the two points defining the reference axis. The first point will be placed at the origin. If xy = NULL, the second point will be placed at v = 0. Default is ax = 1:2.

chir

The index (if numeric) or Unique ID (if character) of the point defining the reference handendess/chirality. This must be a point not in ax. Default is ax = 3

x

Character. The name of the column in xy containing the x coordinate for each observation. Default is xy = 'x'. Ignored if xy is a SpatVect or Spatial object.

y

Character. The name of the column in xy containing the y coordinate for each observation. Default is xy = 'y'. Ignored if xy is a SpatVect or Spatial object.

...

Additional parameters to pass to isoMDS

Details

The function relies on isoMDS from the MASS package to generate pseudo-coordinates for distance matrices using a 2D non-metric Multi Dimensional Scaling. Since the output orientation can be unpredictable, normMDS aligns all topologies based on a common user-defined axis (the ends of which will appear equidistant and equioriented on an output plot), and selects a chiral reference point to ensure that plots are oriented in a common orientation.

Value

A named list, with each entry containing a data.table of estimated pseudo-coordinates in (u,y) space. One unit is equal to the distance between both points in the ax parameter. If xy was provided, the first entry 'ref' will be the geographic data.

Examples


# Create fake data
xy <- data.table(ID = c('A','B','C','D','E'),
                 x = runif(5, -100, 100),
                 y = runif(5, -100, 100))
                 
# Calculate a distance matrix
dists <- as.matrix(stats::dist(xy[,.(x,y)], upper = TRUE, diag = TRUE) )
rownames(dists) <- xy$ID
colnames(dists) <- xy$ID               
                 
                 
# Make a list of five fake distance matrices from five fake coordinates
dists <- list()
for (i in 1:5){
  fake <- data.table(ID = c('A','B','C','D','E'),
                 x = runif(5, -100, 100),
                 y = runif(5, -100, 100))
                 
  fake <- as.matrix(stats::dist(fake[,.(x,y)], upper = TRUE, diag = TRUE) )
  rownames(fake) <- xy$ID
  colnames(fake) <- xy$ID 
  dists[[i]] <- fake
}

# Get pseudo-coordinates
normMDS(dists, xy = xy)

andresgmejiar/lbmech documentation built on Feb. 2, 2025, 12:37 a.m.