TL/DR:
temporaltestData = TemporalData[{testdata},Automatic];
r = CorrelationFunction[temporaltestData, {0, 1000}]["Values"];
Recap of Question
In your question, you have provided the code
testdata = RandomVariate[BinormalDistribution[{10, 20}, 0.4], {10000}];
AbsoluteTiming[
x = CorrelationFunction[testdata[[All, 1]], {0, 1000}];
y = CorrelationFunction[testdata[[All, 2]], {0, 1000}];
]
ListPlot[{x, y}, PlotRange -> {0, 1}]
and you found that this code finds the autocorrelations in the first and second components of your time series just fine. However, you also wanted to find the lagged cross-correlations between the first and second components.
Attempted solution
You attempted to do this with
r = CorrelationFunction[testdata, {0, 100}];
but you found that this doesn't work. I got an error that said
CorrelationFunction::tmpln: Uniformly spaced sampling expected in {{-3.38558,-24.5187},{-5.09168,-0.21692},{7.14122,14.2209},{-9.21681,19.2432},{8.15215,14.9583},{0.911419,-8.53165},{-19.1743,-22.1},{10.885,14.1329},{5.9896,3.49815},{9.51289,32.5084},<<31>>,{-1.15955,25.1969},{11.6961,13.6815},{-13.5907,-14.7231},{15.2179,17.0268},{4.61082,11.2426},{4.04496,-2.09691},{-0.278494,17.8067},{-4.02344,10.879},{19.5057,8.53984},<<9950>>}.
What I believe is happening is that mathematica is interpreting the first component as a time. You can try to get around this by prepending the times:
timedTestData = Prepend[testdata[[#]], #] & /@ Range@Length@testdata
r = CorrelationFunction[timedTestData, {0, 100}]
but now I get the error
CorrelationFunction::bdlag: The lag specification {0,100} should be a symbol, an integer with magnitude less than the length of the data, or a range specification indicating such integers.
which doesn't make sense.
Real solution
However, there is a way to find the correlation, as you can see by going to the help for CorrelationFunction
, and then going to Examples->Scope->Empirical Estimates, and looking at the last example in this section. The example is
proc = ARProcess[{{{.3, .1}, {.6, .3}}}, {{1, .3}, {.3, .6}}];
data = RandomFunction[proc, {100}];
cov = CorrelationFunction[data, {-6, 6}];
They have no problem taking the correlation of the multidimensional data set. This is because their data
is a TemporalData
object. So we must make one of our own. This can be done with
temporaltestData = TemporalData[{testdata},Automatic];
The brackets around testdata
are necessary because otherwise TemporalData
will treat testdata
as 10000 time series of length two instead of one 2D time series of length 10000. The second argument, Automatic
, just assigns consecutive integer times to each data point. Once the data is packaged in the TemporalData
object, CorrelationFunction
has a much easier time knowing what to do with it:
r = CorrelationFunction[temporaltestdata, {0, 1000}]["Values"]
Here, CorrelationFunction
returns a TimeSeries
object, which is a special kind of TemporalData
object. If we just want the list of lagged autocovariance matrices, we can access them by applying our time series object to "Values"
. Now we have our lagged autocovariances. Notice for example:
Norm@Chop[r[[;; , 1, 1]] - x]
gives 0
{{t1, x1}, ..., {tn, xn}}
. If I misunderstood your question and you want the n-dimensional autocorrelation for values sampled on a regular grid, rather than that for 1-d but unevenly spaced data, you can get it yourself usingListCorrelate
. $\endgroup$absCorr[lists_, n_] := Length@lists AbsoluteCorrelationFunction[#, n] & /@ Transpose@lists // Total
$\endgroup$