# Autocovariance function explanation

It seems that I still do not understand properly how ACF works My R calculations

> a1
[1] 5.0 1.5 2.0 3.5 1.0
Autocovariances of series ‘a1’, by lag

0      1      2      3      4
2.140 -0.792 -0.294  0.784 -0.768


Then I have decided to change the first and the last entry

> a1
[1] 1.0 1.5 2.0 3.5 5.0
> acf(a1,lag.max = NULL,type = c("covariance"),plot = FALSE)

Autocovariances of series ‘a1’, by lag

0      1      2      3      4
2.140  0.808 -0.294 -0.816 -0.768


Why does the value at the lag4 stays equal as before? I have repeated a1 with same values

acf(a2,,lag.max = NULL,type = c("covariance"),plot = FALSE)

Autocovariances of series ‘a2’, by lag

0      1      2      3      4      5      6      7      8      9
2.140  0.424 -0.702 -0.963 -0.364  1.070  0.404 -0.147 -0.408 -0.384
> a2
[1] 1.0 1.5 2.0 3.5 5.0 1.0 1.5 2.0 3.5 5.0


I am struggling to understand physical meaning of lags.I am especially interested with link to power spectral density.Power spectral density can be obtained computing autocorrelation function in Fourier space.Does this mean that the power spectral density is the same both for a1 and a2?

The formula gives, for $j=0,...,4$, $$\hat{\gamma}_j=T^{-1}\sum_{t=1}^{T-j}(Y_{t}-\bar{Y}_T)(Y_{t+j}-\bar{Y}_T)$$ where $\bar{Y}_T$ is the sample mean (it may divide by another quantity such as $T-j$, but that does not affect the argument).
Now, for $j=4$, we have $$\hat{\gamma}_j=T^{-1}\sum_{t=1}^{1}(Y_{t}-\bar{Y}_T)(Y_{t+4}-\bar{Y}_T)$$ as $T=5$, or $$\hat{\gamma}_j=T^{-1}(Y_{1}-\bar{Y}_T)(Y_{5}-\bar{Y}_T)$$ If you now flip around $Y_1$ and $Y_5$, the result will evidently remain the same.