P-value of cross-correlation
47 views (last 30 days)
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');
[R2, lags2] = xcorr(Ya(1:length(Xa)),Xa,'coeff');
[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?
Jeff Miller on 24 Aug 2018
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 on 7 May 2020
Edited: Alex Backer on 7 May 2020
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.