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.

nlagsint, optional

Number of lags to return cross-correlations for. If not provided, the number of lags equals len(x).

alphafloat, 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 CcfResult is returned. When alpha is not None a CcfResult is always returned; it holds the same two values as the legacy tuple it replaces. When alpha is None a bare array is returned unless result_object=True, which additionally yields a CcfResult with confint set to None.

Returns:
CcfResult or ndarray

When alpha is not None (or result_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). None when alpha is None.

See CcfResult.

When alpha is None a bare ndarray of cross-correlations is returned instead.

See also

statsmodels.tsa.stattools.pccf

Partial cross-correlation function.

statsmodels.tsa.stattools.acf

Autocorrelation function.

statsmodels.tsa.stattools.pacf

Partial autocorrelation function.

statsmodels.graphics.tsaplots.plot_ccf

Plot 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.