avatarHair Parra

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4920

Abstract

vial. Finding such nice, closed forms can get a bit messy with the infinite summations and the algebra, but otherwise, it is a pretty straightforward process. Thankfully, unless you are learning this material for academic purposes or pure enjoyment, most of the time you won’t find yourself calculating this by hand. In later articles, we will fully immerse ourselves in thorough examples in R, so you can see how everything connects. For now, let’s end this article with a review of the PACF :).</p><h2 id="0555">The PACF</h2><figure id="7299"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*nuyxm0ciYpUpq-WgwdqK1A.png"><figcaption></figcaption></figure><figure id="167e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*HHxatsHx8HAWZKb1QD9SeA.png"><figcaption></figcaption></figure><figure id="30f4"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*5Sz0Y0IqHGdag01DmbtrGg.png"><figcaption></figcaption></figure><figure id="093c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*ywvWkZil-u1Zu5zdLAVg5w.png"><figcaption></figcaption></figure><p id="9ddd">Of course, the <b>sample PACF </b>uses the sample autocovariance equivalents.</p><p id="b383"><b>Remark</b></p><figure id="764b"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*0SmiMk2iWZZcMPkZhWchKw.png"><figcaption></figcaption></figure><p id="f044"><b>What is the PACF measuring?</b></p><p id="34af">The PACF measures the association of <i>X_{h+1} </i>and <i>X_{1},</i> adjusting for <i>X_{h}, X_{h-1}, … , X_{2}.</i><b> </b>That is, it tells us how much correlation is due to the furthest lag <i>X_{1}</i> with the actual observation we are looking at, having adjusted for the association of all other intermediate lags. More explicitly,</p><figure id="2982"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*HgrJi2lMYc9gnCVyG915mA.png"><figcaption></figcaption></figure><p id="b0c1">Check out some examples using the PACF in R<a href="https://readmedium.com/a-complete-introduction-to-time-series-analysis-with-r-tests-for-stationarity-a8f1966a7c88"> here</a>, but we will revisit it soon with ARMA processes :).</p><h2 id="6e3a">How to R</h2><p id="3f81">Let’s take a look at a quick example by simulating an ARMA(2,1) process, and inspecting how its ACF and PACF behave. As in the last article, we start by specifying its coefficients into an appropriate format:</p> <figure id="4706"> <div> <div>

            <iframe class="gist-iframe" src="/gist/JairParra/7c32dcad68ca27cf5bece828f29bdb17.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure>
    <figure id="6b69">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/JairParra/66a1bc58aff8e40699aca400caf46e4c.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="d6c9">Next, we make use of the <code>arima.sim</code> function to simulate our given ARMA(2,1) process:</p>
    <figure id="45aa">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/JairParra/d1901ea0619430009d34886ce65f3ad1.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="db5a">We can also plot the resulting process:</p>
    <figure id="908f">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/JairParra/63a392f822abdfdc9fee16cf5db40c94.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><figure id="6df6"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*7VTtwDHsJ4WcrfQ0t1jPGg.png"><figcaption></figcaption></figure><p id="5f4b">Note how hard it is to take a look at a Time Series plot and figure out whether it is stationary! If we take a look at the data, it looks like we “don’t” have a trend, and you could even think that there are seasonal components, the variability kind of changes from time, etc. We can also loop into a small window of the process:</p>
    <figure id="0f0f">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/JairParra/cb13855ef103fef5ba8635cd8241a047.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><figure id="6451"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*F3f3NIsb02NznbGxK2e

Options

M4Q.png"><figcaption></figcaption></figure><p id="9345">There seems to be some autocorrelation here, but it is still very hard to tell precisely what it is. Instead, let’s take a look at the ACF and PACF:</p> <figure id="e008"> <div> <div>

            <iframe class="gist-iframe" src="/gist/JairParra/05a6b5ef7b207d820ba51f220267bf84.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><figure id="ccb5"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*tHKS5y-lRqKE_DdBetapMg.png"><figcaption></figcaption></figure>
    <figure id="97ba">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/JairParra/8b151f25c0d1fdb518cb711319a461fb.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><figure id="0d67"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*jnCL0_KEwRActx41CqthFA.png"><figcaption></figcaption></figure><p id="655e">Here, one important thing to see is that even though in the ACF there are a number of lags that go outbounds, the PACF shows us that when adjusting for the correlation in between, this becomes significantly smaller. We can use the true ARMA(2,1) coefficients that we specified above to compute the theoretical ACF and PACF quantities and compare them to the sample ones as follows:</p>
    <figure id="9479">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/JairParra/8afd8daff063008d42c07091967443a4.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="c851">We can observe that these values closely correspond to the ones in the plots:</p>
    <figure id="9095">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/JairParra/929f0e1f2806b7cb636f8b3ef3ebc9b2.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><figure id="4cda"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*zXptTqGTPVIG8gOiHTu1Ag.png"><figcaption></figcaption></figure><figure id="6710"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*S49Iq1ckqAx4q2utECdlqA.png"><figcaption></figcaption></figure><h2 id="e78a">Next time</h2><p id="ce99">And that’s it for now! In the following articles, we will take a look at forecasting with ARMA(p,q) processes, along with some cool examples in R. Stay tuned, and happy learning!</p><h2 id="4d23">Last time</h2><p id="d69c"><a href="https://readmedium.com/a-complete-introduction-to-time-series-analysis-with-r-arma-processes-part-ii-85a6bb5becae">ARMA processes (Part II)</a></p><div id="8cb1" class="link-block">
      <a href="https://readmedium.com/a-complete-introduction-to-time-series-analysis-with-r-arma-processes-part-ii-85a6bb5becae">
        <div>
          <div>
            <h2>A Complete Introduction To Time Series Analysis (with R):: ARMA processes (Part II)</h2>
            <div><h3>In the last article, we saw that a general ARMA(p,q) process can be written, with the help of the autoregressive and…</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*V517s0EbYioCVa0xuQEfhw.png)"></div>
          </div>
        </div>
      </a>
    </div><h2 id="bbf2">Main page</h2><div id="dddc" class="link-block">
      <a href="https://readmedium.com/a-complete-introduction-to-time-series-analysis-with-r-9882f2d44c9d">
        <div>
          <div>
            <h2>A Complete Introduction To Time Series Analysis (with R)</h2>
            <div><h3>During these times of the Covid19 pandemic, you have perhaps heard about the collaborative efforts to predict new…</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*TL2PeOANEN4zG0_OqoHptQ.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><h2 id="653d">Follow me at</h2><ol><li><a href="https://www.linkedin.com/in/hair-parra-526ba19b/">https://www.linkedin.com/in/hair-parra-526ba19b/</a></li><li><a href="https://github.com/JairParra">https://github.com/JairParra</a></li><li><a href="https://medium.com/@hair.parra">https://medium.com/@hair.parra</a></li></ol></article></body>

