Classic Multidimensional Scaling aka Principal Coordinate Analysis (PCoA).
Get the Senate vote-patterns down to a nice 2D plot.
$ npm i fit-mds
import { MultidimensionalScaling as MDS } from 'fit-mds';
const result = new MDS(data, dimension, options);
// some methods and properties
const d = result.dimension; // dimension of the output space
const error = result.strain(); // stress of the solution
const up = result.scaleUp(n); // `n` either number or array !
const down = result.scaleDown(n); // same
-
data
is an array of arrays. There are two cases:- Pass the distances between pair of points. In this case we are passing a dissimilarity/distance matrix. Which is the default.
- Pass the raw data. It needs the option
calculateDissimilarity:true
.
-
dimension
is the dimension of the output space. It may be less depending on the EigenValues, you can inspect it usingresult.dimensions
. -
options
is an object currently only with the optioncalculateDissimilarity
which isfalse
by default, as described previously.
Given a distance matrix with the distances between each pair of objects in a set, and a chosen number of dimensions, N, an MDS algorithm places each object into N-dimensional space (a lower-dimensional representation) such that the between-object distances are preserved as well as possible. For N = 1, 2, and 3, the resulting points can be visualized on a scatter plot.