Search code examples
pythonmatlabcorrelationdata-analysissliding-window

Can someone teach me how to show that these two time series correlate?


I have the following two time series :

enter image description here

The x-axis is over 10000 values. Now, if I break them up into sliding windows, then I don't get a correlation since well, individually they aren't correlating. However, you can see that in the larger picture, they do correlate. I need to show this correlation. Can anyone please give me pointers on how to do this?

I am working in Matlab & Python, but I mainly need an overview really. Thanks!


Solution

  • I suggest two things to show the overall correlation, in Matlab. Let the x1, x2 vectors denote your data.

    • Compute c = corrcoef(x1,x2) and observe c(2,1). That's the correlation coefficient for the whole vectors. It measures correlation normalized between -1 and 1.
    • plot(x1,x2,'.','markersize',3). That draws a cloud of points, from which you can visually assess the correlation. For correlated x1 and x2, the points tend to form a more or less thin cloud along a straight line (see example shapes and its associated correlation coefficient)

    If your vectors contain NaN's, you should first remove them:

    ind = ~(isnan(x1)|isnan(x2));
    x1 = x1(ind);
    x2 = x2(ind);
    

    For example: the following two example vectors give c=0.91, and the cloud shape makes it obvious that there is significant correlation:

    Signals

    Cloud