statsmodels.graphics.tsaplots.plot_ccf

statsmodels.graphics.tsaplots.plot_ccf(x, y, *, ax=None, lags=None, negative_lags=False, alpha=0.05, use_vlines=True, adjusted=False, fft=False, title='Cross-correlation', auto_ylims=False, vlines_kwargs=None, **kwargs)[source]

Plot the cross-correlation function

Correlations between x and the lags of y are calculated.

The lags are shown on the horizontal axis and the correlations on the vertical axis.

Parameters:
x, yarray_like

Arrays of time-series values.

axAxesSubplot, optional

If given, this subplot is used to plot in, otherwise a new figure with one subplot is created.

lags{int, array_like}, optional

An int or array of lag values, used on the horizontal axis. Uses np.arange(lags) when lags is an int. If not provided, lags=np.arange(len(corr)) is used.

negative_lags: bool, optional

If True, negative lags are shown on the horizontal axis.

alphascalar, optional

If a number is given, the confidence intervals for the given level are plotted, e.g. if alpha=.05, 95 % confidence intervals are shown. If None, confidence intervals are not shown on the plot.

use_vlinesbool, optional

If True, shows vertical lines and markers for the correlation values. If False, only shows markers. The default marker is ‘o’; it can be overridden with a marker kwarg.

adjustedbool

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

fftbool, optional

If True, computes the CCF via FFT.

titlestr, optional

Title to place on plot. Default is ‘Cross-correlation’.

auto_ylimsbool, optional

If True, adjusts automatically the vertical axis limits to CCF values.

vlines_kwargsdict, optional

Optional dictionary of keyword arguments that are passed to vlines.

**kwargskwargs, optional

Optional keyword arguments that are directly passed on to the Matplotlib plot and axhline functions.

Returns:
Figure

The figure where the plot is drawn. This is either an existing figure if the ax argument is provided, or a newly created figure if ax is None.

Examples

>>> import pandas as pd
>>> import matplotlib.pyplot as plt
>>> import statsmodels.api as sm
>>> dta = sm.datasets.macrodata.load_pandas().data
>>> diffed = dta.diff().dropna()
>>> sm.graphics.tsa.plot_ccf(diffed["unemp"], diffed["infl"])
>>> plt.show()

Last update: Oct 03, 2024