Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to extract the points from a P/ACF graph in Python?

I'm using the statsmodels.graphics.tsaplots module to plot an ACF or a PACF graph using time series data. I've added an example plot below:

Example ACF Plot

Is there any way of getting the individual values for each lag (i.e. each blue circle), as well as the corresponding value of the blue area for each lag? The reason why I need the blue area values is that sometimes the area might expand over the higher lags. Example: ACF with growing blue area

I've tried Retrieve XY data from matplotlib figure but it did not help me in this instance.

The idea for this would be to automatically check the significance of each lag (i.e. if the lag is in the blue area or not)

Any help would be appreciated :)

Thank you

like image 902
AMSD Avatar asked Oct 15 '25 03:10

AMSD


1 Answers

You can get the numbers directly using the acf and pacf functions, by passing the alpha parameter. For example:

import statsmodels.api as sm

acf, ci = sm.tsa.acf(endog, alpha=0.05)
pacf, ci = sm.tsa.pacf(endog, alpha=0.05)

The confidence intervals are centered around the (P)ACF values, but you can re-center them around zero (to get the blue shaded region in the chart) by subtracting the (P)ACF values. See https://github.com/statsmodels/statsmodels/issues/6851#event-3511269194 for more details about that.

like image 128
cfulton Avatar answered Oct 17 '25 15:10

cfulton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!