({{, (RefLink[CorrelationFunction, paclet:ref/CorrelationFunction])[data,hspec] 
estimates the correlation function at lags hspec from data.}, {, (RefLink[CorrelationFunction, paclet:ref/CorrelationFunction])[proc,hspec]
represents the correlation function at lags hspec for the random process proc. }, {, (RefLink[CorrelationFunction, paclet:ref/CorrelationFunction])[proc,s,t]
represents the correlation function at times s and t for the random process proc. }})

OpenersNotesSection(Spacer1)Details

(RefLink[CorrelationFunction, paclet:ref/CorrelationFunction]) is also known as autocorrelation or cross-correlation function (ACF or CCF).

The following specifications can be given for hspec:

(RefLink[CorrelationFunction, paclet:ref/CorrelationFunction])[{(Subscript[x, 1]),…,(Subscript[x, n])},h] is equivalent to (∑_(i==1)^(n-h))((Subscript[x, i])-(OverHat[μ])) ((Subscript[x, i+h])-(OverHat[μ]))/(∑_(i=1)^n)((((Subscript[x, i])-(OverHat[μ])) )^2) with (OverHat[μ])=(RefLink[Mean, paclet:ref/Mean])[{(Subscript[x, 1]),…,(Subscript[x, n])}].

When data is (RefLink[TemporalData, paclet:ref/TemporalData]) containing an ensemble of paths, the output represents the average across all paths.

(RefLink[CorrelationFunction, paclet:ref/CorrelationFunction]) of the process proc is the (RefLink[CovarianceFunction, paclet:ref/CovarianceFunction]) c normalized by the outer product of the standard deviation function σ at times s and t:

The symbol ⊗ represents (RefLink[KroneckerProduct, paclet:ref/KroneckerProduct]).

(RefLink[CorrelationFunction, paclet:ref/CorrelationFunction])[proc,h] is defined only if proc is a weakly stationary process and is equivalent to (RefLink[CorrelationFunction, paclet:ref/CorrelationFunction])[proc,h,0].

