[R] ccf and covariance

From: Bob Farmer <farmerb_at_gmail.com>
Date: Wed, 23 Apr 2008 11:42:38 -0300

It's my understanding that a cross-correlation function of vectors x and y at lag zero is equivalent to their correlation (or covariance, depending on how the ccf is defined).
If this is true, could somebody please explain why I get an inconsistent result between cov() and ccf(type = "covariance"), but a consistent result between cor() and ccf(type = "correlation")? Or have I misunderstood what is a cross-correlation? (unfortunately, I can't seem to get a look at the ccf code, since I think it's buried in some C function outside of the main environment)

Thanks very much.
--Bob Farmer
PhD candidate, Dalhousie University
Halifax, NS, Canada


d1<-data.frame(matrix(ldeaths, nrow = 6, byrow = T))

ccf(x=seventy_4, y=seventy_5,
  plot = F, lag.max = 0, type = "covariance"

cov(seventy_4, seventy_5) #inconsistent

ccf(x=seventy_4, y=seventy_5,
  plot = F, lag.max = 0, type = "correlation"

cor(seventy_4, seventy_5) #consistent

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. Received on Wed 23 Apr 2008 - 19:08:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 23 Apr 2008 - 20:31:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive