7 Functions to do Metric Multidimensional Scaling in R

In this post we will talk about 7 different ways to perform a metric multidimensional scaling in R.

Multidimensional Scaling

Multidimensional Scaling (MDS), is a set of multivariate data analysis methods that are used to analyze similarities or dissimilarities in data. One of the nice features of MDS is that it allows us to represent the (dis)similarities among pairs of objects as distances between points in a low-dimensional space. Put another way, MDS allows us to visualize the (dis)similarities in a low-dimensional space for exploration and inspection purposes.

The general approach behind MDS consists of calculating a (dis)similarity matrix among pairs of objects (i.e. observations, individuals, samples, etc), and then apply one of the several MDS “models” to obtain the low-dimensional representation. The MDS model to be applied depends on the type of data, and consequently, the type of (dis)similarity measurement that the analyst decides to use.

Metric Multidimensional Scaling

Depending on the chosen measurement and the obtained (dis)similarity matrix, MDS can be divided in two main approaches: metric and nonmetric. If the analyzed matrix is based on a metric distance, we talk about metric MDS, otherwise we talk about nonmetric MDS.

Metric multidimensional scaling, also known as Principal Coordinate Analysis or Classical Scaling, transforms a distance matrix into a set of coordinates such that the (Euclidean) distances derived from these coordinates approximate as well as possible the original distances (do not confuse Principal Coordinate Analysis with Principal Component Analysis). In other words, the advantage of working with metric MDS, is that the relationships among objects can, in most cases, be fully represented in an Euclidean space.

Metric Multidimensional Scaling in R

R has a number of ways to perform metric MDS. The following list shows you 7 different functions to perform metric MDS (with their corresponding packages in parentheses):

You should know that all the previous functions require a distance matrix as the main argument to work with. If you don’t have your data in (dis)similairty matrix format, you can calculate the distance matrix with the function dist. This is the “work-horse” function in R for calculating distances (euclidean, manhattan,binary, canberra and maximum). In addition, some of the packages mentioned above, provide their own functions for calculating other types of distances.

Installing packages

Except for cmdscale, the rest of the functions don’t come with the default distribution of R; this means that you have to install their corresponding packages:

Data eurodist

We will use the dataset eurodist that gives the road distances (in km) between 21 cities in Europe. Notice that eurodist is already an object of class “dist” (matrix distance). You can inspect the first 5 elements like so:

As you can see, the obtained graphic allows us to represent the distances between cities in a two-dimensional space. However, the representation is not identical to a geographical map of Europe: Athens is in the north while Stockholm is in the south. This “anomaly” reflects the fact that the representation is not unique; if we wanted to get a more accurate geographical representation, we would need to invert the vertical axis.

2) MDS with wcmdscale

The package ‘vegan’ provides the function wcmdscale (Weighted Classical Multidimensional Scaling). Its general usage has the following form:

wcmdscale(d, k, eig = FALSE, add = FALSE, x.ret = FALSE, w)

If we specify the vector of the weights w as a vector of ones, wcmdscale will give ordinary multidimensional scaling.

7) MDS with smacofSym

The package ‘smacof’ provides the function smacofSym (Multidimensional scaling (stress minimization: SMACOF) on symmetric dissimilarity matrix.). This function uses a majorization approach to get the solution (more info in this vignette). Its general usage has the following form: