0

I'm new to MDS, but I found some good starter code here (http://mhermans.net/static/postdata/r-examples/neighbours-mds/neighbours-mds-example.html) and which I borrowed for below. The code works fine, but I would like to change the way I calculate my dissimilarity matrix.

The data I want to analyze is ecological time series, so I'd like to use a Spearman's Rank Correlation, as opposed to the co-occurrence matrix outlined from the above site. So given a simple data set of 10 species from 6 sites:

Site_1 <- c(1, 1, 1, 1, 1, 2, 2, 4, 8, 16)
Site_2 <- c(3, 4, 3, 2, 3, 5, 6, 10, 17, 33)
Site_3 <- c(5, 4, 5, 6, 5, 9, 8, 18, 33, 66)
Site_4 <- c(16, 15, 16, 14, 16, 15, 17, 13, 10, 1)
Site_5 <- c(5, 6, 5, 7, 5, 5, 4, 5, 3 ,5)
Site_6 <- c(16, 9, 3, 3, 2, 2, 1, 1, 1 ,1)

DF <- data.frame(Site_1, Site_2, Site_3, Site_4, Site_5, Site_6)
row.names(DF) <- c('S1','S2','S3','S4','S5','S6','S7',"S8",'S9','S10')

The code that works from the above site looks like this:

X <- as.matrix(DF)  # convert to matrix
C <- t(X) %*% X     # turn dummies into co-occurence matrix
D <- max(C) - C     # subtract max value to turn into dissimilarities
diag(D) <- 0                                # clear values on diagonal
Ds      <- as.dist(D, diag = T)             # convert to distance-object
fit     <- cmdscale(Ds, eig = TRUE, k = 2)  # MDS with 2 dimensions

x <- fit$points[, 1]
y <- fit$points[, 2]

plot(x,y)
text(x,y,labels=names(DF))

I was hoping I could change the dissimilarity matrix like so and still get a working MDS:

C   <- cor(DF, method="spearman")       #Calculate Spearman Rank Correlation
Ds  <- as.dist(C, diag = T)             # convert to distance-object
fit <- cmdscale(Ds, eig = TRUE, k = 2)  # MDS with 2 dimensions

x <- fit$points[, 1]
y <- fit$points[, 2]

plot(x,y)
text(x,y,labels=names(DF))

But the resulting plot no longer groups the sites according to a pattern of distances that makes sense to the original data. So I'm assuming I can't just substitute a Spearman's correlation in, and more globally, that I don't understand the difference between a co-occurrence matrix and correlation matrix. I hope you can help me out plotting a MDS that makes sense with a Spearman's correlation.

gung - Reinstate Monica
  • 132,789
  • 81
  • 357
  • 650
Vinterwoo
  • 183
  • 1
  • 1
  • 8
  • I can't help you with `R`, but can insure that you may use Spearman correlations. You are probably doing something wrong technically - most likely when converting into dissimilarity. – ttnphns Nov 30 '13 at 21:08
  • 1
    correlations (Spearman, or any other) are SIMILARITY measures - the higher, the closer the data is. cmdscale needs a DISSIMILARITY measure, like distance, - the higher the less closer the data is. – Jacques Wainer Nov 30 '13 at 23:02
  • Is it proper to run a Spearmans correlation as above, and then calculate a dissimilarity matrix by subtracting each value of the Spearmans matrix by the max value of the matrix (max(C)-C). Or us there a better way to calculate a dissimilarity matrix from a Spearman correlation? – Vinterwoo Dec 01 '13 at 03:20
  • 1
    The general, always working way is mentioned [here](http://stats.stackexchange.com/a/12925/3277). A particular way exploits the fact that Sperman rho is Pearson r mathematically (only for ranks), hence yo can convert it into euclidean d as explained [here](http://stats.stackexchange.com/a/36158/3277). – ttnphns Dec 01 '13 at 05:32

1 Answers1

1

I generated the dissimiliries (as mentioned by Jacques) this way:

Ds <- as.dist(-abs(cor(DF, method="spearman")) + 1, diag=TRUE)

Positive and negative correlations become 'identical' and become close to each other in the MDS

yhoogstrate
  • 126
  • 1