Ljung-box test using fixed lag value of 1 in ARIMA model
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from statsmodels/statsmodels
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
statsmodels/statsmodels#10271 ·
-
type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
statsmodels/statsmodels#10269 ·
-
Documentation
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
statsmodels/statsmodels#10266 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
statsmodels/statsmodels#9627 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
statsmodels/statsmodels#9293 · 1 comment ·
All issues in statsmodels/statsmodels
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100