ACF and PACF in Excel
ACF and PACF in Excel
The purpose of this tutorial is not to explain the meaning, use and purpose of autocorrelation (ACF)
and partial autocorrelation (PACF) coefficients, but just to show you how to calculate them in Excel.
If you need to learn more about these tools, check some other resources on the web. Once you
understand them and assuming that you would like to use Excel to calculate them, return to this
tutorial.
What is so special about this tutorial? First of all, we want to use Excel. Secondly, we do not want to
create Macros or write a VBA program to calculate these coefficients. Our ambition is to use
standard Excel functions to execute this task.
How are we going to do it? We will use a time series that is given in cells B2:B51 in Figure 1. To make
things easier, in cells A2:A51 we have used sequential numbers 1, 2, …, 50 that represent n number
of observations and which will also represent k number of ACF and PACF. In this tutorial, we will do
the following calculations:
1. Calculate ACF
2. Calculate the standard errors (SE) for ACF using two different methods
3. Extract the time-lagged autocorrelation matrix
4. Calculate PACF and SE
5. Show both ACF and PACF functions with their respective standard errors in a graph
That is all we intend to do. We will show the equations so that you can see how the Excel functions
were constructed, but we will not explain them. This tutorial just translates the equations into Excel
syntax.
1. Calculate ACF
Figure 1 below shows the time series in cells B2:B51 (rows 10:40 hidden). To calculate the ACF
coefficients we must first calculate deviations from the mean for the time series. Column C2:C51 in
Figure 1 contains the deviations of every observation in the time series from their mean.
𝑑𝑖 = 𝑦𝑖 − 𝑦̅ (1)
Where di is the deviation, yi is the observation and 𝑦̅ is the mean value of all the observations.
1
Figure 1
∑𝑛−𝑘
𝑖=1 (𝑦𝑖 − 𝑦
̅)(𝑦𝑖+𝑘 − 𝑦̅)
𝑟𝑘 = (2)
∑𝑘𝑖=1(𝑦𝑖 − 𝑦̅)2
=SUMPRODUCT($C$2:INDEX($C$2:$C$51,ROWS(C3:C$51)),$C3:C$51)/DEVSQ($C$2:$C$51).
This is the function from cell D2 in Figure 2. If we copy this cell down to D22, we have all the
autocorrelation coefficients calculated. That is all that is needed to have ACFs done in Excel.
In Figure 2, you can also see that columns E and F contain the values for the standard error for every
autocorrelation coefficient. Column E contains the conventional equation for the autocorrelation
standard errors (SE) and this is:
1 𝑛−𝑘
𝑆𝐸1𝑘 = √ ( )
𝑛 𝑛+2 (3)
Where n is the total number of observations and k changes and corresponds to the ACF coefficient.
2
Figure 2
However, it is more customary to use the Bartletts formula for autocorrelation standard errors,
which is:
𝑘−1
1
𝑆𝐸2𝑘 = √ (1 + 2 ∑ 𝑟𝑙2 ) (4)
𝑛
𝑙=1
Where, as before n is the number of observations, k is the lag for the ACF and rl is the ACF coefficient
for the same lag as ACF.
We need three steps to apply this formula in column F. First, in cell F1 we enter a formula:
=SQRT(1/COUNT($B$2:$B$51)).
This completes step 2 and we have two versions of calculating the standard errors (SE) for the
autocorrelation (ACF) coefficients. The second version (Bartlett) is a much more often used version
of calculating ACF SE and we recommend that you use this method.
3
3. Extract the time-lagged autocorrelation matrix
Our autocorrelation coefficients are calculated in cells D2:D22. We’ll first just copy the range D2:D22
into G2:G22 (see Figure 3). We will then type number 1 in cell G1 (this implies that the correlation
with the series of data with itself is 1). So, our full autocorrelation set is now in cells G1:G22.
Figure 3
Now copy D2:D22 (or G2:G22) and Paste Special as transposed values into cells H1:AB1. See Figure 4
below if you are unsure how to use Paste Special function and if you are not familiar with
transposing values in Excel. Essentially, you copy the range G2:G22, then select Paste Special option
and then tick the Values and Transpose options, as in Figure 4.
4
Figure 4
Now we have the frame (the first row and the first column) for our autocorrelation matrix that is
going to be time-lagged. What is the next step? We need to fill in the cells H2:AB22 to have the full
matrix completed.
Figure 5
Figure 6
5
After we have the formula copied across row 2 from H2:AB2, we highlight this whole row H2:AB2
and copy it down to AB22. The result is shown in Figure 7.
Figure 7
This creates a matrix of all autocorrelations lagged by one period at a time. This matrix will be the
basis for calculating the partial autocorrelation coefficients. Without it, we would not be able to
calculate the PACF using a single formula.
The formulae for partial autocorrelation coefficients look scary, so let’s just show them here without
necessarily going into them.
The first partial autocorrelation coefficient 11 is the same as the first autocorrelation coefficient r1:
𝜙̂11 = 𝑟1 (5)
Still easy. From there, we generalise for kj and calculate the intermediate values of kj:
𝜙̂𝑘𝑗 = 𝜙̂𝑘−1,𝑗 − 𝜙̂𝑘𝑘 𝜙̂𝑘−1,𝑘−𝑗 (7)
This enables us to calculate all the higher kk that are defined by the equation:
𝑘−1 𝑘−1
Sounds complicated. Right? Well, with the use of Excel, we can “squeeze” everything into a single
function: =INDEX(MMULT(MINVERSE(OFFSET($G$1,0,0,A2,A2)),OFFSET($G$1,1,0,A2,1)),A2). This is
the function in cell AC2 in Figure 8. This cell was copied down to AC22 and these are our partial
autocorrelation (PACF) coefficients.
6
Figure 8
The reason why we were able to use one single formula using standard Excel functions comes from
matrix algebra. The autocorrelation function can be expressed as the following equation:
𝛒k = 𝐏k 𝛟k (11)
It might sound very complicated, but in terms of Excel functions this means that to calculate the
partial autocorrelations, we need only two standard Excel functions, =MMULT() and =MINVERSE().
The first function is used to multiply two matrices and the second one returns an inverse of the
matrix, which is exactly what we need, as per equation (12). This is exactly what we have done in cell
AC2 in Figure 8: =INDEX(MMULT(MINVERSE(OFFSET($G$1,0,0,A2,A2)),OFFSET($G$1,1,0,A2,1)),A2).
Easy, isn’t it!
7
We now have to calculate the standard errors (SE) for the partial autocorrelation (PACF) coefficients.
Unlike the autocorrelation standard errors, the ones for partial autocorrelations are much easier to
calculate. They are simply for all values of PACF:
1 (13)
𝑆𝐸 = √
𝑛
Column AD2:AD22 contain the values of the partial autocorrelation coefficients standard errors and
they are calculated in Excel as: =1/SQRT(COUNT($B$2:$B$51)).
5. Show both ACF and PACF functions with their respective standard errors in a graph
We can now construct two graphs, one for ACF and the corresponding standard errors and the other
one for PCF and its standard errors. For ACF standard errors, we will only use the Bartlett formula
values from column F in Figure 2.
We copied the values of ACF and their SE and PACF and their SE in columns AL:AM and AP:AQ
respectively. Columns AN and AR contain the negative values of ASF SE and PACF respectively. The
only reason why we are doing this is to make it easier to create the charts. Otherwise, there is no
need to do it. See Figure 9 for the final result.
Figure 9
Now we’ll create the ACF graph from columns AL:AN. We highlight these three variables (ranges)
and create a line graph as in Figure 10.
8
Figure 10
We would like to present ACF (blue line) as bars, as it is customary, and change the colour for two SE
lines to be identical.
We right-click on the blue line and then select Change Series Chart Type as in Figure 11.
Figure 11
This produces another dialogue box as in Figure 12. We change ACF from line to clustered columns.
9
Figure 12
After that, we just change the colour of the two SE lines to make them the same colour. We get a
proper ACF chart as in Figure 13.
Figure 13
We repeat the same procedure for PACF and their SE using data from AP:AR in Figure 9 and the final
graph is as in Figure 14.
10
Figure 14
The graphs show 5 significant ACFs and 1 significant PACF. You could try to model this time series
using a simple AR(1) model, but this is a subject for completely different tutorial.
Branko Pecar
Spring 2021
11