Hi Mihnea, I'm afraid I don't have much time to look at this right now -- I'm sort of swamped for the next 5 days -- so I'm forwarding back to the list so more eyeballs pass over it. In general, you should always cc the list so the archives remain complete and so that you get a quicker response.
Michael On Sun, Oct 14, 2012 at 2:02 PM, Mihnea Constantinescu <mihnea.co...@gmail.com> wrote: > Hi Michael > > Thank you for the reply. I forgot to mention that I cbind() after applying > the lag() function and then ran the cor() on the new data object. I had > noticed too that lag() passed inside of the cor() is useless. > > I'm getting somehow closer to troubleshooting the observed difference... > > Have a nice day > Mihnea > > -----Original Message----- > From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] > Sent: Saturday, October 13, 2012 12:31 PM > To: Mihnea Constantinescu > Cc: r-help@r-project.org > Subject: Re: [R] ccf(x,y) vs. cor() of x and lagged values of y > > On Fri, Oct 12, 2012 at 12:28 AM, Mihnea Constantinescu > <mihnea.co...@gmail.com> wrote: >> Hi >> >> >> >> I'm computing the correlation between two time-series x_t and y_t-1 >> (time-series lagged using the lag(y,-1) function) using the cor() >> function and the returned value is different from the value of ccf() >> function at the same lag. Any ideas why this is so? > > I'd bet that you'd also find that > > cor(x,y) = cor(x, lag(y,-1)) > > ? That's because the effect of "lagging" seems to be discarded by > cor() which only looks at the data itself and doesn't align the > observations. The ccf() result is the one you want. > > Cheers, > Michael > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.