({{, (RefLink[AutocorrelationTest, paclet:ref/AutocorrelationTest])[data]
tests whether the data is autocorrelated.}, {, (RefLink[AutocorrelationTest, paclet:ref/AutocorrelationTest])[data,k]
tests whether the data is autocorrelated up to lag k.}, {, (RefLink[AutocorrelationTest, paclet:ref/AutocorrelationTest])[data,k,"property"]
returns the value of "property\!\(\*StyleBox["\"", "TI"]\) for a given model.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[AutocorrelationTest, paclet:ref/AutocorrelationTest]) performs a hypothesis test for randomness on data with the null hypothesis (Subscript[H, 0]) that the autocorrelations (Subscript[ρ, 1])=(Subscript[ρ, 2])=…=(Subscript[ρ, k])==0 and alternative (Subscript[H, a]) that at least one of the (Subscript[ρ, i])≠0.

Rejecting the null hypothesis allows the conclusion that the data is not random.

By default, a probability value or p-value is returned.

A small p-value suggests that randomness is unlikely.

The data can be a list of values {(Subscript[x, 1]),(Subscript[x, 2]),…,(Subscript[x, n])} or a (RefLink[TemporalData, paclet:ref/TemporalData]) object.

The lag k can be (RefLink[Automatic, paclet:ref/Automatic]) or a positive integer such that k<n.

If k is not given, it is taken to be (RefLink[Automatic, paclet:ref/Automatic]).

Setting k to (RefLink[Automatic, paclet:ref/Automatic]) gives k=(RefLink[Ceiling, paclet:ref/Ceiling])[(RefLink[Log, paclet:ref/Log])[n]]].

(RefLink[AutocorrelationTest, paclet:ref/AutocorrelationTest])[data,k,"test"] reports the p-value according to "test".

The following tests can be used for univariate data with all paths of equal length n:

For multivariate data:

(RefLink[AutocorrelationTest, paclet:ref/AutocorrelationTest])[data,k,"HypothesisTestData"] returns a (RefLink[HypothesisTestData, paclet:ref/HypothesisTestData]) object htd that can be used to extract additional test results and properties using the form htd["property"].

(RefLink[AutocorrelationTest, paclet:ref/AutocorrelationTest])[data,k,"property"] can be used to directly give the value of "property".

Properties related to the reporting of test results include:

The following option can be used:

For unit root tests, a cutoff α is chosen such that (Subscript[H, 0]) is rejected only if p<α. The value of α used for the "TestConclusion" and "ShortTestConclusion" properties is controlled by the (RefLink[SignificanceLevel, paclet:ref/SignificanceLevel]) option. By default, α is set to 0.05.

OpenersPrimaryExamplesSection(Spacer1)Examples  (19)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Test whether data is random:

SeedRandom[0];
data=RandomFunction[ARProcess[{.3,.4},1],{1,50}];

ListLinePlot[data]

The data is autocorrelated:

AutocorrelationTest[data]

OpenersExampleSection1(Spacer1)Scope  (14)

OpenersExampleSubsection0(Spacer1)Testing  (10)

Test time-series data for autocorrelation:

SeedRandom[135];
nac=RandomFunction[ARProcess[{},1],{1,10000}];
ac=RandomFunction[ARProcess[{.1},1],{1,10000}];

The p-values are typically large when the data is not autocorrelated:

AutocorrelationTest[nac]

The p-values are typically small when the data is autocorrelated:

AutocorrelationTest[ac]

Test vector data:

SeedRandom[135];
data=RandomFunction[ARProcess[{},{{1,1/3},{1/3,2}}],{1,10000}]

data["ValueDimensions"]

AutocorrelationTest[data]

Test for autocorrelation up to lag 5:

SeedRandom[324];
data=RandomFunction[SARIMAProcess[{.3},1,{.2},{12,{.4},3,{.2}},1],{1,10^2}];

AutocorrelationTest[data,5]

Setting the lag to (RefLink[Automatic, paclet:ref/Automatic]) is equivalent to using (RefLink[Ceiling, paclet:ref/Ceiling])[(RefLink[Log, paclet:ref/Log])[n]]:

