On 03/07/13 04:21, Venkatesh Nagarajan wrote:
> I am trying to understand lagged correlations.
>   
> x= 1:100;
> y = c(rep(NA,40), 1:60)ccf(x = x, y = y, lag.max=100, na.action=na.pass, type = "correlation")
>   
> I was hoping to see max cor at lag = 40. But I am not. What am I doing wrong?
Well, I would have expected the correlation to be equal to 1, at any 
(meaningful) lag.
Essentially the idea is cor(x,x+a) = 1 for any constant a.

Experimenting with cor(...,use="pair") and various lags would seem to 
bear this out.

Note that the help for acf/ccf says:
> The lag |k| value returned by |ccf(x, y)| estimates the correlation 
> between |x[t+k]| and |y[t]|. 

E.g. lag 40 (cor(x[t+40],y[t]):

     cor(x[41:140],y,use="pair") # Yields 1.

E.g. lag -40 (cor(x[t-40],y[t]):

     cor(c(rep(NA,40),x[1:60]),y,use="pair") # Yields 1.

So I am mystified by the output of ccf().

Perhaps someone would care to explain .....

Or perhaps not. :-)

     cheers,

         Rolf Turner

	[[alternative HTML version deleted]]

