生若直木,不语斧凿.

LjungBox统计量两种实现方式

Posted on By xiaoyongsheng
Email: xiaoyongsheng@hotmail.com
Views:

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:

lbfile

 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]

  1. 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.
  2. Ljung G M, Box G E P. On a measure of lack of fit in time series models[J]. Biometrika, 1978: 297-303.
  3. https://en.wikipedia.org/wiki/Ljung%E2%80%93Box_test
  4. http://pypr.sourceforge.net/stattest.html
  5. http://statsmodels.sourceforge.net/0.6.0/generated/statsmodels.stats.diagnostic.acorr_ljungbox.html