Here are 2 different way to realize Ljung Box test[1][2][3]:
1. statsmodels.stats.diagnostic.acorr_ljungbox[5]
from statsmodels.stats.diagnostic import acorr_ljungbox
data = ***
acorr_ljungbox(data, lags=None, boxpirece=False) #lags is the largest lag to report
2. pypr.stattest.ljungbox[4]
from pypr.stattest.jungbox import *
h, pV, Q, cV = lbqtest(x, range(1, 20), alpha=0.1)
problem “no module named ljungbox” occured when import pypr.stattest, find out the package files in ‘Lib/site-packages/pypr/stattest’, find out that all these files lying silently here:
The truth is only one:
__init__.py
from ljungbox import *
from model_select import *
it should be:
__init__.py
from .ljungbox import *
from .model_select import *
and now all fix!
[References]
- Box G E P, Pierce D A. Distribution of residual autocorrelations in autoregressive-integrated moving average time series models[J]. Journal of the American statistical Association, 1970, 65(332): 1509-1526.
- Ljung G M, Box G E P. On a measure of lack of fit in time series models[J]. Biometrika, 1978: 297-303.
- https://en.wikipedia.org/wiki/Ljung%E2%80%93Box_test
- http://pypr.sourceforge.net/stattest.html
- http://statsmodels.sourceforge.net/0.6.0/generated/statsmodels.stats.diagnostic.acorr_ljungbox.html