How to use the autocorrelation calculator
- Paste your series in time order, separated by commas, spaces or new lines.
- Choose the number of lags to examine. It must be at least 1 and at most 2 fewer than the number of values.
- Read the lag-1 value and the Ljung-Box p value, then the table of every lag.
- 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.
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.