{
  "id": "ljung-box-test",
  "title": "Ljung–Box Test",
  "lang": "en",
  "source_lang": "en",
  "summary": "The Ljung–Box test assesses whether a time series exhibits autocorrelation across a specified set of lags, commonly as a diagnostic check on fitted-model residuals.",
  "category": "mathematics",
  "subcategory": "probability-statistics",
  "type": "concept",
  "aliases": [
    "Ljung–Box Q test",
    "Ljung–Box portmanteau test",
    "Modified Box–Pierce test"
  ],
  "generated_at": "2026-11-06",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/ljung-box-test/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/ljung-box-test/",
      "json": "https://aiwiki.page/zh/ljung-box-test.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "The Ljung–Box test is a statistical hypothesis test used to assess whether a time series has nonzero autocorrelations over a specified range of lags. It combines several estimated autocorrelations into one statistic, rather than testing each lag separately. A common application is checking whether the residuals of a fitted time-series model retain serial correlation that the model has not explained. The test concerns linear dependence across time; it is not a general test of randomness or independence."
    },
    {
      "heading": "Hypotheses and scope",
      "text": "For a weakly stationary process, let \\(\\rho_k\\) denote the population autocorrelation at lag \\(k\\), the correlation between observations separated by \\(k\\) time steps. For a chosen maximum lag \\(h\\), the null hypothesis is\n\n\\[H_0:\\rho_1=\\rho_2=\\cdots=\\rho_h=0.\\]\n\nThe alternative is that at least one of these autocorrelations is nonzero.\n\nThe test is called a portmanteau test because it combines evidence across multiple lags into a single assessment. Rejection indicates evidence against the joint hypothesis, but does not identify which lags account for the result.\n\nZero autocorrelation is weaker than statistical independence. A process can have no linear correlation between observations at different times while still exhibiting nonlinear dependence. Consequently, failing to reject the null does not establish that the observations are independent or that every aspect of a fitted model is adequate."
    },
    {
      "heading": "Test statistic",
      "text": "For observations \\(x_1,\\ldots,x_n\\), define the sample mean as\n\n\\[\\bar{x}=\\frac{1}{n}\\sum_{t=1}^{n}x_t.\\]\n\nA commonly used sample autocorrelation at lag \\(k\\) is\n\n\\[\\widehat{\\rho}_k = \\frac{ \\sum_{t=k+1}^{n}(x_t-\\bar{x})(x_{t-k}-\\bar{x}) }{ \\sum_{t=1}^{n}(x_t-\\bar{x})^2 }.\\]\n\nThe Ljung–Box test statistic is\n\n\\[Q_{\\mathrm{LB}} = n(n+2)\\sum_{k=1}^{h} \\frac{\\widehat{\\rho}_k^{\\,2}}{n-k}, \\qquad 1\\leq h<n.\\]\n\nHere, \\(n\\) is the number of observations entering the calculation and \\(h\\) is the maximum lag included. When applied to model residuals, \\(n\\) is the number of usable residuals.\n\nEach autocorrelation is squared, so positive and negative autocorrelations both increase the statistic. The denominator \\(n-k\\) reflects the declining number of observation pairs at higher lags. Large values of \\(Q_{\\mathrm{LB}}\\) provide evidence against the null hypothesis.\n\nReference distribution\n\nFor independent, identically distributed observations with finite, nonzero variance, and with \\(h\\) fixed as \\(n\\) increases, the null sampling distribution is asymptotically\n\n\\[Q_{\\mathrm{LB}}\\ \\overset{d}{\\longrightarrow}\\ \\chi_h^2.\\]\n\nThus, the statistic is commonly compared with a chi-squared distribution with \\(h\\) degrees of freedom. The upper-tail p-value is\n\n\\[p=\\Pr\\!\\left(\\chi_h^2\\geq Q_{\\mathrm{LB,obs}}\\right).\\]\n\nAt significance level \\(\\alpha\\), the null is rejected when \\(p<\\alpha\\).\n\nThis calibration requires more than zero autocorrelations alone. Under some forms of dependent but uncorrelated data, particularly processes with time-varying conditional variance, the usual chi-squared reference distribution may be inappropriate."
    },
    {
      "heading": "Use with fitted time-series models",
      "text": "A principal use of the test is checking residuals from an autoregressive integrated moving-average model, or ARIMA model. A model that adequately captures the series’ linear temporal structure should leave residuals without systematic autocorrelation.\n\nParameter estimation changes the distribution of residual autocorrelations. For residuals from a fitted nonseasonal ARMA\\((p,q)\\) model, a conventional approximation uses\n\n\\[Q_{\\mathrm{LB}}\\approx\\chi^2_{h-p-q},\\]\n\nrather than \\(\\chi_h^2\\). Here, \\(p\\) is the autoregressive order and \\(q\\) is the moving-average order. This approximation is typically used when \\(h\\) is sufficiently greater than \\(p+q\\); it is not an exact finite-sample result.\n\nFor seasonal ARIMA models with seasonal autoregressive and moving-average orders \\(P\\) and \\(Q\\), a common convention uses\n\n\\[\\nu=h-(p+q+P+Q).\\]\n\nThe differencing orders are not ordinarily included in this subtraction. The resulting degrees of freedom must be positive.\n\nThese adjustments are model-specific conventions, not a universal instruction to subtract every estimated coefficient. Models containing regression terms, complex seasonal structures, or other fitted components may require different treatment. Software implementations can also differ in how they count fitted parameters.\n\nA significant result suggests remaining serial correlation, which may reflect omitted dynamics, an inadequate seasonal specification, or another form of misspecification. A nonsignificant result means only that the selected test did not detect autocorrelation through lag \\(h\\); it does not establish accurate forecasts, normally distributed errors, or correct variance dynamics."
    },
    {
      "heading": "Choosing the lag range",
      "text": "The maximum lag \\(h\\) determines which departures the test can detect.\n\n- Small \\(h\\): concentrates on short-range dependence but can miss longer-lag or seasonal patterns.\n- Larger \\(h\\): includes a broader range of dependence, but adds degrees of freedom and may reduce power against alternatives concentrated at a few lags.\n- Seasonal data: including relevant seasonal lags can help detect patterns that a short-lag test would miss.\n\nFor a fixed dataset, \\(Q_{\\mathrm{LB}}\\) increases or remains unchanged as \\(h\\) increases. Its p-value need not decrease, because the reference distribution’s degrees of freedom also change.\n\nLag selection is therefore part of the test specification. Examining many lag cutoffs and reporting only a significant result introduces a multiple-testing issue. A sample autocorrelation plot can help locate patterns, but individual-lag assessments are not equivalent to the joint Ljung–Box test."
    },
    {
      "heading": "Numerical example",
      "text": "Suppose a series of \\(n=100\\) observations has sample autocorrelations\n\n\\[\\widehat{\\rho}_1=0.20,\\qquad \\widehat{\\rho}_2=0.10,\\qquad \\widehat{\\rho}_3=0.05.\\]\n\nTesting through lag \\(h=3\\) gives\n\n\\[\\begin{aligned} Q_{\\mathrm{LB}} &=100(102) \\left( \\frac{0.20^2}{99} +\\frac{0.10^2}{98} +\\frac{0.05^2}{97} \\right)\\\\ &\\approx 5.42. \\end{aligned}\\]\n\nIf these are observations rather than residuals requiring a model-fitting adjustment, the conventional reference distribution has three degrees of freedom. Its 5% upper-tail critical value is approximately \\(7.81\\), so the null is not rejected at that level. This does not imply that all three population autocorrelations are exactly zero."
    },
    {
      "heading": "Relationship to the Box–Pierce test",
      "text": "The Ljung–Box test modifies the earlier Box–Pierce test, whose statistic is\n\n\\[Q_{\\mathrm{BP}} = n\\sum_{k=1}^{h}\\widehat{\\rho}_k^{\\,2}.\\]\n\nThe two statistics are asymptotically equivalent for fixed \\(h\\), because\n\n\\[\\frac{n(n+2)}{n-k}\\sim n\\]\n\nas \\(n\\) increases. The Ljung–Box weighting was designed to improve the finite-sample approximation to the reference distribution. It is therefore widely used in place of the original Box–Pierce statistic, although its chi-squared calibration remains approximate.\n\nThe modification was introduced by Greta M. Ljung and George E. P. Box in their 1978 paper On a Measure of Lack of Fit in Time Series Models."
    },
    {
      "heading": "Limitations and related diagnostics",
      "text": "Nonlinear dependence. An uncorrelated series may still have dependence in its squared values or other transformations. Applying a Ljung–Box test to squared residuals is a common diagnostic for some forms of volatility dependence, but it tests a different hypothesis from a test on the residuals themselves.\n\nConditional heteroskedasticity. Changes in conditional variance can affect the sampling distribution of the statistic even when raw observations are serially uncorrelated. Robust portmanteau procedures or appropriately designed bootstrap methods may be used in such settings.\n\nSmall samples and large lag ranges. The finite-sample correction does not make the test exact. Its reference approximation can be inaccurate when the sample is short, the lag range is large relative to the sample size, or the fitted model is complex.\n\nNonstationarity and structural change. Trends, changing seasonal patterns, or structural breaks can generate autocorrelation that does not correspond to a stable stationary dependence structure. The test does not distinguish these explanations.\n\nDistributional shape. Normality is not the null hypothesis. The test neither establishes nor directly assesses whether observations or residuals follow a normal distribution.\n\nIrregular observation times. The standard formulation assumes that a lag represents a consistent time interval. Missing observations and irregular sampling require care, since deleting observations and treating the remainder as equally spaced can change the temporal meaning of the test."
    }
  ],
  "links": [
    "statistical-hypothesis-testing",
    "time-series",
    "stationary-process",
    "autocorrelation",
    "correlation",
    "null-hypothesis",
    "statistical-independence",
    "sample-mean",
    "test-statistic",
    "variance",
    "sampling-distribution",
    "chi-squared-distribution",
    "degrees-of-freedom",
    "p-value",
    "significance-level",
    "arima-model",
    "autoregressive-model",
    "statistical-power",
    "multiple-testing",
    "bootstrap-sampling",
    "normal-distribution"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}