# Test for Serial Correlation

Generate random sample of an ARProcess.

 In[1]:= XarData = RandomFunction[ARProcess[{.3, .5, -.2}, 1], {1000}];

The estimated correlation function slowly decreases as a function of lag.

 In[2]:= XListPlot[CorrelationFunction[arData, {20}], Filling -> Axis, PlotRange -> All]
 Out[2]=

Test for serial correlation up to lag 10.

 In[3]:= XAutocorrelationTest[arData, 10, {"TestDataTable", All}]
 Out[3]=

The tests confirm that data is serially correlated.

 In[4]:= XAutocorrelationTest[arData, 10, {"TestConclusion", All}]
 Out[4]=

Now generate a random sample from a GARCHProcess.

 In[5]:= Xgarch = GARCHProcess[.4, {.3, .4}, {.2}]; BlockRandom[SeedRandom["Mathematica 10"]; garchData = RandomFunction[garch, {10^2}, 10^5];]

The values of the estimated correlation function at nonzero lags are very small.

 In[6]:= XListPlot[CorrelationFunction[garchData, {10}], Filling -> Axis, PlotRange -> All, PlotStyle -> PointSize[Medium]]
 Out[6]=

Check the first path with the AutocorrelationTest.

 In[7]:= XAutocorrelationTest[garchData["Path", 1], 10, {"TestDataTable", All}]
 Out[7]=
 In[8]:= XAutocorrelationTest[garchData["Path", 1], 10, {"TestConclusion", All}]
 Out[8]=

There is no serial correlation, but the slices are not independent.

 In[9]:= Xgarch0 = garchData["SliceData", 0];
 In[10]:= Xslices = Table[garchData["SliceData", k], {k, 1, 4}];

Check the independence between the slice at time zero and the four following slices using Hoeffding's independence test.

 In[11]:= XDistributeDefinitions[garch0]; LaunchKernels[]; tests = ParallelMap[ IndependenceTest[ garch0, #, {"ShortTestConclusion", "HoeffdingD"}] &, slices];

Show scattered plots of slice values at time zero and at other times and the conclusions of the test.

 Out[12]=

## Mathematica + Mathematica Online

Questions? Comments? Contact a Wolfram expert »