statsmodels.tsa.stattools.ccf#
- statsmodels.tsa.stattools.ccf(x, y, adjusted=True, fft=True, *, nlags=None, alpha=None, result_object=None)[source]#
The cross-correlation function
- Parameters:
- x, yarray_like
The time series data to use in the calculation.
- adjustedbool,
optional If True, then denominators for cross-covariance are the number of overlapping observations at each lag k, min(m, n-k), otherwise n.
- fftbool,
optional If True, use FFT convolution. This method should be preferred for long time series.
- nlags
int,optional Number of lags to return cross-correlations for. If not provided, the number of lags equals len(x).
- alpha
float,optional If a number is given, the confidence intervals for the given level are returned. For instance if alpha=.05, 95 % confidence intervals are returned where the standard deviation is computed according to 1/sqrt(len(x)).
- result_objectbool,
optional Flag controlling whether a
CcfResultis returned. Whenalphais not None aCcfResultis always returned; it holds the same two values as the legacy tuple it replaces. Whenalphais None a bare array is returned unlessresult_object=True, which additionally yields aCcfResultwithconfintset toNone.
- Returns:
CcfResultorndarrayWhen
alphais not None (orresult_object=True), a result object with fields:- ccfndarray
The cross-correlation function of x and y: the element at index k is the correlation between {x[k], x[k+1], …, x[n]} and {y[0], y[1], …, y[m-k]}, where n and m are the lengths of x and y, respectively.
- confintndarray or None
Confidence intervals for the CCF at lags 0, 1, …, nlags-1 using the level given by alpha and the standard deviation calculated as 1/sqrt(len(x)) [1]. Shape (nlags, 2).
Nonewhenalphais None.
See
CcfResult.When
alphais None a bare ndarray of cross-correlations is returned instead.
See also
statsmodels.tsa.stattools.pccfPartial cross-correlation function.
statsmodels.tsa.stattools.acfAutocorrelation function.
statsmodels.tsa.stattools.pacfPartial autocorrelation function.
statsmodels.graphics.tsaplots.plot_ccfPlot cross-correlations and confidence intervals.
Notes
If adjusted is True, the denominator for the cross-correlation is adjusted.
References
[1]Brockwell and Davis, 2016. Introduction to Time Series and Forecasting, 3rd edition, p. 242.