14

I have two time series S, and T. they have the same frequency and the same length.

I would like to calculate (using R), the correlation between this pair (i.e. S and T), and also be able to calculate the significance of the correlation), so I can determine whether the correlation is due to chance or not.

I would like to do this in R, and am looking for pointers/skeletal framework to get me started.

morpheous
  • 605
  • 1
  • 8
  • 9
  • 3
    Are the time series both stationnary ? www.econ.ohio-state.edu/dejong/note1.pdf – user603 Oct 10 '10 at 11:54
  • @kwak: No, the series are both NOT stationary. – morpheous Oct 12 '10 at 17:49
  • Here: http://stats.stackexchange.com/questions/1881/analysis-of-cross-correlation-between-point-processes I was proposing a Monte Carlo approach to determine confidence limits. The idea was to do this for two point processes, but I guess it could be easily adapted for your situation. – nico Oct 13 '10 at 10:53

2 Answers2

6

You can use the ccf function to get the cross-correlation, but this will only give you a plot. If the estimated cross correlations fall outside the dash red line, then you can conclude that there is a statistically significant cross-correlation. But I do not know of a package with a formally encapsulated test. Example from ccf doc:

require(graphics)

## Example from Venables & Ripley (Provided in  CCF help file)
ccf(mdeaths, fdeaths, ylab = "cross-correlation")

Note, that the question of significance test is also discussed here.

M. Tibbits
  • 1,693
  • 14
  • 25
  • 1
    Other posters have noted that stationarity is important here. If both series have a linear upwards trend (one kind of nonstationarity), they will be correlated - but all the correlation may be due to the common trend, which may or may not be what we are interested in. – Stephan Kolassa Oct 21 '10 at 13:06
4

How do you define correlation for non stationary time series? Do you plan to take the correlation of the diff or these time series? If not, I suggest you look for cointegration rather than correlation (cf Granger etc...)

RockScience
  • 2,731
  • 4
  • 27
  • 46