Consider $X$ to be a random variate with defined expectation $\mu$ and finite variance $\sigma^2$ . Consider a ton of points $X_1,X_2,..X_n$ generated via some process. The points need not be all independent of each other i.e there exists some auto-correlation amongst them.
We are interested in calculating the auto-correlation for some function $f$, which maps over these points, defined as
$$
\rho_h(f)=R_h(f)/R_0(f)$$
where
$$
R_h(f)=\frac{1}{n-h}\sum_{i=1}^{n-h}\left(f(x_i)-\langle f\rangle\right)(f(x_{i+h})-\langle f\rangle)\\
\langle f\rangle=\frac{1}{n}\sum_{i=1}^{n}f(x_i)$$
In particular consider $f(x)=x$.
Then
$$
\begin{align}
\rho_h&=\frac{\frac{1}{n-h}\sum_{i=1}^{n-h}(x_i-\mu)(x_{i+h}-\mu)}{\frac{1}{n}\sum_{i=1}^{n}(x_i-\mu)^2}\\
&\\
&=\frac{\langle (X_i-\mu)(X_{i+h}-\mu)\rangle}{\sigma^2}\tag1
\end{align}$$
However the ACF given by mathematica,CorrelationFunction
, is
$$
\rho_h=\frac{\sum_{i=1}^{n-h}(x_i-\mu)(x_{i+h}-\mu)}{\sum_{i=1}^{n}(x_i-\mu)^2}\tag 2$$
1. How to get the correct value (1) from (2)?
2. Is there some inbuilt option to get this correction instead of having to multiply (2) by $\frac{n}{n-h}$? The problem with this is I wish to calculate $\sum_h\rho_h$ using CorrelationFunction[..,{1,10^4}]
and so explicit casewise correction is awkward.
Update2
Currently using
ACFTotal[data_, {a_, b_}] :=
With[{n = Length@data},
CorrelationFunction[data, {a, b}].Array[1.0/(1.0 - #/n) &,
b - a + 1, a]]
test
rn = 10^4;
rPts = RandomFunction[ARMAProcess[1, {-.7, .1}, {.8}, 1], {0, rn}];
AbsoluteTiming[ACFTotal[rpts, {1, rn - 1}]]
(*{0.0157095, -4.44417}*)
compared to @JimB's
AbsoluteTiming[Sum[CorrelationFunction[rpts, h] rn/(rn - h), {h, rn - 1}]]
(* {95.271, -4.44417}*)
Update
Currently I am using
ACFTotal[data_, {a_, b_}] := With[{n = Length@data},CorrelationFunction[data,{a, b}].Array[1.0/(1.0 - #/n) &,b - a + 1, a]]
but its slow
CovarianceFunction
rather thanCorrelationFunction
? Please consider changing the title. The definition isn't wrong. It just isn't the one you want. $\endgroup$ – JimB Jan 23 '20 at 15:55ACFTotal
? Yes, I'm easily confused. For example your two definitions of $\rho_h$ use different notations. And theCorrelationFunction
uses $\bar{x}$ rather than $\mu$. $\endgroup$ – JimB Jan 23 '20 at 16:14