A Complete Introduction To Time Series Analysis (with R):: The ACF and PACF functions

Sample autocovariance for a linear process

In the last article, we discussed the stationarity, causality, and invertibility properties of ARMA(p,q) process, along with the conditions required to ensure these, and how to verify them. In this article, we will see how these properties, in particular, stationarity and causality greatly simplify our task of finding the ACVF, ACF, and PACF.

ARMA(p,q) as a Linear Process

Recall from this article that a linear process is no more than a stationary time series which has the representation

satisfying

Further, we saw in this article that when the underlying random variables of such a process where white noise, then the autocovariance of such process can be written as

Now, from the previous article, we saw that if our ARMA(p,q) process is causal, we can find coefficients phi such that

which is indeed a linear process with coefficients

Note that we can see the Psi polynomial as a “ratio” of the Theta and Phi polynomials,

Thus, we can simply use the psi coefficients to find the ACV!

Worked Example

Let’s take a look at a fully-worked example with the ARMA(1,1); assume we have such a process given by

Now, we could use the recursive formula to find a casual representation. Such representation has the form

where

.Then, using the formula

we find

and that’s it! Needless to mention, once we know these forms, finding the ACF is trivial. Finding such nice, closed forms can get a bit messy with the infinite summations and the algebra, but otherwise, it is a pretty straightforward process. Thankfully, unless you are learning this material for academic purposes or pure enjoyment, most of the time you won’t find yourself calculating this by hand. In later articles, we will fully immerse ourselves in thorough examples in R, so you can see how everything connects. For now, let’s end this article with a review of the PACF :).

The PACF

Of course, the sample PACF uses the sample autocovariance equivalents.

Remark

What is the PACF measuring?

The PACF measures the association of X_{h+1} and X_{1}, adjusting for X_{h}, X_{h-1}, … , X_{2}. That is, it tells us how much correlation is due to the furthest lag X_{1} with the actual observation we are looking at, having adjusted for the association of all other intermediate lags. More explicitly,

Check out some examples using the PACF in R here, but we will revisit it soon with ARMA processes :).

How to R

Let’s take a look at a quick example by simulating an ARMA(2,1) process, and inspecting how its ACF and PACF behave. As in the last article, we start by specifying its coefficients into an appropriate format:

Next, we make use of the arima.sim function to simulate our given ARMA(2,1) process:

We can also plot the resulting process:

Note how hard it is to take a look at a Time Series plot and figure out whether it is stationary! If we take a look at the data, it looks like we “don’t” have a trend, and you could even think that there are seasonal components, the variability kind of changes from time, etc. We can also loop into a small window of the process:

There seems to be some autocorrelation here, but it is still very hard to tell precisely what it is. Instead, let’s take a look at the ACF and PACF:

Here, one important thing to see is that even though in the ACF there are a number of lags that go outbounds, the PACF shows us that when adjusting for the correlation in between, this becomes significantly smaller. We can use the true ARMA(2,1) coefficients that we specified above to compute the theoretical ACF and PACF quantities and compare them to the sample ones as follows:

We can observe that these values closely correspond to the ones in the plots:

Next time

And that’s it for now! In the following articles, we will take a look at forecasting with ARMA(p,q) processes, along with some cool examples in R. Stay tuned, and happy learning!

Last time

ARMA processes (Part II)

Main page

Follow me at

  1. https://www.linkedin.com/in/hair-parra-526ba19b/
  2. https://github.com/JairParra
  3. https://medium.com/@hair.parra
Timeseries
Machine Learning
Statistics
Mathematics
Forecasting
Recommended from ReadMedium