 Statistics - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

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

Statistics

 CrossCorrelation
 compute sample cross-correlations of two time series

 Calling Sequence CrossCorrelation(X1, X2) CrossCorrelation(X1, X2, lags)

Parameters

 X1, X2 - discrete univariate time series given as Vectors, lists, Matrices with one column, or TimeSeries objects 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-\left|k\right|}$.
 • raw
 If this option is given, the output is not normalized so that the middle entry (corresponding to ${R}_{0}$) is 1 when scaling=unbiased or scaling=none.

Description

 • For a discrete time series X1 and X2, the CrossCorrelation command computes the cross-correlations ${R}_{k}=\frac{{C}_{k}}{{C}_{0}}$ where ${C}_{k}={\sum }_{t=1}^{n-k}{\mathrm{X1}}_{t}\stackrel{&conjugate0;}{{\mathrm{X2}}_{t+k}}$ for $k=-n+1..n-1$.
 • For efficiency, all of the lags are computed at once using a numerical discrete Fourier transform.  Therefore all data provided must have type complexcons and all returned solutions are floating-point, even if the problem is specified with exact values.
 • If the inputs are not the same length, the shorter is padded with zeros at the end.
 • Note: CrossCorrelation 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):
 > CrossCorrelation(<1,2,1,2>,<1,2,1,2>);
 $\left[\begin{array}{c}{0.200000000062240}\\ {0.500000000030599}\\ {0.599999999986719}\\ {1.}\\ {0.599999999986719}\\ {0.500000000030599}\\ {0.200000000062240}\end{array}\right]$ (1)
 > CrossCorrelation(<1,2,1,2>,<1,2,1,2>, 2);
 $\left[\begin{array}{c}{0.500000000030599}\\ {0.599999999986719}\\ {1.}\\ {0.599999999986719}\\ {0.500000000030599}\end{array}\right]$ (2)
 > CrossCorrelation(<1,2,1,2>,<1,2,1,2>, -2..2 );
 $\left[\begin{array}{c}{0.500000000030599}\\ {0.599999999986719}\\ {1.}\\ {0.599999999986719}\\ {0.500000000030599}\end{array}\right]$ (3)
 > CrossCorrelation(<1,2,1,2>,<1,2,1,2>, 2, scaling=unbiased );
 $\left[\begin{array}{c}{1.00000000006120}\\ {0.799999999982292}\\ {1.}\\ {0.799999999982292}\\ {1.00000000006120}\end{array}\right]$ (4)
 > CrossCorrelation(<1, 2, 3>,<4, 5>);
 $\left[\begin{array}{c}{0.857142857196174}\\ {1.64285714296768}\\ {1.}\\ {0.357142857174354}\\ {2.32142559164592}{}{{10}}^{{-11}}\end{array}\right]$ (5)
 > CrossCorrelation(<1, 2, 3>,<4, 5, 0>);
 $\left[\begin{array}{c}{0.857142857196174}\\ {1.64285714296768}\\ {1.}\\ {0.357142857174354}\\ {2.32142559164592}{}{{10}}^{{-11}}\end{array}\right]$ (6)
 > CrossCorrelation(<4, 5>,<1,2,3>);
 $\left[\begin{array}{c}{2.32142559164592}{}{{10}}^{{-11}}\\ {0.357142857174354}\\ {1.}\\ {1.64285714296768}\\ {0.857142857196174}\end{array}\right]$ (7)
 > CrossCorrelation(<4, 5, 0>,<1,2,3>);
 $\left[\begin{array}{c}{2.32142559164592}{}{{10}}^{{-11}}\\ {0.357142857174354}\\ {1.}\\ {1.64285714296768}\\ {0.857142857196174}\end{array}\right]$ (8)

The CrossCorrelation command also accepts TimeSeries objects, but the date information is ignored.

 > t1 := TimeSeriesAnalysis:-TimeSeries([4, 5, 0], enddate="2012-01-01", frequency="monthly");
 ${\mathrm{t1}}{≔}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{data set}}\\ {\mathrm{3 rows of data:}}\\ {\mathrm{2011-11-01 - 2012-01-01}}\end{array}\right]$ (9)
 > t2 := TimeSeriesAnalysis:-TimeSeries([1, 2, 3], enddate="2015-09-30", frequency="daily");
 ${\mathrm{t2}}{≔}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{data set}}\\ {\mathrm{3 rows of data:}}\\ {\mathrm{2015-09-28 - 2015-09-30}}\end{array}\right]$ (10)
 > CrossCorrelation(t1, t2);
 $\left[\begin{array}{c}{2.32142559164592}{}{{10}}^{{-11}}\\ {0.357142857174354}\\ {1.}\\ {1.64285714296768}\\ {0.857142857196174}\end{array}\right]$ (11)
 > t3 := TimeSeriesAnalysis:-TimeSeries([[4,5,0], [1,2,3]], headers=["Sales", "Profits"], enddate="2013-05-01", frequency="weekly");
 ${\mathrm{t3}}{≔}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{Sales, Profits}}\\ {\mathrm{3 rows of data:}}\\ {\mathrm{2013-04-17 - 2013-05-01}}\end{array}\right]$ (12)
 > CrossCorrelation(t3[.., "Sales"], t3[.., "Profits"]);
 $\left[\begin{array}{c}{2.32142559164592}{}{{10}}^{{-11}}\\ {0.357142857174354}\\ {1.}\\ {1.64285714296768}\\ {0.857142857196174}\end{array}\right]$ (13)

CrossCorrelation can be used to create cross-correlograms

 > L := LinearAlgebra:-RandomVector(1000, datatype=float):
 > S := CrossCorrelation(1/3*(2*L[101..1000]+L[51..950]),L[1..900], 150, scaling=unbiased, raw):
 > ColumnGraph(S, offset=-151, color="Gray", style=polygon); Compatibility

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

 See Also