compute sample cross-correlations of two time series - Maple Help

Home : Support : Online Help : Statistics : 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.

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}\phantom{\rule[-0.0ex]{5.0px}{0.0ex}}{\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

 > $\mathrm{with}\left(\mathrm{Statistics}\right):$
 > $\mathrm{CrossCorrelation}\left(⟨1,2,1,2⟩,⟨1,2,1,2⟩\right)$
 $\left[\begin{array}{c}{0.200000000062240}\\ {0.500000000030599}\\ {0.599999999986719}\\ {1.}\\ {0.599999999986719}\\ {0.500000000030599}\\ {0.200000000062240}\end{array}\right]$ (1)
 > $\mathrm{CrossCorrelation}\left(⟨1,2,1,2⟩,⟨1,2,1,2⟩,2\right)$
 $\left[\begin{array}{c}{0.500000000030599}\\ {0.599999999986719}\\ {1.}\\ {0.599999999986719}\\ {0.500000000030599}\end{array}\right]$ (2)
 > $\mathrm{CrossCorrelation}\left(⟨1,2,1,2⟩,⟨1,2,1,2⟩,-2..2\right)$
 $\left[\begin{array}{c}{0.500000000030599}\\ {0.599999999986719}\\ {1.}\\ {0.599999999986719}\\ {0.500000000030599}\end{array}\right]$ (3)
 > $\mathrm{CrossCorrelation}\left(⟨1,2,1,2⟩,⟨1,2,1,2⟩,2,\mathrm{scaling}=\mathrm{unbiased}\right)$
 $\left[\begin{array}{c}{1.00000000006120}\\ {0.799999999982292}\\ {1.}\\ {0.799999999982292}\\ {1.00000000006120}\end{array}\right]$ (4)
 > $\mathrm{CrossCorrelation}\left(⟨1,2,3⟩,⟨4,5⟩\right)$
 $\left[\begin{array}{c}{0.857142857196174}\\ {1.64285714296768}\\ {1.}\\ {0.357142857174354}\\ {2.32142559164592}{}{{10}}^{{-11}}\end{array}\right]$ (5)
 > $\mathrm{CrossCorrelation}\left(⟨1,2,3⟩,⟨4,5,0⟩\right)$
 $\left[\begin{array}{c}{0.857142857196174}\\ {1.64285714296768}\\ {1.}\\ {0.357142857174354}\\ {2.32142559164592}{}{{10}}^{{-11}}\end{array}\right]$ (6)
 > $\mathrm{CrossCorrelation}\left(⟨4,5⟩,⟨1,2,3⟩\right)$
 $\left[\begin{array}{c}{2.32142559164592}{}{{10}}^{{-11}}\\ {0.357142857174354}\\ {1.}\\ {1.64285714296768}\\ {0.857142857196174}\end{array}\right]$ (7)
 > $\mathrm{CrossCorrelation}\left(⟨4,5,0⟩,⟨1,2,3⟩\right)$
 $\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.

 > $\mathrm{t1}:=\mathrm{TimeSeriesAnalysis}:-\mathrm{TimeSeries}\left(\left[4,5,0\right],\mathrm{enddate}="2012-01-01",\mathrm{frequency}="monthly"\right)$
 ${\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)
 > $\mathrm{t2}:=\mathrm{TimeSeriesAnalysis}:-\mathrm{TimeSeries}\left(\left[1,2,3\right],\mathrm{enddate}="2015-09-30",\mathrm{frequency}="daily"\right)$
 ${\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)
 > $\mathrm{CrossCorrelation}\left(\mathrm{t1},\mathrm{t2}\right)$
 $\left[\begin{array}{c}{2.32142559164592}{}{{10}}^{{-11}}\\ {0.357142857174354}\\ {1.}\\ {1.64285714296768}\\ {0.857142857196174}\end{array}\right]$ (11)
 > $\mathrm{t3}:=\mathrm{TimeSeriesAnalysis}:-\mathrm{TimeSeries}\left(\left[\left[4,5,0\right],\left[1,2,3\right]\right],\mathrm{headers}=\left["Sales","Profits"\right],\mathrm{enddate}="2013-05-01",\mathrm{frequency}="weekly"\right)$
 ${\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)
 > $\mathrm{CrossCorrelation}\left({\mathrm{t3}}_{\left(\right)..\left(\right),"Sales"},{\mathrm{t3}}_{\left(\right)..\left(\right),"Profits"}\right)$
 $\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:=\mathrm{LinearAlgebra}:-\mathrm{RandomVector}\left(1000,\mathrm{datatype}=\mathrm{float}\right):$
 > $S:=\mathrm{CrossCorrelation}\left(\frac{1\left(2{L}_{101..1000}+{L}_{51..950}\right)}{3},{L}_{1..900},150,\mathrm{scaling}=\mathrm{unbiased},\mathrm{raw}\right):$
 > $\mathrm{ColumnGraph}\left(S,\mathrm{offset}=-151,\mathrm{color}="Gray",\mathrm{style}=\mathrm{polygon}\right)$