[R] NaN with ccf() for vector with all same element
Prof Brian Ripley
ripley at stats.ox.ac.uk
Mon Nov 27 17:12:28 CET 2006
On Mon, 27 Nov 2006, colliera at ukzn.ac.za wrote:
> 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()?
How do you get a non-zero value for the variance of y? Dividing zero by
zero is NaN, and that is what is happening here.
--
Brian D. Ripley, ripley at 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
More information about the R-help
mailing list