I want to compute the autocorrelation for the series {1,2,3,4,5} at lag k=1.
I step through the calculation in tabular format.
| t | $x_t$ | $x_{t+1}$ | $x_t - \bar{x}$ | $x_{t+1} - \bar{x}$ | $(x_t - \bar{x})(x_{t+1} - \bar{x})$ |
|---|---|---|---|---|---|
| 1 | 1 | 2 | 1 - 3 = -2 | 2 - 3 = -1 | (-2) * (-1) = 2 |
| 2 | 2 | 3 | 2 - 3 = -1 | 3 - 3 = 0 | (-1) * 0 = 0 |
| 3 | 3 | 4 | 3 - 3 = 0 | 4 - 3 = 1 | 0 * 1 = 0 |
| 4 | 4 | 5 | 4 - 3 = 1 | 5 - 3 = 2 | 1 * 2 = 2 |
Here's how each column is calculated:
- $t$ is the time index.
- $x_t$ is the value of the series at time $t$.
- $x_{t+1}$ is the value of the series at time $t+1$ (lagged by 1).
- $x_t - \bar{x}$ is the deviation of $x_t$ from the mean $\bar{x}$.
- $x_{t+1} - \bar{x}$ is the deviation of $x_{t+1}$ from the mean $\bar{x}$.
- $(x_t - \bar{x})(x_{t+1} - \bar{x})$ is the product of deviations.
The mean $\bar{x}$ of the series {1,2,3,4,5} is calculated as:
$$\bar{x} = \frac{1 + 2 + 3 + 4 + 5}{5} = \frac{15}{5} = 3$$
We can sum the last column to find the numerator for the autocorrelation function:
$$\text{Numerator Sum} = 2 + 0 + 0 + 2 = 4$$
The variance $\text{Var}(X)$ of the series is calculated as:
$$\text{Var}(X) = \frac{(-2)^2 + (-1)^2 + 0^2 + 1^2 + 2^2}{5} = \frac{4 + 1 + 0 + 1 + 4}{5} = \frac{10}{5} = 2$$
Since we're using the biased estimator for variance (dividing by $n$), the denominator for the ACF function at lag 1 is $n \times \text{Var}(X) = 5 \times 2 = 10$.
Now we can calculate the autocorrelation for lag 1:
$$\text{ACF}(1) = \frac{\text{Numerator Sum}}{n \times \text{Var}(X)} = \frac{4}{10} = 0.4$$
Thus, the autocorrelation at lag 1 for the series {1,2,3,4,5} is 0.4.
Is this the correct computation of autocorrelation with for lag=1?
acf(1:5, plot=FALSE)– Christoph Hanck Mar 01 '24 at 15:14