P-value of cross-correlation

19 次查看(过去 30 天)
Sepp
Sepp 2018-8-23
Hello everybody
I have two time series Xa and Ya from which I'm calculating the cross-correlation vm2 in Matlab in the following way:
% after aligning signals, take the part of signal Xa with equal lentht of Ya
if length(Xa) > length(Ya)
[R2, lags2] = xcorr(Xa(1:length(Ya)),Ya,'coeff');
else
[R2, lags2] = xcorr(Ya(1:length(Xa)),Xa,'coeff');
end
[vm2, im2] = max(R2); % max. correlation and index
Unfortunately, I'm not getting a p-value from the xcorr method. Could I somehow first remove the lag which I retrieve from xcorr and then using corrcoef to get the correlation with p-value? Or how can I else calculate the p-value of the correlation of these two signals?

回答(2 个)

Jeff Miller
Jeff Miller 2018-8-24
If I understand, you are looking for the tail probability of vm2 within the Pearson's r distribution. That distribution doesn't seem to be supported by MATLAB, though they have many others used in hypothesis testing (t, F, chi-squared). The r distribution is included in Cupid , so if you download that you could potentially use
myR = r(min(length(Xa),length(Ya));
p = 1 - myR.CDF(vm2); % one-tailed, for positive r
% or, p = 2*(1 - myR.CDF(vm2)); % two-tailed, for positive r

Alex Backer
Alex Backer 2020-5-7
编辑:Alex Backer 2020-5-7
I found Jeff's code above was giving me p-values that seemed too low, even for random series, so I wrote some code to estimate the p-value empirically:
Alex Backer (2020). xcorrpvalue (https://www.mathworks.com/matlabcentral/fileexchange/75403-xcorrpvalue), MATLAB Central File Exchange.
Hope it helps.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by