Supposing I have a document-term matrix as scripted below:


txt1 <- c("this is a sample document about Computer Science", "Not all sample documents are about science, they can be about art too", "and sometimes they are just useless")
names(txt1) <- c("Doc1", "Doc2", "Doc3")
df1 <- data.frame(doc = names(txt1), texts = txt1, stringsAsFactors = FALSE)

a1 <- df1 %>% unnest_tokens(output = word, input = texts) %>% 
group_by(doc, word) %>% 
summarise(totals = n()) %>% 
ungroup %>% 
spread(word, totals, fill = 0) %>% 
select(-doc) %>% as.matrix %>% 
scale(center = TRUE, scale = TRUE) %>% 
dist.cosine %>%
cmdscale %>%

a1$name <- 1:nrow(a1)

ggplot(data = a1, aes(x = X1, y = X2)) + 
geom_text(aes(label = name))

Q1. Is it Statistically correct to apply Multi-dimensional scaling (in R, this is via cmdscale) or PCA on a Cosine Similarity matrix?
I think it is not, since Cosine Similarity is not a proper distance metric.

If the application is incorrect, could you please state why?
If the application is correct, could you again, please, state why?

Q2. Could you also state if z-score transformation is at all required for computing the cosine similarity?

  • 1
    $\begingroup$ It is perfetly fine to do PCA on cosines. Linear PCA is valid on any sscp-type similarity coefficient. PCA on cosines is PCA on unit-scaled (but not centered) variables. As for MDS, it needs distance, not similarity. If you decide on a reasonable, sound way to convert, you may they do MDS, metric or nonmetric, on any distance measure. Torgerson's MDS (PCoA) is more reasonable to do on Euclidean distance. Cosine (or any sscp-similarity) and euclidean distance are directly related. $\endgroup$ – ttnphns Oct 21 '16 at 20:11
  • $\begingroup$ @ttnphns thank you for the response. Would you like to add this as an answer? Or would you rather I add it on your behalf? $\endgroup$ – info_seeker Oct 22 '16 at 6:46
  • $\begingroup$ I won't post it as an answer just because it is too brief, w/o theory explicated,... maybe later. If you were satisfied see it as an answer. $\endgroup$ – ttnphns Oct 22 '16 at 9:28
  • $\begingroup$ @ttnphns I would certainly appreciate some elaboration, but it seems nobody else will be registering an answer, as the question has had less views from the community. $\endgroup$ – info_seeker Oct 22 '16 at 10:17
  • 1
    $\begingroup$ 1-(similarityMatrix) is euclidean d squared. Take the root. In general, MDS doesn't requite metricity. But metricity is always better - just because it is closer to the euclidean distances plotted on the map! $\endgroup$ – ttnphns Oct 22 '16 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.