How to use this calculator
Check aggregate residual autocorrelation through a selected lag, with an explicit degrees-of-freedom adjustment.
- Enter Time-ordered residuals, Maximum lag, Fitted AR/MA parameter adjustment. Match the units shown beside each field and review the result together with the assumptions below.
- Read the worked example below to check the expected input format and result.
- Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
Ljung Box residual portmanteau test explained
The Ljung–Box statistic aggregates residual autocorrelation through the chosen maximum lag. Its approximate chi-square p-value is a diagnostic for remaining serial correlation, not a test that a model is otherwise correct.
Inputs, symbols, and units
x— Time-ordered residuals- Time-ordered residuals. Use comma-separated values in the stated order.
k— Maximum lag- Maximum lag. Enter a whole number.
d— Fitted AR/MA parameter adjustment- Fitted AR/MA parameter adjustment. Enter a whole number.
Formula and method
Q = n(n+2) Σₖ₌₁ᵐ rₖ²/(n−k), where rₖ is the sample autocorrelation at lag k and m is the maximum lag. The adjusted chi-square degrees of freedom are m minus the entered fitted-parameter count.
Residuals are demeaned and autocorrelations use the full centered sum-of-squares denominator. The chi-square approximation is asymptotic and requires positive adjusted degrees of freedom.
A worked scenario
Time-ordered residuals = 1, 0.5, -0.5, -1, 0.2, 0.8, -0.2, 0.3, -0.7, 0.1; Maximum lag = 2; Fitted AR/MA parameter adjustment = 0.
- Ljung–Box Q: 2.45566842
- Adjusted degrees of freedom: 2
- Approximate p-value: 0.29292631
Assumptions and edge cases
Residuals are demeaned; autocorrelations use the full centered sum-of-squares denominator. P-value is asymptotic and requires lag minus model adjustment >0.
Frequently asked questions
Does lag one check every lag?
No, choose the maximum lag of interest.
What does model adjustment mean?
For an ARMA residual diagnostic, it often accounts for fitted AR and MA parameters.
Does it prove a model is correct?
No, it addresses residual autocorrelation only.
How do I use the Ljung Box residual portmanteau test calculator?
Enter Time-ordered residuals, Maximum lag, Fitted AR/MA parameter adjustment. Match the units shown beside each field and review the result together with the assumptions below.
What is a worked example of Ljung Box residual portmanteau test?
Time-ordered residuals = 1, 0.5, -0.5, -1, 0.2, 0.8, -0.2, 0.3, -0.7, 0.1; Maximum lag = 2; Fitted AR/MA parameter adjustment = 0. Ljung–Box Q: 2.45566842 Adjusted degrees of freedom: 2 Approximate p-value: 0.29292631
Method reference: statsmodels Ljung–Box definition.
Read our calculation methodology.