 Statistics - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

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, DataSeries object, Matrix with one column, DataFrame 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

 > with(Statistics):
 > AutoCorrelation(<1,2,1,2,1,2,1,2>);
 $\left[\begin{array}{c}{1.}\\ {-0.875000000009056}\\ {0.750000000020185}\\ {-0.625000000014873}\\ {0.500000000015000}\\ {-0.375000000015127}\\ {0.250000000009815}\\ {-0.125000000020944}\end{array}\right]$ (1)
 > AutoCorrelation(<1,2,1,2,1,2,1,2>, 2);
 $\left[\begin{array}{c}{1.}\\ {-0.875000000009056}\\ {0.750000000020185}\end{array}\right]$ (2)
 > AutoCorrelation(<1,2,1,2,1,2,1,2>, 0..2);
 $\left[\begin{array}{c}{1.}\\ {-0.875000000009056}\\ {0.750000000020185}\end{array}\right]$ (3)
 > AutoCorrelation(<1,2,1,2,1,2,1,2>, 1..2);
 $\left[\begin{array}{c}{-0.875000000009056}\\ {0.750000000020185}\end{array}\right]$ (4)
 > AutoCorrelation(<1,2,1,2,1,2,1,2>, 2, scaling=unbiased);
 $\left[\begin{array}{c}{1.}\\ {-1.00000000001035}\\ {1.00000000002691}\end{array}\right]$ (5)
 > AutoCorrelation(<1,2,1,2,1,2,1,2>, 2, scaling=biased);
 $\left[\begin{array}{c}{0.0624999999981250}\\ {-0.0546874999989254}\\ {0.0468749999998553}\end{array}\right]$ (6)
 > AutoCorrelation(<1,2,1,2,1,2,1,2>, 2, raw);
 $\left[\begin{array}{c}{0.499999999985000}\\ {-0.437499999991403}\\ {0.374999999998843}\end{array}\right]$ (7)
 > t := TimeSeriesAnalysis:-TimeSeries([[1,2,1,2,1,2,1,2],[8,7,6,5,4,3,2,1]], header=["Sales", "Profits"], enddate="2012-01-01", frequency="monthly");
 ${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)
 > AutoCorrelation(t[.., "Sales"], 2);
 $\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 := :
 > LineChart(R, size=[0.5,"golden"]); > AutoCorrelationPlot(R, lags=100); Periodicity in a time series can be observed with Autocorrelation.

 > with(TimeSeriesAnalysis):
 > Data := Import( "datasets/sunspots.csv", base=datadir, output=Matrix );
  (10)
 > tsData := TimeSeries( Data[265..310, 2] );
 ${\mathrm{tsData}}{≔}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{data set}}\\ {\mathrm{46 rows of data:}}\\ {\mathrm{1974 - 2019}}\end{array}\right]$ (11)
 > S := AutoCorrelation(tsData);
  (12)
 > AutoCorrelationPlot(GetData(tsData)); Compatibility

 • The Statistics[AutoCorrelation] command was introduced in Maple 15.
 • For more information on Maple 15 changes, see Updates in Maple 15.
 • The Statistics[AutoCorrelation] command was updated in Maple 2015.
 • The X parameter was updated in Maple 2015.

 See Also