Statsmodels Pacf Plot Confidence Interval Does Not Match Pacf Function
Solution 1:
according to the code:
stattools.pacf
computes the confidence interval around the estimated pacf, i.e. it's centered at the actual valuegraphics.tsa.plot_pacf
takes that confidence interval and subtracts the estimated pacf, So the confidence interval is centered at zero.
I don't know or remember why it was done this way.
In the example all pacf for lags larger or equal to 2 are close to zero, so there is no visible difference between plot and the results from stattools.pacf.
Solution 2:
The PACF for lag 0 is always 1 (see e.g. here), and hence its confidence interval is [1,1].
This is ensured by the last line of the code snippet where the CI is calculated:
varacf = 1. / len(x) # for all lags >=1
interval = stats.norm.ppf(1. - alpha / 2.) * np.sqrt(varacf)
confint = np.array(lzip(ret - interval, ret + interval))
confint[0] = ret[0] # fix confidence interval for lag 0 to varpacf=0
(See also issue 1969 where this was fixed).
As the 0 lag is of no interest you usually make the PACF plot start from lag 1 (as in R's pacf function). This can be achieved by zero=False
:
sm.graphics.tsa.plot_pacf(x, ax=axes[0], zero=True, title='zero=True (default)')
sm.graphics.tsa.plot_pacf(x, ax=axes[1], zero=False, title='zero=False')
Solution 3:
if I understood initial question correctly - why the CI numbers returned by ACF/PACF function does not match CI shown on graph (made by function plot_acf)? Answer is simple - CI on graph is centered around 0, it uses the ~same numbers that you get from acf/pacf functions.
Post a Comment for "Statsmodels Pacf Plot Confidence Interval Does Not Match Pacf Function"