# Ljung-Box Statistics for ARIMA residuals in R: confusing test results

I have a time series I am trying to forecast, for which I have used the seasonal ARIMA(0,0,0)(0,1,0)[12] model (=fit2). It is different from what R suggested with auto.arima (R calculated ARIMA(0,1,1)(0,1,0)[12] would be a better fit, I named it fit1). However, in the last 12 months of my time series my model (fit2) seems to be a better fit when adjusted (it was chronically biased, I have added the residual mean and the new fit seems to sit more snugly around the original time series. Here is the example of the last 12 months and MAPE for 12 most recent months for both fits:

The time series looks like this:

So far so good. I have performed residual analysis for both models, and here is the confusion.

The acf(resid(fit1)) looks great, very white-noisey:

However, Ljung-Box test doesn't look good for , for instance, 20 lags:

    Box.test(resid(fit1),type="Ljung",lag=20,fitdf=1)


I get the following results:

    X-squared = 26.8511, df = 19, p-value = 0.1082


To my understanding, this is the confirmation that the residuals are not independent ( p-value is too big to stay with the Independence Hypothesis).

However, for lag 1 everything is great:

    Box.test(resid(fit1),type="Ljung",lag=1,fitdf=1)


gives me the result:

    X-squared = 0.3512, df = 0, p-value < 2.2e-16


Either I am not understanding the test, or it is slightly contradicting to what I see on the acf plot. The autocorrelation is laughably low.

Then I checked fit2. The autocorrelation function looks like this:

Despite such obvious autocorrelation at several first lags, the Ljung-Box test gave me much better results at 20 lags, than fit1:

    Box.test(resid(fit2),type="Ljung",lag=20,fitdf=0)


results in :

    X-squared = 147.4062, df = 20, p-value < 2.2e-16


whereas just checking autocorrelation at lag1, also gives me the confirmation of the null-hypothesis!

    Box.test(resid(arima2.fit),type="Ljung",lag=1,fitdf=0)
X-squared = 30.8958, df = 1, p-value = 2.723e-08


Am I understanding the test correctly? The p-value should be preferrably smaller than 0.05 in order to confirm the null hypothesis of residuals independence. Which fit is better to use for forecasting, fit1 or fit2?

Additional info: residuals of fit1 display normal distribution, those of fit2 do not.

• You don't understand p-values, & are interpreting them the wrong way round. – Scortchi Jul 18 '13 at 14:36
• Yes, it could be the question of understanding. Could you please expand? For example, what exactly means if p-value is bigger than 0.5? I have read the definition of p-value (probability of obtaining statistics at least as extreme as the test statistic given that null hypotheses holds). How does it apply to Ljung-Box test? Does "at least as extreme" mean "larger than X squared"? I would be grateful for the example with my data, since significance testing has been challenging for me to understand. – zima Jul 18 '13 at 14:42
• The Ljung-Box test statistic (X-squared) gets larger as the sample auto-correlations of the residuals get larger (see its definition), & its p-value is the probability of getting a value as large as or larger than that observed under the null hypothesis that the true innovations are independent. Therefore a small p-value is evidence against independence. – Scortchi Jul 18 '13 at 14:58
• @Scortchi, I think I got it. But that also makes my test at lag=1 for fit1 fail. How could this be explained? I do not see any autocorrelation at lag=1. Is there an some sort of extremality of this test with small number of lags (very small sample)? – zima Jul 18 '13 at 15:07
• The Box-Ljung is an omnibus test of independence at all lags up to the one you specify. The degrees of freedom used is the no. lags minus the no. AR & MA parameters (fitdf) so you were testing against a chi-squared distribution with zero degrees of freedom. – Scortchi Jul 18 '13 at 15:28

You've interpreted the test wrong. If the p value is greater than 0.05 then the residuals are independent which we want for the model to be correct. If you simulate a white noise time series using the code below and use the same test for it then the p value will be greater than 0.05.

m = c(ar, ma)
w = arima.sim(m, 120)
w = ts(w)
plot(w)
Box.test(w, type="Ljung-Box")

• A short and neat explanation. +1 for the code example. – Dawny33 Aug 7 '15 at 8:10
• Your interpretation is not correct as well. A p-value of 0.05 means that you have 5% chance to make an error if you reject the null hypothesis of no auto-correlation until order 1 in your case. – DJJ Nov 19 '15 at 14:10

Many statistical tests are used to try to reject some null hypothesis. In this particular case the Ljung-Box test tries to reject the independence of some values. What does it mean?

• If p-value < 0.051: You can reject the null hypothesis assuming a 5% chance of making a mistake. So you can assume that your values are showing dependence on each other.

• If p-value > 0.051: You don't have enough statistical evidence to reject the null hypothesis. So you can not assume that your values are dependent. This could mean that your values are dependent anyway or it can mean that your values are independent. But you are not proving any specific possibility, what your test actually said is that you can not assert the dependence of the values, neither can you assert the independence of the values.

In general, what is important here is to keep in mind that p-value < 0.05 lets you reject of the null-hypothesis, but a p-value > 0.05 does not let you confirm the null-hypothesis.

In particular, you can not proof the independence of the values of Time Series using the Ljung-Box test. You can only prove the dependence.

1: I assumed $\alpha = 0.05$, which is a standard value of risk.

• Sorry I'm confused about your second point (p>0.05). When p>0.05 (assuming $\alpha=0.05$) we cannot reject the null hypothesis of independence. But you write "But you are not proving any possibility, you proved that both possibilit[i]es are still a chance". Can you explain it better? – utobi Nov 26 '16 at 14:06

According to the ACF graphs, it is obviously that the fit 1 is better since the correlation coefficient at lag k(k>1) drops sharply, and close to 0.

If you are judging with ACF then fit 1 is more appropriate. Instead of being confused on Ljung test you can still use the correlogram of the residuals to ascertain the best fit between fit1 and fit2

• I don't understand this answer. – Michael Chernick May 27 '18 at 23:03
• When we visit Ljung box statistics, we could be interested in model diagnostic check I.e, model adequacy..... If using that is confusing to you there are other ways to check model adequacy which I stated above. You can plot the correlogram I.e, ACF and PACF of the data residual and then check the bounds of the series if it is white noise...... It's not must to use Ljung box test – Vincent May 27 '18 at 23:23

## protected by kjetil b halvorsenMay 27 '18 at 22:10

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).