Use the Ljung-Box q statistic to test whether a series of observations over time are random and independent. If observations are not independent, one observation can be correlated with a different observation k time units later, a relationship called autocorrelation. Autocorrelation can decrease the accuracy of a time-based predictive model, such as time series plot, and lead to misinterpretation of the data.
For example, an electronics company tracks monthly sales of batteries for five years. They want to use the data to develop a time series model to help forecast future sales. However, monthly sales might be affected by seasonal trends. For example, each year an increase in sales occurs when people buy batteries for Christmas toys. Thus a monthly sales observation in one year could be correlated with a monthly sales observations 12 months later (a lag of 12).
Before choosing their time series model, they can assess autocorrelation for the monthly differences in sales. The Ljung-Box Q (LBQ) statistic tests the null hypothesis that autocorrelations up to lag k equal zero (that is, the data values are random and independent up to a certain number of lags--in this case 12). If the LBQ is greater than a specified critical value, autocorrelations for one or more lags might be significantly different from zero, indicating the values are not random and independent over time.
LBQ is also used to assess assumptions after fitting a time series model, such as ARIMA, to ensure that the residuals are independent.
The Ljung-Box is a Portmanteau test and is a modified version of the Box-Pierce chi-square statistic.