[R] NaN with ccf() for vector with all same element

colliera at ukzn.ac.za colliera at ukzn.ac.za
Mon Nov 27 15:42:45 CET 2006


hello,

i have been using ccf() to look at the correlation between lightning and electrogamnetic data. for the most part it has worked exactly as expected. however, i have come across something that puzzles me a bit:

> x <- c(1, 0, 1, 0, 1, 0)
> y <- c(0, 0, 0, 0, 0, 0)
> ccf(x, x, plot = FALSE)

Autocorrelations of series 'X', by lag

    -4     -3     -2     -1      0      1      2      3      4 
 0.333 -0.500  0.667 -0.833  1.000 -0.833  0.667 -0.500  0.333 
> ccf(x, y, plot = FALSE)

Autocorrelations of series 'X', by lag

 -4  -3  -2  -1   0   1   2   3   4 
NaN NaN NaN NaN NaN NaN NaN NaN NaN 
> y <- c(1, 1, 1, 1, 1, 1)
> ccf(x, y, plot = FALSE)

Autocorrelations of series 'X', by lag

 -4  -3  -2  -1   0   1   2   3   4 
NaN NaN NaN NaN NaN NaN NaN NaN NaN

i don't see why the result from ccf() would be NaN if the elements of y are all the same... perhaps i am just being silly or missing something. but if i work this out by hand, then i get a proper result. so, why not with ccf()?

thanks for the help!

best regards,
andrew.

-- 
Andrew B. Collier

Space Physics Group
Hermanus Magnetic Observatory

Antarctic Research Fellow                                   tel: +27 31 2601157
Space Physics Research Institute                            fax: +27 31 2616550
University of KwaZulu-Natal, Durban, 4041, South Africa     gsm: +27 83 3813655



More information about the R-help mailing list