statsmodels.tsa.stattools.acf

statsmodels.tsa.stattools.acf(x, adjusted=False, nlags=None, qstat=False, fft=None, alpha=None, missing='none')[source]

Calculate the autocorrelation function.

Parameters
xarray_like

The time series data.

adjustedbool, default False

If True, then denominators for autocovariance are n-k, otherwise n.

nlagsint, default 40

Number of lags to return autocorrelation for.

qstatbool, default False

If True, returns the Ljung-Box q statistic for each autocorrelation coefficient. See q_stat for more information.

fftbool, default None

If True, computes the ACF via FFT.

alphascalar, default None

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 Bartlett”s formula.

missingstr, default “none”

A string in [“none”, “raise”, “conservative”, “drop”] specifying how the NaNs are to be treated. “none” performs no checks. “raise” raises an exception if NaN values are found. “drop” removes the missing observations and then estimates the autocovariances treating the non-missing as contiguous. “conservative” computes the autocovariance using nan-ops so that nans are removed when computing the mean and cross-products that are used to estimate the autocovariance. When using “conservative”, n is set to the number of non-missing observations.

Returns
acfndarray

The autocorrelation function.

confintndarray, optional

Confidence intervals for the ACF. Returned if alpha is not None.

qstatndarray, optional

The Ljung-Box Q-Statistic. Returned if q_stat is True.

pvaluesndarray, optional

The p-values associated with the Q-statistics. Returned if q_stat is True.

Notes

The acf at lag 0 (ie., 1) is returned.

For very long time series it is recommended to use fft convolution instead. When fft is False uses a simple, direct estimator of the autocovariances that only computes the first nlag + 1 values. This can be much faster when the time series is long and only a small number of autocovariances are needed.

If adjusted is true, the denominator for the autocovariance is adjusted for the loss of data.

References

1

Parzen, E., 1963. On spectral analysis with missing observations and amplitude modulation. Sankhya: The Indian Journal of Statistics, Series A, pp.383-392.