Percentages and Math

Autocorrelation Calculator

Paste a series in time order to see how strongly each value is related to the ones before it.

Your numbers

Numbers separated by commas, spaces or new lines. Example data.

How many steps back to look. Must be smaller than the series length minus 1. Example value.

Result

Lag 1 autocorrelation

0.7687

Ljung-Box p value over 5 lags: less than 0.0001.

Lag 1 autocorrelation
0.7687
Ljung-Box Q (5 lags)
25.906
Ljung-Box p value
less than 0.0001
Approximate band
plus or minus 0.4900
Lags outside the band
2 of 5
Values and mean
16 and 24.8125

Autocorrelation by lag

LagrBandLjung-Box Qp
10.7687Outside11.3440.0008
20.6305Outside19.521less than 0.0001
30.4447Inside23.903less than 0.0001
40.2504Inside25.407less than 0.0001
50.1380Inside25.906less than 0.0001
How this was calculated
  1. Subtract the mean 24.8125 from every value and total the squared differences.
  2. For each lag k, multiply each difference by the one k steps later, add them up and divide by the squared total: r1 = 0.7687.
  3. For a series with no relationship between values, about 95% of the r values fall within plus or minus 1.96 / sqrt(16) = 0.4900.
  4. Ljung-Box Q = n (n + 2) x sum of r squared / (n - k) over the 5 lags = 25.906, compared with chi-square with 5 degrees of freedom.
  • A trend or a seasonal pattern inflates the early lags, so remove them (by differencing, for example) before judging whether what is left is random. The band is a rough guide for a series with no relationship between values.

Calculated using SumPanda.com · https://sumpanda.com/autocorrelation-calculator/

Results are estimates for general information. Verify important figures before relying on them.

Next step

How to use the autocorrelation calculator

  1. Paste your series in time order, separated by commas, spaces or new lines.
  2. Choose the number of lags to examine. It must be at least 1 and at most 2 fewer than the number of values.
  3. Read the lag-1 value and the Ljung-Box p value, then the table of every lag.
  4. Compare each r with the band: values outside it are larger than expected from a series with no relationship between values.

Formula

r_k = sum of (x_t - mean)(x_(t+k) - mean) over t = 1 to n - k, divided by sum of (x_t - mean)^2

Band = plus or minus 1.96 / sqrt(n)

Ljung-Box Q = n (n + 2) x sum of r_k^2 / (n - k) for k = 1 to h

Q is compared with chi-square with h degrees of freedom

The denominator uses all n values for every lag, the convention used by most statistics software. The band is exact only for a series of independent values.

A rising series of 16 values

The series 12, 15, 14, 18, 20, 19, 23, 25, 24, 28, 30, 29, 33, 35, 34, 38 has mean 24.8125. Its first five autocorrelations are 0.7687, 0.6305, 0.4447, 0.2504 and 0.1380.

The band is plus or minus 1.96 / sqrt(16) = 0.4900, so lags 1 and 2 fall outside it. The Ljung-Box statistic over 5 lags is 25.906 with 5 degrees of freedom, giving p below 0.0001. The strong pattern comes from the upward trend.

What autocorrelation shows

Autocorrelation at lag k is the correlation between the series and itself shifted by k steps. A high value at lag 1 means each value tends to resemble the one before it. A strong negative value means values alternate high and low, as in the alternating example where lag 1 is -0.8886. Regular peaks at lag 12 in monthly data point to a yearly pattern.

The Ljung-Box test combines the first h autocorrelations into one number. A small p value says the series is unlikely to be unrelated values; it does not say which lag or what kind of pattern.

Using it sensibly

A trend or a seasonal cycle pushes autocorrelations up at many lags, so the result may describe the trend and not the leftover noise. Differencing the series or removing the cycle first is common practice. Smoothing tools such as the moving average calculator or the exponential smoothing forecast work on the same kind of series.

Short series give noisy estimates, and the band is a rough guide, not a verdict. For the plain spread of the values see descriptive statistics.

Assumptions and limits

  • The values are equally spaced in time and listed in order, with no gaps.
  • The series is roughly stationary: no strong trend or changing spread, unless you want those to show up.
  • The plus or minus band assumes independent values and is approximate for short series.
  • The Ljung-Box test uses a chi-square approximation that needs a reasonable number of values.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

How many lags should I choose?

A common starting point is about a quarter of the series length, capped near 20 for long series. For monthly data include at least 12 lags so a yearly cycle can appear. More lags dilute the Ljung-Box test, so do not add them without a reason.

Why does a trend give high autocorrelation?

In a rising series each value sits near its neighbors and above the overall mean, so products of deviations are mostly positive at every small lag. The correlation then reflects the trend instead of any short-term memory.

What does a negative autocorrelation mean?

It means that a high value tends to be followed by a low one and the other way around. Over-corrected processes and alternating schedules produce it. The alternating example in this tool gives about -0.89 at lag 1.

Is the result the same as in other software?

The autocorrelations follow the standard biased estimator with n in the denominator and match statsmodels. Some packages offer an unbiased version that divides by n minus k, which gives larger values at high lags.