The process proc can be any random process, such as (RefLink[ARMAProcess, paclet:ref/ARMAProcess]) and (RefLink[WienerProcess, paclet:ref/WienerProcess]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (32)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Estimate the correlation function at lag 2:

CorrelationFunction[{2,3,4,3},2]

The sample correlation function for a random sample from an autoregressive time series:

data=RandomFunction[ARProcess[{.2,.3,.4},1],{1,10^4}];

ListPlot[CorrelationFunction[data,{20}],Filling->Axis,PlotRange->All]

The correlation function for a discrete-time process:

CorrelationFunction[BinomialProcess[p],s,t]

DiscretePlot3D[Evaluate[%/.{p->2/3}],{s,1,10},{t,1,10},ExtentSize->1/2,ColorFunction->"Rainbow"]

The correlation function for a continuous-time process:

CorrelationFunction[WienerProcess[μ,σ],s,t]

Plot3D[Evaluate[%/.{μ->1,σ->2}],{s,0,10},{t,0,10},ColorFunction->"Rainbow"]

OpenersExampleSection1(Spacer1)Scope  (13)

OpenersExampleSubsection0(Spacer1)Empirical Estimates  (7)

Estimate the correlation function for some data at lag 9:

CorrelationFunction[Range[10],9]

Obtain empirical estimates of the correlation function up to lag 9:

CorrelationFunction[Range[10],{9}]

Compute the correlation function for lags 1 to 9 in steps of 2:

CorrelationFunction[Range[10],{1,9,2}]

Compute the correlation function for a time series:

ts=TimeSeries[];

The correlation function of a time series for multiple lags is given as a time series:

corr=CorrelationFunction[ts,{100}]

ListPlot[corr,Filling->Axis]

Estimate the correlation function for an ensemble of paths:

data=RandomFunction[ARProcess[{.8},1],{0,500},10]

corr=CorrelationFunction[data,{12}];

ListPlot[corr,Filling->0]

Compare empirical and theoretical correlation functions:

proc=MAProcess[{.4,.3,.5,.6,.3},1.];

data=RandomFunction[proc,{0,1000}];

ListPlot[TemporalData[CorrelationFunction[#,{10}]&/@{proc,data}],Filling->{1->{2}},PlotStyle->PointSize[Medium]]

Plot the cross-correlation for vector data:

proc=ARProcess[{{{.3,.1},{.6,.3}}},{{1,.3},{.3,.6}}];
data=RandomFunction[proc,{100}];
cov=CorrelationFunction[data,{-6,6}];

Table[ListPlot[cov["Values"][[All,i,j]],Filling->0,PlotLabel->{i,j}],{i,1,2},{j,1,2}]

OpenersExampleSubsection1(Spacer1)Random Processes  (6)

The correlation function for a weakly stationary discrete-time process:

CorrelationFunction[ARProcess[{a},(σ^2)],s,t]//PiecewiseExpand

DiscretePlot3D[Evaluate[%/.{a->2/3,σ->1}],{s,0,10},{t,0,10},ExtentSize->1/2,ColorFunction->"Rainbow"]

The correlation function only depends on the antidiagonal h==t-s:

CorrelationFunction[ARProcess[{a},(σ^2)],h]//PiecewiseExpand

DiscretePlot[Evaluate[%/.{a->2/3,σ->1}],{h,0,10},ExtentSize->1/2,ColorFunction->"Rainbow",AxesLabel->{h,None}]

The correlation function for a weakly stationary continuous-time process:

CorrelationFunction[OrnsteinUhlenbeckProcess[μ,σ,θ],s,t]

Plot3D[Evaluate[%/.{μ->1,σ->2,θ->1/3}],{s,0,10},{t,0,10},ColorFunction->"Rainbow"]

The correlation function only depends on the antidiagonal h==t-s:

CorrelationFunction[OrnsteinUhlenbeckProcess[μ,σ,θ],h]

Plot[Evaluate[%/.{μ->1,σ->2,θ->1/3}],{h,0,10},ColorFunction->"Rainbow",Filling->Axis,AxesLabel->{h,None}]

The correlation function for a non-weakly stationary discrete-time process:

CorrelationFunction[BinomialProcess[p],s,t]

DiscretePlot3D[Evaluate[%/.p->1/3],{s,1,10},{t,1,10},ExtentSize->1/2,ColorFunction->"Rainbow"]

The correlation function depends on both time arguments:

antidiagonals=CorrelationFunction[BinomialProcess[1/3],t,t+h]

DiscretePlot[Evaluate@Table[antidiagonals,{t,1,4}],{h,0,5},ExtentSize->1/2,PlotLegends->(Row[{"t = ", #}]&/@Range[1,4]),AxesLabel->{h,None}]

The correlation function for a non-weakly stationary continuous-time process:

CorrelationFunction[PoissonProcess[μ],s,t]

Plot3D[Evaluate[%/.μ->3],{s,0,10},{t,0,10},ColorFunction->"Rainbow"]

The correlation function depends on both time arguments:

antidiagonals=CorrelationFunction[PoissonProcess[3],t,t+h]

Plot[Evaluate@Table[antidiagonals,{t,1,4}],{h,0,5},PlotLegends->(Row[{"t = ",#}]&/@Range[1,4]),AxesLabel->{h,None}]

The correlation function for some time series processes:

proc1=ARProcess[{.8},1];
proc2=MAProcess[{-.4,-.7,.6,-1},1];
proc3=SARMAProcess[{},{},{3,{.6},{.1}},1];
proc4=FARIMAProcess[{},1/3,{},1];

DiscretePlot[CorrelationFunction[#,h],{h,0,15},ExtentSize->1/2,PlotRange->All,PlotLabel->Head[#]]&/@{proc1,proc2,proc3,proc4}

Cross-correlation plots for a vector (RefLink[ARProcess, paclet:ref/ARProcess]):

proc=ARProcess[{{{.3,.1},{.6,.3}}},{{1,.3},{.3,.6}}];
cov=CorrelationFunction[proc,h];

Table[DiscretePlot[cov[[i,j]],{h,-6,6},ExtentSize->1/2,PlotLabel->{i,j}],{i,1,2},{j,1,2}]

OpenersExampleSection3(Spacer1)Applications  (2)

Determine whether the following data is best modeled with an (RefLink[MAProcess, paclet:ref/MAProcess]) or an (RefLink[ARProcess, paclet:ref/ARProcess]):

ListLinePlot[data=TimeSeries[]]

It is difficult to determine the underlying process from sample paths:

candidates={MAProcess[{.5,.4},1],ARProcess[{.5,.4},1]};

SeedRandom[2];ListLinePlot[RandomFunction[#,{0,100}]]&/@candidates

The correlation function of the data decays slowly:

ListPlot[CorrelationFunction[data,{10}],Filling->0]

(RefLink[ARProcess, paclet:ref/ARProcess]) is clearly a better candidate model than (RefLink[MAProcess, paclet:ref/MAProcess]):

ListPlot[CorrelationFunction[#,{10}],PlotLabel->Head[#],Filling->0]&/@candidates

Create an ACF plot with white-noise confidence bands:

data=RandomFunction[MAProcess[{.6,.4,.5},.1],{1,500}];

acf[data_,lmax_,clev_:0.95]:=Show[ListPlot[CorrelationFunction[data,{0,lmax}],Filling->Axis,PlotRange->{{0,lmax},All},PlotStyle->PointSize[Medium]],
Graphics[{Dashed,Line[{{0,#},{lmax,#}}]}]&/@((Quantile[NormalDistribution[],{((1-clev)/2),1-((1-clev)/2)}])/(Sqrt[data["PathLengths"][[1]]]))]

Plot the correlation for lags 0 to 20 with 95% white-noise confidence bands:

acf[data,20,.95]

Compare to uncorrelated white noise:

acf[TemporalData[RandomVariate[NormalDistribution[],500],Automatic],20,.95]

OpenersExampleSection4(Spacer1)Properties & Relations  (12)

Sample correlation function is a biased estimator for the process correlation function:

proc=ARMAProcess[1,{5/6,-1/6},{2/3},1];
paths=RandomFunction[proc,{0,n=10},10^3];

Calculate the sample correlation function:

CorrelationFunction[paths,{10}]

scorr=TimeSeriesMapThread[#2(n+1)/(n+1-#1)&,%]

Correlation function for the process:

corr=CorrelationFunction[proc,{10}]

Plot both functions:

ListPlot[{scorr,corr},Filling->0]

Correlation function for a process is the off-diagonal entry in the (RefLink[Correlation, paclet:ref/Correlation]) matrix:

𝒫=WienerProcess[μ,σ];

Correlation[𝒫[{s,t}],1,2]

CorrelationFunction[𝒫,s,t]

Simplify[%%-%,0<s<t]

Sample correlation at lag 0 is always 1:

Simplify[CorrelationFunction[{x,y,z},0],{x,y,z}∈Reals]

Sample correlation function is related to (RefLink[CovarianceFunction, paclet:ref/CovarianceFunction]):

data=Range[10];

CorrelationFunction[data,{Length[data]-1}]

Scaled sample covariance function:

CovarianceFunction[data,{Length[data]-1}]/CovarianceFunction[data,0]

%-%%

Sample correlation function is related to (RefLink[AbsoluteCorrelationFunction, paclet:ref/AbsoluteCorrelationFunction]):

data=Range[10];
n=Length[data];

AbsoluteCorrelationFunction[data-Mean[data],{n-1}]

Scale by the first element:

%/First[%]

Compare to the sample correlation function:

CorrelationFunction[data,{n-1}]

%-%%

Use (RefLink[Expectation, paclet:ref/Expectation]) to calculate correlation:

𝒫=WienerProcess[μ,σ];

Define mean and standard deviation functions:

sd[s_]:=StandardDeviation[𝒫[s]]
m[s_]:=Mean[𝒫[s]]

Expectation[(x[s]-m[s])(x[t]-m[t])/(sd[s] sd[t]),x\[Distributed]𝒫]

CorrelationFunction[𝒫,s,t]

Simplify[%-%%,0<s<t]

Correlation function for equal times reduces to 1:

CorrelationFunction[PoissonProcess[μ],t,t]//Simplify[#,t>0]&

Correlation function ρ(s,t) is related to the (RefLink[CovarianceFunction, paclet:ref/CovarianceFunction]) c(s,t):

𝒫=OrnsteinUhlenbeckProcess[μ,σ,θ];
sd[s_]:=StandardDeviation[𝒫[s]]

CorrelationFunction[𝒫,s,t]

For ρ(s,t)==c(s,t)/(σ(s) σ(t)), the standard deviation function is σ(t):

CovarianceFunction[𝒫,s,t]/(sd[s] sd[t])

%-%%

The correlation function is related to the (RefLink[Correlation, paclet:ref/Correlation]):

𝒫=WienerProcess[μ,σ];

CorrelationFunction[𝒫,s,t]

It is the off-diagonal entry in the covariance matrix:

Correlation[𝒫[{s,t}],1,2]

Simplify[%%-%,0<s<t]

Correlation function is invariant for (RefLink[ToInvertibleTimeSeries, paclet:ref/ToInvertibleTimeSeries]):

TimeSeriesInvertibility[proc=MAProcess[{2,4},1]]

iproc=ToInvertibleTimeSeries@proc

CorrelationFunction[#,s,t]&/@{proc,iproc}

Correlation function is invariant to centralizing:

data=RandomFunction[ARIMAProcess[{},1,{},1],{0,100}];

The data has nonzero mean:

Mean[data]

Centralize data:

newdata=Standardize[data,Mean,1&];

Compare correlation functions:

ListPlot[CorrelationFunction[#,{20}],Filling->0]&/@{data,newdata}

Sum of the sample correlation function is constant:

n=100;
sample=RandomInteger[n,n];

The sample is random:

ListPlot[sample,Filling->Axis]

Calculate the sample correlation function from 1 to n-1:

corr=CorrelationFunction[sample,{1,n-1}];
ListLinePlot[corr]

Calculate the sum:

Total@corr

OpenersExampleSection5(Spacer1)Possible Issues  (1)

(RefLink[CorrelationFunction, paclet:ref/CorrelationFunction]) output may contain (RefLink[DifferenceRoot, paclet:ref/DifferenceRoot]):

CorrelationFunction[ARProcess[{a,b},(σ^2)],t] //Simplify[#,t>0]&

Use (RefLink[FunctionExpand, paclet:ref/FunctionExpand]) to recover explicit powers:

%//FunctionExpand

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[CovarianceFunction, paclet:ref/CovarianceFunction])  ▪  (RefLink[AbsoluteCorrelationFunction, paclet:ref/AbsoluteCorrelationFunction])  ▪  (RefLink[Correlation, paclet:ref/Correlation])  ▪  (RefLink[PartialCorrelationFunction, paclet:ref/PartialCorrelationFunction])  ▪  (RefLink[Covariance, paclet:ref/Covariance])  ▪  (RefLink[WeakStationarity, paclet:ref/WeakStationarity])  ▪  (RefLink[PowerSpectralDensity, paclet:ref/PowerSpectralDensity])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Time Series Processing, paclet:guide/TimeSeries])}, {▪(RefLinkPlain[Random Processes, paclet:guide/RandomProcesses])}, {▪(RefLinkPlain[Stochastic Differential Equation Processes, paclet:guide/StochasticDifferentialEquationProcesses])}, {▪(RefLinkPlain[Time Series Processes, paclet:guide/TimeSeriesProcesses])}})}})