# [R] Cross-correlation between two time series data

Spencer Graves spencer.graves at pdf.com
Tue Sep 5 01:00:44 CEST 2006

```Hi, Andrew:

This will produce a "permutation distribution" for the correlation
under the null hypothesis of zero correlation between the variables.
This is a reasonable thing to do, and would probably produce limits more
accurate than the dashed red lines on the 'ccf' plot.  However, they
would NOT be confidence interval(s).

For a confidence interval on cross correlation, you'd have to
hypothesize some cross correlation pattern between x and y, preferably
parameterized parsimoniously, then somehow determine an appropriate
range of values consistent with the data.  By the time you've done all
that, you've effectively fit some model and constructed confidence
intervals on the parameter(s).

Best Wishes,
Spencer

Andrew Robinson wrote:
> Jun,
>
> If your interest is to estimate the correlation and either a
> confidence interval or a test for no correlation, then you might try
> to proceed as follows.  This is a Monte-Carlo significance test, and a
> useful strategy.
>
> 1) use ccf() to compute the cross-correlation between x and y.
>
> 2) repeat the following steps, say, 1000 times.
>
> 2a) randomly reorder the values of one of the time series, say x.
>     Call the randomly reordered series x'.
>
> 2b) use ccf() to compute the cross-correlation between x' and y.
>     Store that cross-correlation.
>
> 3) the 1000 cross-correlation estimates computed in step 2 are all
>    estimating cross-correlation 0, conditional on the data.  A
>    two-tailed test then is: if the cross-correlation computed in step
>    1 is outside the (0.025, 0.975) quantiles of the empirical
>    distribution of the cross-correlations computed in step 2, then,
>    reject the null hypothesis that x and y are uncorrelated, with size
>    0.05.
>
> I hope that this helps.
>
> Andrew
>
>
> Juni Joshi wrote:
>
>>    Hi all,
>>
>>    I  have  two  time  series  data  (say  x  and  y). I am interested to
>>    calculate the correlation between them and its confidence interval (or
>>    to  test  no  correlation). Function cor.test(x,y) does the test of no
>>    correlation. But this test probably is wrong because of autocorrelated
>>    data.
>>
>>    ccf()  calculates the correlation between two series data. But it does
>>    not  provide  the  confidence intervals of cross correlation. Is there
>>    any  function  that  calculates the confidence interval of correlation
>>    between  two  time  series data or performs the test of no correlation
>>    between two time series data.
>>
>>    Thanks.
>>
>>    Jun
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help