What equation is used in R ccf and Julia crosscor?

I scratch my head a lot. Now, except for the fact that Julia gives a seemingly opposite result in relation to delays

julia> crosscor([1,2,3,4], [1,2,3,1])'
1x7 Array{Float64,2}:
 -0.30339  0.0  0.64049  0.13484  -0.37081  -0.40452  0.30339

> print(ccf(c(1,2,3,4), c(1,2,3,1), type="correlation", plot=F))

Autocorrelations of series ‘X’, by lag

    -3     -2     -1      0      1      2      3 
 0.303 -0.405 -0.371  0.135  0.640  0.000 -0.303

      

which is easily solved by reversing x and y ("easy" relative, when it takes an hour of your life to figure out), the numbers are unlike any of the equations I'm familiar with (which anyway).

So, I opened my statistics textbook and found many other formulas that I am not going to test with pen and paper. I suspected for a moment that removing funds from vectors played a role, so I didn't try to do this (unfortunately, this can only be done in Julia)

julia> crosscor([1,2,3,4], [1,2,3,1], demean=false)'
1x7 Array{Float64,2}:
 0.188562  0.518545  0.942809  0.848528  0.518545  0.235702  0.0471405

      

but that still doesn't look like the normalized cross-correlation that I calculated with pen and paper (pending mistakes I could make).

In short: I need to cite a formula, so what is it?

+3


source to share


1 answer


I'm guessing quoting this excerpt here is ok with StackOverflow terms of use? On page 390 (section 14.1) of Venables and Ripley (2002), you can find the definition they use here for a function acf()

:

enter image description here



If you look at the source code for the function ccf()

in R (enter "ccf" at the prompt), you can see how it is used acf()

, and you can ask how the above implementation acf()

relates to calculation.

+3


source







All Articles