Name

CORRCROIS — Extension of the corr function

Calling Sequence

[Res] = CORRCROIS(u,v,DecalMax,[NoNegVal])

Parameters

u

First variable (Matrix [Nx1])

v

Second variable (Matrix [Nx1])

DecalMax

Maximal value of the lag (positive integer)

NoNegVal

flag to exclude negative values (%t) or not (%f). Default = %f

Res

Result of the cross correlation analysis (Matrix [2*DecalMax+1 x 4], first column = lag, second column = r2, third/fourth column = coefficients of the linear regression)

Description

  • The function permit to locate the lag that optimises the cross correlation between two series.

    This function is different from corr because it allows negative lags. It is based on the function REGRESS_LIN

Examples

   // Two variables y1 and y2
   x=(0:0.1:10)';e=rand(size(x,1),1);
   y1=sin(x)+e;
   y2=sin(x+%pi/4)+e;
   
   // Cross lagged correlation
   R=CORRCROIS(y1,y2,20);
   
   // Plot
   subplot(2,1,1),plot([y1 y2])
   subplot(2,1,2),plot(R(:,1),R(:,2));xtitle('','Lag','r2');   
  

See Also

REGRESS_LIN , corr

Authors

Julien Lerat

CEMAGREF Antony, HBAN Unit, julien.lerat@cemagref.fr