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? Thanks VN [[alternative HTML version deleted]]
Then you are posting in the wrong forum, since this is a forum about getting R
to do things for which you already understand the theory.
As to the results you are getting, I highly recommend reading the details
section of ?ccf.
BTW The Posting Guide indicates that you should post in text format because HTML
mutilates R code. This is a setting in your email program.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Venkatesh Nagarajan <gocanon at yahoo.com> 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?
>?
>Thanks
>VN
> [[alternative HTML version deleted]]
>
>
>
>------------------------------------------------------------------------
>
>______________________________________________
>R-help at 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.
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]]