Math calculator

Ljung-Box Test Calculator

Is the series white noise?

Test many lags

Sixty independent draws. Q is 13.5477 on 12 degrees of freedom, p = 0.33052 — nothing to see, correctly. Box-Pierce on the same data gives 11.3277 with p = 0.50107: a statistic 19.6% smaller and a p-value half again as forgiving. Both are printed below, because the gap between them at this sample size is the whole reason Box-Pierce was replaced.

60 observations · 12 lags

Q = 13.5477 on 12 df, p = 0.33052

Box-Pierce on the same lags gives 11.3277 with p = 0.50107 — 19.6% smaller. Nothing here separates this series from independent noise at these lags.

Ljung-Box Q

13.5477

12 degrees of freedom

p-value

0.33052

consistent with noise

Box-Pierce Q

11.3277

p = 0.5011

Lags tested

12

n/4 is 15.0

Where the evidence accumulates

The cumulative Ljung-Box statistic at each lag
LagAutocorrelationCumulative Qdfp
1-0.01050.007010.93350
2+0.07610.378620.82753
3+0.04900.535330.91108
4-0.25214.755840.31328
5+0.01374.768450.44479
6+0.07785.185160.52031
7-0.03745.283170.62546
8+0.07925.731880.67724
9-0.05125.923390.74757
10-0.19968.8871100.54285
11+0.148910.5693110.48002
12-0.196013.5477120.33052

Q only ever rises as lags are added, and so do the degrees of freedom. Reading down this column and stopping at the first significant row is choosing the lag count from the data, which is a different test with a different error rate.

Many lags at once Box-Pierce beside it Degrees of freedom corrected Says nothing about where

What this tool shows

On sixty independent observations at twelve lags, Ljung-Box gives Q = 13.5477 with p = 0.33052 and Box-Pierce gives 11.3277 with p = 0.50107. A statistic 19.6% smaller and a p-value half again as forgiving, on data where both are correct. That gap at realistic sample sizes is the entire reason Box-Pierce was replaced, and both are printed here so it is visible rather than asserted.

  • The Ljung-Box portmanteau statistic across any number of lags
  • Box-Pierce on the same lags, so the small-sample difference is measurable
  • The degrees-of-freedom correction for residuals from a fitted model
  • The cumulative statistic lag by lag, with the autocorrelation that produced it
  • A seasonal preset that Durbin-Watson cannot detect at all
  • A warning when the lag count is large relative to the series length
Many lags at once Box-Pierce beside it df corrected Lag-by-lag table

It says dependence exists somewhere. It never says where.

Updated 13 September 2026 · Works in any browser, no installation

Ljung-Box pools the autocorrelations at many lags into a single test of whether a series is white noise. Reading a correlogram by eye means running one test per lag, and at twelve lags roughly one will look significant by chance. This pools them instead, so the whole question gets one p-value. Its most common use is on the residuals of a fitted model, where the answer decides whether the model has captured the structure or left some behind.

At a glance

Formula shown
Q = n(n+2)·Σₖ rₖ²/(n−k) over k = 1…h, referred to a chi-square on h − p degrees of freedom, where p is the number of parameters estimated in producing the series. Box-Pierce is the same idea without the weighting: Q = n·Σrₖ². Because (n+2)/(n−k) exceeds 1 for every lag, Ljung-Box is always the larger of the two, and the gap grows with h relative to n — which is where Box-Pierce’s chi-square approximation breaks down.
Scenario support
Checking whether ARIMA or regression residuals still contain structure, testing a forecast’s errors for information the model missed, confirming that a differenced series is stationary noise, screening returns data for volatility clustering (on squared returns), and validating a random number generator.
Educational estimate
Planning support from the values you enter — not professional advice.

Why Box-Pierce was replaced

Both statistics test the same hypothesis and differ only in a weight. On large samples they agree; at the sizes people actually have, they do not.

Sixty white-noise observations, twelve lags: Q = 13.5477 against Box-Pierce’s 11.3277. The Ljung-Box statistic is 19.6% larger.

The p-values are 0.33052 and 0.50107. On data where nothing is happening, that is harmless. On data near a decision boundary it is not.

The weight is (n+2)/(n−k), which exceeds 1 at every lag. So Ljung-Box is always the larger, and the verification suite asserts that ordering on 150 generated series.

The correction exists because Box-Pierce’s chi-square approximation is poor when h is a meaningful fraction of n. It under-rejects, which is the direction that lets a misspecified model through.

Residuals need fewer degrees of freedom

Most uses of this test are on residuals, and most implementations leave the correction to the user.

Fitting parameters absorbs autocorrelation. An ARMA(1,1) fit removes structure from the residuals, so their correlations are smaller than a chi-square on h degrees of freedom expects.

So the degrees of freedom drop by one per estimated parameter. Twelve lags on the residuals of an ARMA(1,1) gives 10, not 12.

On the shipped residual preset that changes p from 0.38982 to 0.23983. Same statistic, same lags, and the uncorrected version is 63% more forgiving.

The error is always in the same direction: skipping the correction accepts models that should be rejected. The control here defaults to zero for raw series and should be raised for residuals.

How many lags, and why it is not a free choice

The lag count is the one real decision this test asks for, and it moves the answer in both directions.

