9
$\begingroup$

I would like to do Multidimensional Scaling (MDS) using cmdscale() in R. I have read that it is useful to try out how many dimensions are suitable for the data by trying different values of k, and then seeing what proportion of variance is accounted for in the MDS result by looking at the R-square value. R-square values smaller than 0.6 are generally found to be acceptable for a good fit between the data and the number of dimensions.

However, how do I calculate R-square from an MDS generated by cmdscale()?

$\endgroup$
3
  • 1
    $\begingroup$ It would be great if you could provide some more specific context and maybe example data or the type of data you want to use. $\endgroup$ Commented Jan 4, 2012 at 13:32
  • 2
    $\begingroup$ It sounds like you might be confusing non-metric MDS and classical MDS. Different values of k in non-metric MDS can potentially produce different results. metaMDS in the vegan package does this kind of analysis. Classical MDS, as in cmdscale, produces the same results for any value of k; changing the value of k just changes the number of axes returned, but the values of the axes will be the same. $\endgroup$
    – Tyler
    Commented Jan 4, 2012 at 14:20
  • 1
    $\begingroup$ This is a statistics question not a programming question. $\endgroup$
    – hadley
    Commented Jan 5, 2012 at 4:54

2 Answers 2

12
$\begingroup$

You can look at the "GOF" component of the result ("goodness of fit"), if you specify the number of dimensions. It returns two numbers, that should be equal unless the distance matrix is not positive.

You can also directly look at the eigenvalues: when they become small, you have enough dimensions.

In the following example, two dimensions seem sufficient.

> cmdscale(eurodist, 1, eig=TRUE)$GOF
[1] 0.4690928 0.5401388
> cmdscale(eurodist, 2, eig=TRUE)$GOF
[1] 0.7537543 0.8679134
> cmdscale(eurodist, 3, eig=TRUE)$GOF
[1] 0.7904600 0.9101784
> r <- cmdscale(eurodist, eig=TRUE)
> plot(cumsum(r$eig) / sum(r$eig), 
       type="h", lwd=5, las=1, 
       xlab="Number of dimensions", 
       ylab=expression(R^2))
> plot(r$eig, 
       type="h", lwd=5, las=1, 
       xlab="Number of dimensions", 
       ylab="Eigenvalues")
$\endgroup$
3
  • $\begingroup$ Thank you for this explanation! May I ask for more...? So for the GOF; the higher the better, right? Is this number related to the percentage of explained variance? As for the eigenvalues, is it suitable to do an analysis with k=10, plot the eigenvalues, and look for the 'cut-off' point as one would do for PCA? Sorry for all these questions... $\endgroup$
    – Annemarie
    Commented Jan 4, 2012 at 21:14
  • 1
    $\begingroup$ Yes, the goodness of fit increases to 1 as you add more dimensions; it can be interpreted as an R-squared. But if it is too high, you are overfitting the data. As mentioned in a previous comment, cmdscale only does linear MDS: if you specify the number of dimensions, the result is just truncated. MDS (linear multi-dimensional scaling) and PCA (principal component analysis) are identical: the only difference is that MDS starts with a distance matrix. $\endgroup$ Commented Jan 5, 2012 at 0:09
  • $\begingroup$ I don't believe this statement in your answer is correct: "It returns two numbers, that should be equal unless the distance matrix is not positive.". With positive non-euclidean distance matrices you could get negative eigenvalues and thus unequal numbers (stats.stackexchange.com/a/355465) $\endgroup$
    – Lulu
    Commented Jan 7, 2021 at 16:51
0
$\begingroup$

I personally prefer to measure goodness of fit using R squared, which cmdscale does not generate. I wrote some additional code to perform this; it is described and provided as the following entry in my "Cognition and Reality" blog post: Computing The Fit Of An MDS Solution Using R.

$\endgroup$
1
  • 3
    $\begingroup$ Welcome to the site. We are trying to build a permanent repository of high-quality statistical information in the form of questions & answers. Thus, we're wary of link-only answers, due to linkrot. Can you post the code here, or just the main ideas the code implements? At present, this is more of a comment than a complete answer by our standards. $\endgroup$ Commented Apr 28, 2015 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.