Correlating moving window averages. Spurious correlations.
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am taking moving window averages of two variables and then correlating the new data. I was noticing extreme pseudo-cyclical changes in the correlation values with changing window size. I injected random data instead into the algorithm and a very strong correlation appeared when the window size became large enough. This was reproducible with other random datasets. I am guessing this is simply because the windowed values tend toward the mean with increased size, but does anyone have experience with this or have a better idea of the dynamics involved.
Here is the main code. Inputs are one circular variable (phase angle 0-2π) and one linear variable.
for a = 1:2:(length(rt))-1
k=waitforbuttonpress;
window=a
j=1
for i = window:length(rt); % This loop
rt_std(j) = std(rt(j:i));%/mean(rt(j:i));
angs=resp_angles(j:i);
%av_ang(j)=mean(angs);
angs=mod(angs,2*pi); % convert -pi/+pi to 0-2pi
ang_sin = sin(angs);
ang_cos = cos(angs);
ang_sin_sum = sum(ang_sin);
ang_cos_sum = sum(ang_cos);
av_ang(j)=mod(atan2(ang_sin_sum,ang_cos_sum),2*pi); % average phase angles and convert to 0-2pi
%k=waitforbuttonpress;
j=j+1;
end
[r,p]=corrcoef(av_ang,rt_std)
This loops through for all iterations of window size from 1 to n step 2.
Thanks (:
4 Commenti
Michael Melnychuk
il 9 Mar 2020
If anyone is curious I came back to this topic a few months ago, and did extensive analysis on it. Basically, I found that if the moving window average is overlapped then spurious correlations tend to arise. If the window is not overlapped, however, the correlation does not tend to increase. I'm only jotting this down in case someone is looking for an answer to this question. I'm surprised it isn't more commonly asked.
Risposte (1)
Image Analyst
il 28 Gen 2016
Well we don't have your data so I can't say much. But what I can say is that a high correlation does not necessarily mean the signal and the template look like each other at that location. Unfortunately that is a very common misperception. All it means is that the sum of the products is a big number, which can happen for example if you have a huge noise spike in either the signal or template. And you said "I injected random data", so there you go.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!