Ljung-box test using fixed lag value of 1 in ARIMA model

Open
#7,349 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
data

Research direction

Start with the linked test_serial_correlation implementation in statsmodels/tsa/statespace/mlemodel.py and compare its lag choice with acorr_ljungbox and the ARIMA model summary. Trace how nobs_diffuse is used and determine whether the differing Ljung–Box results are expected; done means the lag and nobs_diffuse behavior is clearly explained or corrected.

Written by the indexing model from the issue text.

Description

comp-tsa-statespace question type-enh

I am using an ARIMA model to predict the time series values. I identify the best fit ARIMA model using the AIC value and it turns out that for all the different orders that I tried, the best AIC is returned for the ARIMA order (4, 0, 1).

As I am using statsmodels.tsa.arima.model.ARIMA package, I could see the description of the fitted model using model.summary() and I could observe the following results for tests:

===================================================================================
Ljung-Box (L1) (Q):                   0.00   Jarque-Bera (JB):              4412.50
Prob(Q):                              0.99   Prob(JB):                         0.00
Heteroskedasticity (H):               5.21   Skew:                            -0.01
Prob(H) (two-sided):                  0.00   Kurtosis:                        12.17
===================================================================================

I also manually ran the test using the statsmodels.stats.diagnostic.acorr_ljungbox and statsmodels.stats.stattools.jarque_bera packages respectively. I am using the following code snippet for the same:

jbTest = jarque_bera(model.resid)
print("JBTest:", jbTest)
lbTest = acorr_ljungbox(model.resid, model_df=p_+q_, lags=[20], boxpierce=False)
print("LBTest:", lbTest)

where, model is my best-fit ARIMA model and p_ and q_ are the respective orders of the model. The output from the snippet:

JBTest: (4412.481863170613, 0.0, -0.008442090306796898, 12.171354626003195)
LBTest: (array([32.85885778]), array([0.00490945]))

I can observe that the Jarque-Bera test output is close to the approximations from the model. However, it looks like the Ljunge-box test output is significantly small and does not match with the output from model. I am not sure if I am mis-interpreting the output from the model description versus the output from the acorr_ljungbox function.

However, when I changed my code to use lbTest = acorr_ljungbox(model.resid, lags=[1], boxpierce=False) instead of above snippet, I got values very close to the estimates from the model: LBTest: (array([0.000103]), array([0.9919025])). I did not understand why we are using the lag=1 as found in the class here.

Also, I am confused about the theoretical understanding of the nobs_diffuse value used in the test_serial_correlation function in same class. Any pointers would be really helpful!

I am using statsmodels version 0.12.2.

Dominant language
Python
Stars
11.6k
Forks
3.6k
Avg merge
7h 37m
Merged PRs (30d)
96

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from statsmodels/statsmodels

All issues in statsmodels/statsmodels

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.