nancorr(A, B) is equivalent to matlab's corr(A, B, 'Rows', 'pairwise'), except nancorr routine is orders of magnitude faster on large matrices.
nancorr also returns t-statistics:
[coef, t] = nancorr(A, B); zmat = t;
These can be converted to p-values as follows:
[coef, t, n] = NANCORR(A, B);
pval = tcdf(-abs(t), n - 2)
Oleksandr Frei (2020). nancorr (https://www.mathworks.com/matlabcentral/fileexchange/71893-nancorr), MATLAB Central File Exchange. Retrieved .
MATLAB R2020a ... nancorr is no more faster than corrcoef!!!
>> s = rand(1e5,10);
>> tic;w = corrcoef(s,'rows','pairwise');toc
Elapsed time is 0.003665 seconds.
>> tic;w_ = nancorr(s,s);toc
Elapsed time is 0.015015 seconds.
Moreover, nancorr is numerically unstable (see Steve Smith note)!!!
Excellent - thanks. One minor buglette fix is below: this stops underflow/overflow in calculations from causing the output to become complex (which happened to me with my data):
% sx, sy - standard deviations
% sx = sqrt(x2 - n .* (mx.^2));
% sy = sqrt(y2 - n .* (my.^2));
sx = x2 - n .* (mx.^2); sx(sx<0)=0; sx=sqrt(sx);
sy = y2 - n .* (my.^2); sy(sy<0)=0; sy=sqrt(sy);