Can anyone explain why these two correlation matrices return different results?
library(recommenderlab)
data(MovieLense)
cor_mat <- as( similarity(MovieLense, method = "pearson", which = "items"), "matrix" )
cor_mat_base <- suppressWarnings( cor(as(MovieLense, "matrix"), use = "pairwise.complete.obs") )
print( cor_mat[1:5, 1:5] )
print( cor_mat_base[1:5, 1:5] )
The
dissimilarity() = 1 - pmax(cor(), 0)R base function. Also, it is important to specify themethodfor both of them to use the same one:To understand it well, check the details of both packages :).
OP/ EDIT: It is important to point out that there are some values that are a little different between even
1-dissimilarityandcor, havingcorbigger than 1. This is becausedissimilarity()sets a floor at 0 (i.e., does not return negative numbers), and also doingcor()could return values greater than 1. https://www.rdocumentation.org/packages/stats/versions/3.6.0/topics/cor they only specify thatThis should be evaluated.