Too few lags and the test misses dependence that sits further out. The shipped seasonal preset needs at least twelve to see anything at all.

Too many and the power drains away. Each added lag contributes one degree of freedom whether or not it contributes evidence, so testing 30 lags on 60 observations dilutes a real signal.

The common rules are h = ln(n), or h = 2m for seasonal data of period m, or simply h no larger than n/4 — which is why this tool warns when the lag count passes that.

What is not allowed is picking h after seeing the table. The cumulative column here makes that tempting, and reading down it to the first significant row is a different test with an unstated error rate.

The case Durbin-Watson cannot see

The seasonal preset is here to mark the boundary between this test and the one people reach for first.

Seventy-two monthly values with an annual cycle. Q at 18 lags is 423.8616 with p = 9.56×10⁻⁷⁹.

A Durbin-Watson test is built entirely from consecutive pairs. Dependence that lives at lag 12 is invisible to it by construction.

So a clean Durbin-Watson is not evidence that residuals are independent on any series with a seasonal or cyclical component.

The reverse is also worth knowing: Ljung-Box is less powerful than Durbin-Watson when the dependence really is only at lag 1, because it spends degrees of freedom on lags where nothing is happening.

What the test cannot tell you

A portmanteau test is a single yes or no about a whole set of lags, and that compression costs information.

It does not say which lag carries the dependence. The per-lag table here narrows it down, and a correlogram answers it properly.

It does not distinguish a trend from a cycle from an autoregression. The shipped trend preset gives Q = 349.4265 with no single lag standing out, because a trend correlates with everything.

It assumes the series is stationary. On a trending series a significant result is guaranteed and uninformative — difference the series first, then test.

And it sees only linear dependence. Volatility clustering leaves the levels looking independent; the standard trick is to run the same test on the squared values.

Reporting the test

Four items, and the third is the one most often omitted from software output.

Give Q, h and n. Q without the lag count is uninterpretable, and the critical value moves with both.

Say how h was chosen, and say it was chosen in advance. A lag count picked after seeing the table is not a test.

Give the degrees of freedom and how many parameters were subtracted. “Q(12) = 12.72 on 10 df, ARMA(1,1) residuals” is complete; “Ljung-Box p = 0.39” is ambiguous by a factor that matters.

And say whether the series was differenced first. On a non-stationary series this test rejects by construction.

Sources and methodology

References for the portmanteau statistic and its correction.

Method. Q is accumulated lag by lag so the whole path is printed rather than only its endpoint, and Box-Pierce is computed independently on the same autocorrelations so the two can be compared at the sample size in front of you. The degrees of freedom are reduced by the fitted-parameter count, which is a control rather than an assumption — and it defaults to zero, since most series pasted into a calculator are raw rather than residuals. The autocorrelations themselves come from the same routine that backs the correlogram, so the two pages cannot disagree. The suite asserts that Ljung-Box is never below Box-Pierce across 150 generated series, which follows from the (n+2)/(n−k) weight exceeding 1 at every lag, and that the cumulative Q never decreases as lags are added. It also asserts that every autocorrelation stays within ±1, that shifting and rescaling the series leaves the correlogram unchanged, and that a request for more fitted parameters than lags returns no result rather than a chi-square on zero degrees of freedom. That engine is verified on every change against 157 assertions. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

AutocorrelationACF and PACF at every lag with Bartlett bands that widen rather than a flat line, plus the shapes that identify a model.
Durbin-WatsonThe Durbin-Watson statistic with dL and dU computed by Imhof inversion rather than tabled, so the bounds exist at any n and k.
Chi-SquareGoodness of fit and tests of independence with every expected count and per-cell contribution shown — because the validity condition is about expected counts, not observed ones, and most calculators hide them.
Moving AverageSimple, exponential, weighted and centred moving averages with the lag each one carries — exactly (n−1)/2 periods for a simple average, which is also the reason α = 2/(n+1) is in every EMA formula.
ResidualResiduals, standardised and studentised residuals, leverage and Cook's distance, with Anscombe's quartet built in — including the dataset every residual rule scores cleanest and which one point controls entirely.
Runs TestThe Wald-Wolfowitz test with every run boundary drawn: ten 1s then ten 0s gives z = −3.9055 and perfect alternation +3.9055 — identical counts, mirror-image results, which no frequency test can see.

More in Math, or browse all calculators.

Educational use disclaimer

An educational tool. The Ljung-Box test assumes a stationary series and detects only linear dependence, so a trending series rejects by construction and volatility clustering can pass untouched. It also says nothing about which lag carries the dependence, and its lag count must be chosen before seeing the results rather than after.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (5 updates)

Published 13 September 2026

  1. Launched the Ljung-Box portmanteau test with Box-Pierce computed independently beside it: 13.5477 against 11.3277 on sixty white-noise observations.
  2. Made the degrees-of-freedom correction for fitted models a control rather than an assumption; on the shipped residual preset it moves p from 0.38982 to 0.23983.
  3. Added a lag-by-lag cumulative table with a warning that choosing the lag count from it is a different test.
  4. Shipped a seasonal preset that a Durbin-Watson test cannot detect at all, to mark the boundary between the two.
  5. Shared the autocorrelation routine with the correlogram page so the two cannot disagree on the same series.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.