marcopeix/TimeSeriesForecastingInPython

CH06 acorr_ljungbox

Opened this issue · 2 comments

When using the same code as the book for this test:

from statsmodels.stats.diagnostic import acorr_ljungbox
lbvalue, pvalue = acorr_ljungbox(residuals, np.arange(1, 11, 1))
print(pvalue)

This is what is returned (a string with no values):
lb_pvalue

Instead of a tuple, statsmodels acorr_ljungbox returns a dataframe now instead. The lbvalue is in one column while the pvalues on the other (on statsmodels 0.14.0).

I was going to report the same issue but see this has already been done. For those without much familiarity with pandas who have run into the same error, here's what works:

pvalue = acorr_ljungbox(residuals, np.arange(1, 11, 1))['lb_pvalue']

The Ljung-Box test statistics themselves are not used so there is no real need for any sort of unpacking.

Another solution is
lb_df= acorr_ljungbox(residuals, np.arange(1, 11, 1))