KamitaniLab / GenericObjectDecoding

Demo code for Horikawa and Kamitani (2017) Generic decoding of seen and imagined objects using hierarchical visual features. Nat Commun https://www.nature.com/articles/ncomms15037.
149 stars 47 forks source link

the difference between fastcorr and corrcoef #8

Closed zzstefan closed 5 years ago

zzstefan commented 6 years ago

Hi, recently I have been doing similar analysis on my own dataset. I wonder the difference between these two lines of code:

predAcc.image.perception = nanmean(diag(fastcorr(predPercept, testFeat))) predAcc.image.perception = corrcoef(predPercept, testFeat)

By using corrcoef, the prediction accuracy on my data can achieve much better results than using fastcorr.

ShuntaroAoki commented 6 years ago

Hi,

When given two matrixes (say, A and B), corrcoef regards A and B as two random variables and returns correlation between A and B. So, corrcoef(A, B) is equivalent to corrcoef(A(:), B(:)), and returns 2-by-2 matrix in which (1, 2) and (2, 1) are correlation coefficient between A and B.

On the other hand, factcorr returns column-wise correlation; each column in A and B is regarded as a single random variables. That is, factcorr(A, B) resutrns M-by-N matrix (where M = size(A, 2), N = size(B, 2)), and (i, j) element in the returned matrix is correlation coefficient between A(:, i) and B(:, j).

So, nanmean(diag(fastcorr(predPercept, testFeat))) takes correlation between predicted and true features for each unit and averages the correlation across all units, not just taking the correlation between predPercept(:) and testFeat(:).