s-news
[Top] [All Lists]

Re: Cross-correlation

To: Wayne E Thogmartin <wthogmartin@usgs.gov>
Subject: Re: Cross-correlation
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Date: Thu, 29 Apr 2004 22:14:11 +0100 (BST)
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <OFB20085B6.D2B978C2-ON86256E85.0072A1D5-86256E85.00731AE7@er.usgs.gov>
The S-PLUS acf function does this for you, so why not use it?
You will need to align your two series, e.g. by ts.intersect.
Example (uses the MASS library)

library(MASS)
x <- ts.intersect(mdeaths, fdeaths)
xx <- acf(x, plot=F)
dat <- c(rev(xx$acf[-1, 1, 2]), xx$acf[, 2, 1])
names(dat) <- round(c(rev(xx$lag[-1, 1, 2]), xx$lag[, 2, 1]),3)
dat

(Tested under S-PLUS 6.2, but I think will work under earlier versions.)

Those scripts are for a different task, confidence intervals.

On Thu, 29 Apr 2004, Wayne E Thogmartin wrote:

> I'd like to calculate the cross-correlation between 2 time series.  To
> date, I've been using scripts from
> http://www.stat.rutgers.edu/~rebecka/Spluscode/Splus.html.  My problem is
> that I'd like to extract the values of the cross-correlation at each lag,
> but have yet to figure out how to do that.  My amendments to the scripts
> have yet to allow me to pull out the cross-correlation coefficients.
> 
> Any notions (other than that I'm a bit beyond my element)?

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


<Prev in Thread] Current Thread [Next in Thread>