Statistics - Maple Help

Home : Support : Online Help : Statistics and Data Analysis : Statistics Package : Quantities : Statistics/AutoCorrelation

Statistics

 AutoCorrelation
 compute sample autocorrelations of a real Vector

 Calling Sequence AutoCorrelation(X) AutoCorrelation(X, lags)

Parameters

 X - discrete univariate real time series given as a Vector, list, Matrix with one column, or TimeSeries object with one dataset. lags - (optional) maximal lag to return, or a range of lags to return. By default all possible lags are returned.

Options

 • scaling
 One of biased, unbiased, or none.  Default is none. scaling=biased computes ${R}_{k}=\frac{{C}_{k}}{n}$. scaling=unbiased scales each ${C}_{k}$ by $\frac{1}{n-k}$.
 • raw
 If this option is given, the output is not normalized so that the first entry is 1 when scaling=unbiased or scaling=none.

Description

 • For a discrete time series X, the AutoCorrelation command computes the autocorrelations ${R}_{k}=\frac{{C}_{k}}{{C}_{0}}$ where ${C}_{k}={\sum }_{t=1}^{n-k}\left({X}_{t}-\mathrm{\mu }\right)\left({X}_{t+k}-\mathrm{\mu }\right)$ for $k=0..n-1$ and  $\mathrm{\mu }$ is the mean of X.
 • For efficiency, all of the lags are computed at once using a numerical discrete Fourier transform.  Therefore all data provided must have type realcons and all returned solutions are floating-point, even if the problem is specified with exact values.
 • Note: AutoCorrelation makes use of DiscreteTransforms[FourierTransform] and thus will work strictly in hardware precision, that is, its accuracy is independent of the setting of Digits.
 • For more time series related commands, see the TimeSeriesAnalysis package.

Examples

 > $\mathrm{with}\left(\mathrm{Statistics}\right):$
 > $\mathrm{AutoCorrelation}\left(⟨1,2,1,2,1,2,1,2⟩\right)$
 $\left[\begin{array}{c}{1.}\\ {-}{0.875000000009056}\\ {0.750000000020185}\\ {-}{0.625000000014873}\\ {0.500000000015000}\\ {-}{0.375000000015127}\\ {0.250000000009815}\\ {-}{0.125000000020944}\end{array}\right]$ (1)
 > $\mathrm{AutoCorrelation}\left(⟨1,2,1,2,1,2,1,2⟩,2\right)$
 $\left[\begin{array}{c}{1.}\\ {-}{0.875000000009056}\\ {0.750000000020185}\end{array}\right]$ (2)
 > $\mathrm{AutoCorrelation}\left(⟨1,2,1,2,1,2,1,2⟩,0..2\right)$
 $\left[\begin{array}{c}{1.}\\ {-}{0.875000000009056}\\ {0.750000000020185}\end{array}\right]$ (3)
 > $\mathrm{AutoCorrelation}\left(⟨1,2,1,2,1,2,1,2⟩,1..2\right)$
 $\left[\begin{array}{c}{-}{0.875000000009056}\\ {0.750000000020185}\end{array}\right]$ (4)
 > $\mathrm{AutoCorrelation}\left(⟨1,2,1,2,1,2,1,2⟩,2,'\mathrm{scaling}'='\mathrm{unbiased}'\right)$
 $\left[\begin{array}{c}{1.}\\ {-}{1.00000000001035}\\ {1.00000000002691}\end{array}\right]$ (5)
 > $\mathrm{AutoCorrelation}\left(⟨1,2,1,2,1,2,1,2⟩,2,'\mathrm{scaling}'='\mathrm{biased}'\right)$
 $\left[\begin{array}{c}{0.0624999999981250}\\ {-}{0.0546874999989254}\\ {0.0468749999998553}\end{array}\right]$ (6)
 > $\mathrm{AutoCorrelation}\left(⟨1,2,1,2,1,2,1,2⟩,2,'\mathrm{raw}'\right)$
 $\left[\begin{array}{c}{0.499999999985000}\\ {-}{0.437499999991403}\\ {0.374999999998843}\end{array}\right]$ (7)
 > $t≔\mathrm{TimeSeriesAnalysis}:-\mathrm{TimeSeries}\left(\left[\left[1,2,1,2,1,2,1,2\right],\left[8,7,6,5,4,3,2,1\right]\right],\mathrm{header}=\left["Sales","Profits"\right],\mathrm{enddate}="2012-01-01",\mathrm{frequency}="monthly"\right)$
 ${t}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{Sales, Profits}}\\ {\mathrm{8 rows of data:}}\\ {\mathrm{2011-06-01 - 2012-01-01}}\end{array}\right]$ (8)
 > $\mathrm{AutoCorrelation}\left({t}_{\left(\right)..\left(\right),"Sales"},2\right)$
 $\left[\begin{array}{c}{1.}\\ {-}{0.875000000009056}\\ {0.750000000020185}\end{array}\right]$ (9)

Autocorrelation can be used to create correlograms which are useful for detecting periodicity in signals.

 > $R≔\mathrm{AutoCorrelation}\left(⟨\mathrm{seq}\left(\frac{1\left(\mathrm{evalf}\left(\mathrm{sin}\left(17.2i\right)\mathrm{cos}\left(13.8i\right)+1.17\right)+\frac{\mathrm{rand}\left(0..1\right)\left(\right)\cdot 2}{3}\right)}{3},i=1..1000\right)⟩,200\right):$
 > $\mathrm{ColumnGraph}\left(R,'\mathrm{color}'="Gray",'\mathrm{style}'='\mathrm{polygon}'\right)$

Periodicity in a time series can be observed with Autocorrelation.

 > $\mathrm{with}\left(\mathrm{TimeSeriesAnalysis}\right):$
 > $\mathrm{Data}≔\mathrm{Import}\left(\mathrm{FileTools}:-\mathrm{JoinPath}\left(\left["datasets","sunspots.csv"\right],\mathrm{base}=\mathrm{datadir}\right),\mathrm{output}=\mathrm{Matrix}\right)$
 ${\mathrm{Data}}{:=}\left[\begin{array}{c}{\mathrm{315 x 2}}{\mathrm{Matrix}}\\ {\mathrm{Data Type:}}{\mathrm{anything}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (10)
 > $\mathrm{tsData}≔\mathrm{TimeSeries}\left({\mathrm{Data}}_{265..310,2}\right)$
 ${\mathrm{tsData}}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{data set}}\\ {\mathrm{46 rows of data:}}\\ {\mathrm{1970 - 2015}}\end{array}\right]$ (11)
 > $S≔\mathrm{AutoCorrelation}\left(\mathrm{tsData}\right)$
 ${S}{:=}\left[\begin{array}{c}{\mathrm{1 .. 46}}{{\mathrm{Vector}}}_{{\mathrm{column}}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (12)
 > $\mathrm{ColumnGraph}\left(S,'\mathrm{color}'="Gray",'\mathrm{style}'='\mathrm{polygon}'\right)$

Compatibility

 • The Statistics[AutoCorrelation] command was introduced in Maple 15.
 • The Statistics[AutoCorrelation] command was updated in Maple 2015.
 • The X parameter was updated in Maple 2015.