A visual guide to calculating the Sample AutoCovariance Function (SACVF) and Sample AutoCorrelation Function (SACF).
To measure how a sequence relates to a shifted copy of itself, we use the SACVF, denoted by $\hat{\gamma}(h)$.
SACVF depends on the scale of the data. To get a standardized measure between $-1$ and $1$, we divide the SACVF by the variance (which is the SACVF at lag $h=0$). This gives us the SACF, denoted by $\hat{\rho}(h)$.
4
\(n = 6\)
Adjust the lag $h$ to see how the sequence shifts and which pairs overlap.
Notice that autocorrelation is symmetric around zero: $\hat{\rho}(-h) = \hat{\rho}(h)$.
Review the mechanics for each lag applied to your chosen sequence.
| Lag ($h$) | Overlapping Pairs | Sum of Products | SACVF $\hat{\gamma}(h)$ | SACF $\hat{\rho}(h)$ |
|---|
Enter any 5 numbers. The platform will calculate the mean, centered values, SACVF, and SACF for all possible lags.
You can easily compute this in professional applications using the ready-made functions from Python's statsmodels library:
import numpy as np
import statsmodels.api as sm
# Test with our 'Random' sequence
x = np.array([2, 4, 3, 5, 6, 4])
# Ready-made function for Sample AutoCovariance (SACVF)
# Note: nlag=3 (or nlags=3) specifies the maximum lag to compute (h=0, 1, 2, 3).
# We set it to 3 to match our visual lab and to avoid wasting computation
# time on unnecessary higher lags, which is crucial for huge datasets.
sacvf = sm.tsa.acovf(x, nlag=3)
# Ready-made function for Sample AutoCorrelation (SACF)
sacf = sm.tsa.acf(x, nlags=3)
print("SACVF:", np.round(sacvf, 3))
print("SACF: ", np.round(sacf, 3))