data=RandomVariate[NormalDistribution[],100];

AutocorrelationTest[data,Automatic]

AutocorrelationTest[data,Ceiling[Log[Length[data]]]]

Perform a particular test for autocorrelation:

data=TimeSeries[];

AutocorrelationTest[data,Automatic,"BoxPierce"]

Any number of tests can be performed simultaneously:

AutocorrelationTest[data,Automatic,{"BoxPierce","LjungBox"}]

Using (RefLink[Automatic, paclet:ref/Automatic]) applies the Ljung–Box test:

data=TimeSeries[];

AutocorrelationTest[data,Automatic,Automatic]

The property "AutomaticTest" can be used to show which test is used:

AutocorrelationTest[data,Automatic,"AutomaticTest"]

Perform all tests appropriate to the data simultaneously:

data=EventSeries[];

AutocorrelationTest[data,Automatic,All]

Use the property "AllTests" to identify which tests were used:

AutocorrelationTest[data,Automatic,"AllTests"]

Create a (RefLink[HypothesisTestData, paclet:ref/HypothesisTestData]) object for repeated property extraction:

data=EventSeries[];

ℋ=AutocorrelationTest[data,Automatic,"HypothesisTestData"];

The properties available for extraction:

ℋ["Properties"]

Extract some properties from the (RefLink[HypothesisTestData, paclet:ref/HypothesisTestData]) object:

data=TemporalData[];

ℋ=AutocorrelationTest[data,Automatic,"HypothesisTestData"];

The p-value and test statistic from the "LjungBox" test:

ℋ["PValue","LjungBox"]

ℋ["TestStatistic","LjungBox"]

Extract any number of properties simultaneously:

data=TemporalData[];

ℋ=AutocorrelationTest[data,Automatic,"HypothesisTestData"];

The p-value and test statistic from a Box–Pierce test:

ℋ[{"PValue","BoxPierce"},{"TestStatistic","BoxPierce"}]

OpenersExampleSubsection1(Spacer1)Reporting  (4)

Tabulate the results from a selection of tests:

data=TemporalData[];

ℋ=AutocorrelationTest[data,Automatic,"HypothesisTestData"];

A full table of all appropriate test results:

ℋ["TestDataTable",All]

A table of selected test results:

ℋ["TestDataTable","LjungBox"]

Retrieve the entries from a test table for customized reporting:

SeedRandom[1];
data=RandomVariate[NormalDistribution[],1000];

ℋ=AutocorrelationTest[data,Automatic,"HypothesisTestData"];

res=ℋ["TestData",All];

tests=ℋ["AllTests"]

The p-values are above 0.05, so there is not enough evidence to reject (Subscript[H, 0]) at that level:

Show[BarChart[res[[All,2]],ChartLabels->Placed[tests,Center],BarOrigin->Left],Graphics[Line[{{.05,0},{.05,Length[tests]+1}}]]]

Tabulate p-values for a test or group of tests:

data=TimeSeries[];

ℋ=AutocorrelationTest[data,Automatic,"HypothesisTestData"];

ℋ["PValueTable","LjungBox"]

The p-value from the table:

ℋ["PValue","LjungBox"]

A table of p-values from all appropriate tests:

ℋ["PValueTable",All]

A table of p-values from a subset of tests:

ℋ["PValueTable",{"LjungBox","BoxPierce"}]

Report the test statistic from a test or group of tests:

data=EventSeries[];

ℋ=AutocorrelationTest[data,Automatic,"HypothesisTestData"];

ℋ["TestStatisticTable"]

The test statistic from the table:

ℋ["TestStatistic"]

A table of test statistics from all appropriate tests:

ℋ["TestStatisticTable",All]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection2(Spacer1)SignificanceLevel  (1)

The significance level is used for "TestConclusion" and "ShortTestConclusion":

SeedRandom[40];
data=RandomVariate[NormalDistribution[],150];

ℋ1=AutocorrelationTest[data,Automatic,"HypothesisTestData",SignificanceLevel->.05];

