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

OpenersNotesSection(Spacer1)Details

(RefLink[CovarianceFunction, paclet:ref/CovarianceFunction]) is also known as autocovariance function.

The following specifications can be given for hspec:

(RefLink[CovarianceFunction, paclet:ref/CovarianceFunction]) at lag h for data with mean (OverHat[μ]) and data values (Subscript[x, i]) is given by:

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

(RefLink[CovarianceFunction, paclet:ref/CovarianceFunction]) for a process proc with mean function μ[t] and value x[t] at time t is given by:

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

(RefLink[CovarianceFunction, paclet:ref/CovarianceFunction])[proc,h] is defined only if proc is a weakly stationary process and is equivalent to (RefLink[CovarianceFunction, paclet:ref/CovarianceFunction])[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  (33)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Estimate the covariance function at lag 2:

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

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

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

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

Calculate the covariance function for a discrete-time process:

CovarianceFunction[BinomialProcess[p],s,t]

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

Calculate the covariance function for a continuous-time process:

CovarianceFunction[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 covariance function for some data at lag 9:

CovarianceFunction[Range[10],9]

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

CovarianceFunction[Range[10],{9}]

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

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

Compute the covariance function for a time series:

ts=TimeSeries[];

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

cov=CovarianceFunction[ts,{100}]

ListPlot[cov,Filling->Axis]

Estimate the covariance function for an ensemble of paths:

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

cov=CovarianceFunction[data,{50}];

ListPlot[cov,Filling->0]

Compare empirical and theoretical covariance functions:

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

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

ListPlot[CovarianceFunction[#,{10}]&/@{proc,data},Filling->{1->{2}},PlotStyle->PointSize[Medium],PlotLegends->{"process covariance","sample covariance"}]

Plot the cross-covariance for vector data:

proc=ARProcess[{{{.3,.1},{.6,.3}}},{{1,.3},{.3,.6}}];
data=RandomFunction[proc,{100}];
cov=CovarianceFunction[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 covariance function for a weakly stationary discrete-time process:

CovarianceFunction[ARProcess[{a},(σ^2)],s,t]

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

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

CovarianceFunction[ARProcess[{a},(σ^2)],h]

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

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

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

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

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

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

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

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

CovarianceFunction[BinomialProcess[p],s,t]

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

The covariance function depends on both time arguments:

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

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

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

CovarianceFunction[PoissonProcess[μ],s,t]

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

The covariance function depends on both time arguments:

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

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

The covariance 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[CovarianceFunction[#,h],{h,0,15},ExtentSize->1/2,PlotRange->All,PlotLabel->Head[#]]&/@{proc1,proc2,proc3,proc4}

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

proc=ARProcess[{{{.3,.1},{.6,.3}}},{{1,.3},{.3,.6}}];
cov=CovarianceFunction[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  (1)

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 covariance function of the data decays slowly:

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

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

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

OpenersExampleSection4(Spacer1)Properties & Relations  (14)

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

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

Calculate the sample covariance function:

CovarianceFunction[paths,{10}]

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

Covariance function for the process:

cov=CovarianceFunction[proc,{10}]

Plot both functions:

ListPlot[{scov,cov},Filling->0,PlotLegends->{"sample covariance","process covariance"}]

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

𝒫=WienerProcess[μ,σ];

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

CovarianceFunction[𝒫,s,t]

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

Sample covariance function at lag 0 is a variance estimator:

data=Range[10];
evar1=CovarianceFunction[data,0]

Compare to the estimate using (RefLink[Variance, paclet:ref/Variance]):

evar2=Variance[data]

The scaling factors are different:

(10 evar1)/(9evar2)

Sample covariance function is related to (RefLink[CorrelationFunction, paclet:ref/CorrelationFunction]):

data=Range[10];

CovarianceFunction[data,{9}]

Scaled sample correlation function:

CorrelationFunction[data,{9}] (CovarianceFunction[data,0])

%-%%

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

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

CovarianceFunction[data,{n-1}]

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

%-%%

Use (RefLink[Expectation, paclet:ref/Expectation]) to calculate the covariance function:

𝒫=WienerProcess[μ,σ];
m[s_]:=Mean[𝒫[s]]

Expectation[(x[s]-m[s])(x[t]-m[t]),x\[Distributed]𝒫,Assumptions->s>0&&t>0]

CovarianceFunction[𝒫,s,t]

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

Covariance function for equal times reduces to (RefLink[Variance, paclet:ref/Variance]):

𝒫=OrnsteinUhlenbeckProcess[μ,σ,θ];

CovarianceFunction[𝒫,t,t]

Variance[𝒫[t]]

%-%%

The covariance function c(s,t) is related to the (RefLink[AbsoluteCorrelationFunction, paclet:ref/AbsoluteCorrelationFunction]) r(s,t):

𝒫=WienerProcess[μ,σ];

AbsoluteCorrelationFunction[𝒫,s,t]

For r(s,t)==c(s,t)+μ(s) μ(t), the mean function is μ(t):

CovarianceFunction[𝒫,s,t]+Mean[𝒫[s]] Mean[𝒫[t]]

%-%%

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

𝒫=WienerProcess[μ,σ];

CovarianceFunction[𝒫,s,t]

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

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

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

The covariance function c(s,t) is related to the (RefLink[CorrelationFunction, paclet:ref/CorrelationFunction]) ρ(s,t):

𝒫=PoissonProcess[μ];
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])

%-%%//FullSimplify[#, s>0&&t>0]&

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

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

iproc=ToInvertibleTimeSeries@proc

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

Covariance 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 covariance functions:

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

(RefLink[PowerSpectralDensity, paclet:ref/PowerSpectralDensity]) of a time series is a transform of the covariance function:

proc=ARProcess[c,{a},(σ^2)];
cf=CovarianceFunction[proc,h]

Use (RefLink[FourierSequenceTransform, paclet:ref/FourierSequenceTransform]):

ft=FourierSequenceTransform[cf,h,z]

Compare to the power spectrum:

PowerSpectralDensity[proc,z]

FullSimplify[%-ft]

(RefLink[PowerSpectralDensity, paclet:ref/PowerSpectralDensity]) of data is a transform of the sample covariance function:

sample=Range[20];
n=Length[sample];
cov=CovarianceFunction[sample,{n-1}];
cov=Join[Reverse[Rest[cov]],cov];

Apply (RefLink[ListFourierSequenceTransform, paclet:ref/ListFourierSequenceTransform]):

ListFourierSequenceTransform[cov,w,-n+1]//ExpToTrig

Compare to SamplePowerSpectralDensity:

PowerSpectralDensity[sample,w]

%-%%//FullSimplify

OpenersExampleSection5(Spacer1)Possible Issues  (1)

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

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

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

%//FunctionExpand

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

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Random Processes, paclet:guide/RandomProcesses])}, {▪(RefLinkPlain[Fourier Analysis, paclet:guide/FourierAnalysis])}, {▪(RefLinkPlain[Stochastic Differential Equation Processes, paclet:guide/StochasticDifferentialEquationProcesses])}, {▪(RefLinkPlain[Time Series Processes, paclet:guide/TimeSeriesProcesses])}, {▪(RefLinkPlain[Probability & Statistics, paclet:guide/ProbabilityAndStatistics])}, {▪(RefLinkPlain[Queueing Processes, paclet:guide/QueueingProcesses])}})}})