ℋ2=AutocorrelationTest[data,Automatic,"HypothesisTestData",SignificanceLevel->.005];

ℋ1["TestConclusion","LjungBox"]//TraditionalForm

ℋ2["TestConclusion","LjungBox"]//TraditionalForm

ℋ1["ShortTestConclusion","LjungBox"]

ℋ2["ShortTestConclusion","LjungBox"]

OpenersExampleSection3(Spacer1)Applications  (2)

An instructor asked her students to generate a sequence of 100 random bits with the software of their choice. She warned that she would recognize bits that were not generated appropriately. The following data shows two such examples. One student used a random number generator as asked and the other scribbled down some bits just before class. Find which student is which:

student1={0,0,1,0,0,1,1,0,1,0,0,0,1,1,1,1,0,1,0,1,1,0,0,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,0,1,0,0,1,1,1,0,1,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,1,0,0,1,0,1,1,1,1,0,0,0,0,0,0,1,0,0,0,1,1,0,1,1,1,1,0,1,1,1,1,1};

student2={1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,0,1,0,1,0,0,0,1,1,0,1,1,0,1,0,1,0,1,1,1,1,0,0,1,0,0,1,0,1,0,1,0,1,1,1,0,0,1,0,0,1,0,1,0,1,0,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,0,1,0,1,0,0,0,1,1,0,1,1,0,1,0,1,0,1,1,1,0,0,1,0,0,1,0,1,0,1,0,1};

It appears that the second student did not do the assignment correctly:

AutocorrelationTest[student1]

AutocorrelationTest[student2]

Fit a time-series model to some monthly average temperature data for Chicago over a 10-year period. An adequate model should have uncorrelated residuals:

temp=TimeSeries[];

DateListPlot[temp,Joined->True]

The data is highly autocorrelated:

ListPlot[Table[AutocorrelationTest[temp,i],{i,1,10}],Filling->Axis]

tsm=TimeSeriesModelFit[temp]

The model residuals are uncorrelated, suggesting an adequate model was selected:

ListPlot[Table[AutocorrelationTest[tsm["FitResiduals"],i],{i,1,10}],Filling->Axis,PlotRange->{0,1}]

OpenersExampleSection4(Spacer1)Possible Issues  (1)

Only the first path of (RefLink[TemporalData, paclet:ref/TemporalData]) is tested:

data=TemporalData[];

data["PathCount"]

AutocorrelationTest[data]

Compare to testing only the first path:

AutocorrelationTest[data["Path",1]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[HypothesisTestData, paclet:ref/HypothesisTestData])  ▪  (RefLink[CorrelationFunction, paclet:ref/CorrelationFunction])  ▪  (RefLink[Correlation, paclet:ref/Correlation])  ▪  (RefLink[TimeSeriesModelFit, paclet:ref/TimeSeriesModelFit])  ▪  (RefLink[ARProcess, paclet:ref/ARProcess])  ▪  (RefLink[MAProcess, paclet:ref/MAProcess])  ▪  (RefLink[ARMAProcess, paclet:ref/ARMAProcess])  ▪  (RefLink[ARIMAProcess, paclet:ref/ARIMAProcess])  ▪  (RefLink[FARIMAProcess, paclet:ref/FARIMAProcess])  ▪  (RefLink[SARMAProcess, paclet:ref/SARMAProcess])  ▪  (RefLink[SARIMAProcess, paclet:ref/SARIMAProcess])  ▪  (RefLink[RandomFunction, paclet:ref/RandomFunction])  ▪  (RefLink[LocationTest, paclet:ref/LocationTest])  ▪  (RefLink[IndependenceTest, paclet:ref/IndependenceTest])  ▪  (RefLink[CovarianceFunction, paclet:ref/CovarianceFunction])  ▪  (RefLink[Covariance, paclet:ref/Covariance])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Time Series Processes, paclet:guide/TimeSeriesProcesses])}, {▪(RefLinkPlain[Hypothesis Tests, paclet:guide/HypothesisTests])}})}})