Time Series Talk : Autocorrelation and Partial Autocorrelation

ritvikmath · Intermediate ·📊 Data Analytics & Business Intelligence ·7y ago

Key Takeaways

The video discusses autocorrelation and partial autocorrelation in time series analysis, using a toy example to predict the average monthly price of salmon based on previous months' prices, and introduces the partial autocorrelation function (PACF) and its relationship to the autocorrelation function (ACF). The video also covers the calculation of PACF values and the use of PACF plots to identify a good time series model, such as an AR (Auto Regressive) model, to predict the price assignment tod

Full Transcript

in this video we're going to be talking about the autocorrelation function ACF and the partial autocorrelation function pacf and most importantly the big differences between them so honestly when I first started learning time series in economics this was a really big challenge for me just understanding the intuition behind ACF versus pacf understanding real world examples where they both arise and just understanding how to derive them both mathematically so I'm hoping to make some of those challenges a little bit easier for you guys so to start off with we're going to go ahead and just use a toy example instead of going into a bunch of math theory in the beginning so what we're trying to do is predict the average monthly price of salmon maybe in our city so here's salmon um and we want to predict what is the average monthly price going to be this month compared to last month or the month before and all the months prior okay so here's a bit of notation just outlining that s subt is going to be the average price of salmon this month s subt minus one is the average price price of salmon last month notice it's just minus one so it's the month prior okay and Sub sub T minus 2 is the average price of salmon two months prior and of course we can keep going we can do s subt minus 3 minus four and however far we want it but for the purposes of this video we're going to stick to just these three now a big Concept in Time series maybe one of the most important Concepts is that the measurement of some value at a time period depends on the measurement of that value at the previous time period at the time period before that one and on and on and on in the past and that makes a lot of sense right because there's a lot of things that could affect the price of salmon such as the weather um maybe fishing regulations and stuff like that but arguably their the most intuitive uh determiner of the price of salmon this month is just hey what was the price of salmon last month if it was high last month maybe we expect it to be high this month if it was high one year ago maybe expect it to be again High uh this year for example so that's the idea behind time series uh one of the big Concepts in Time series and we'll get more into that a lot in future videos but for the purposes here we just need to fill in some blanks in this kind of causal diagram so here we have three boxes we have the price of salmon this month price of salmon last month and the price of salmon two months ago now let's just draw a couple of very intuitive arrows that tell us uh what's going to be correlated with what what might cause what so the price of salmon 2 months ago and to just make it even more concrete let's just say 2 months ago was January then February was last month and we're currently in March okay so the price of salmon in January is definitely going to have some kind of effect on the price of salmon in February so we uh denote that by this Arrow leading from January to February similarly the price of salmon in February will have an effect on the price of salmon in March now there's one more Arrow we can draw here and it might seem weird to draw at first but it does make sense the price of semon in January has an effect on the price of semon in March through February right because we have an eror going to February and an eror going through March so there is some indirect uh effect of the price of salmon from January affecting the price of salmon in March but there's also going to be possibly a direct effect that's where we skip over the February alt together and just say that there's some kind of mechanism going on here where the price of salmon in January directly affects the price of salmon in March and to make it more abstract for a second where the price of salmon two months prior affects the price of salmon uh today and why W that happen uh to give a real world example so it's not just abstract maybe there's some big food festival that happens in your city every two months so that food festival happens in January March May and on every other month right um and of course during that food festival priceon might change because maybe the city wants to make more money off of the big festivities and stuff like that so the price of Salon in January might directly affect the price of salimon in March because the food festival happened only in both those months okay there's a concrete example there's several others you can think of now let's get into the actual meat of this video is first how do we calculate the autocorrelation function so I want to know the autocorrelation function and this I've written a CO RR is correlation but this is the same thing as ACF autocorrelation function I want to find the autocorrelation between the price of salmon in January and the price of salmon in March so that is s subt minus 2 s subt okay how would I find that well well I can find it really easily mathematically by basically just taking uh lining up all the prices from two months ago and finding the correlation here we're talking about the regular Pearson correlation you might have learned in high school or college and just finding the correlation that way so for example going further in time I could take the price in January and March and then I would have February and April then I would have March and May and so on and I would just find the correlation between all these different data points treating this as my X variable this as my y variable and I think you guys know how to find the correlation between two data sets just like that okay but kind of at a more theoretical level and this is going to help us understand pacf a lot better let me switch over here to a different color this correlation between uh January and March or more abstractly between the price of salimon two months ago and the price of salimon in a current month is going to be made up of two pieces and we can see that very easily graphically in these boxes we've drawn here because the the arrows leading from two months ago to the current month there's two ways to get there I can get there directly so one effect is going to come from doing s t minus 2 directly to S subt right so that's the direct arrow and of course there's the indirect route so here's the direct route of course the indirect route is sub subt minus 2 going to S subt minus one going to sub subt so hopefully you guys can see that so the direct route is going from two months ago to the current month and the indirect route is going from two months ago to last month to the current month and both of these together kind of form the ACF the autocorrelation between the price of salmon two months ago and the current month now how does that contrast with pacf or the partial autocorrelation you might already see where this is going let me switch sheets here for pacf we only care about the direct effect we don't care about the effect as it comes through other time periods so we only care about the effect s subt minus 2 going to s subt and why do we why might we only care about that why would we uh sometimes care about ACF and sometimes care about pacf well ACF tells you the correlation between uh the price of salmon a number of periods ago and the price of salmon today but of course there's a lot of different components of that there's the component directly and there's a component indirectly now we might only care about the component directly because we want to see whether the price assignment two periods ago so two months ago is a good predictor of the price of salmon today based on ACF it might seem like a good predictor like if that correlation remember that Pearson correlation is really high but that correlation might be high only because of these indirect effects it might be the case that the direct effect has little to no correlation will barely help us at all with predicting the price of salmon today that's why pacf is very very important because pacf tells us okay taking all those indirect effects away just getting rid of them what is the direct effect of the price of salmon some number of periods ago and the price of salmon today so that's what pacf um is so pacf is direct effect ACF includes direct effect and all the indirect effects through the intermediary time periods so now the last thing we'll do in this video is how would I find pacf of course it's pretty easy to find ACF you literally just do a PE in correlation lining up uh your data set the First Column of which is two months ago or however many months ago and the second column of which is today that's pretty easy right pacf seems a little bit more challenging right so here's a way to find pacf you would write a regression model let's say we're trying to find pacf of two right so where k equals 2 K being our lag so you can substitute whatever K value you want so here we're going to write a regression function where the price of semon today which is this is equal to some coefficient 52 sub one Su coefficient uh times the price of salmon last month plus uh some other coefficient times the price of salmon two months ago and of course we have our error term and now this coefficient right here this five 2 sub2 is going to give us the direct effect of the price of salmon two months ago on the price of salmon today and why is it the direct effect why is there no more um confounding going on with the this inter merary Sub sub tus1 because we already took that into effect in our model because we have a term here which already captures that effect therefore this 522 is going to give us that direct effect of price assignment two months ago on price assignment today so it is exactly this 522 which is the pacf that is the pacf for k equals 2 if I want to find the PF for k equal 3 I need to build a new model where I include another term with s sub T minus 3 and the coefficient of that term in the regression is going to be my PF for k equal 3 and so on okay so the last thing I want to do is draw a plot of pacf we'll be looking at more of these plots in the future as we do more time series type videos well let's say we find the pacf for k equal 1 2 3 4 5 6 7 on and on and on and of course these are called our lags and let's say this is the plot we get of course PF can be negative right because if the price assignment today negatively impacts the price of salmon or sorry the price of salmon two months ago negatively impacts the price of salmon today then it should be negative these red bars I've drawn here are error bands you'll see this a lot going forward basically you can think of it right now as anything within the error bands so from zero going out to the air bands is no different than zero we don't have any evidence to say that it's actually different from zero okay so than statistical significance so we see that lag one has a nonzero pacf lag has a non-zero per pacf so it is 3 four and five but six and seven there's not really any correlation between the 6 months ago price of salmon and the seven months ago price of salmon and imagine all future lags um and the price of salmon today so what could a good model look like here remember what pacf tells us pacf tells us the coefficient of the price of salmon that many months ago on the price assignment today and if that coefficient is different from zero as indicated by it being outside these red error Bands then it's a good factor into a model because it can help us make that prediction so for example here this model might look like price of salmon today is going to be equal to and I'll switch to betas here so beta KN plus beta 1 time price of salmon minus one so month ago price of salmon two months ago and then we keep going for three four and five months ago okay so I won't draw out all of them I'll draw the last one will be B beta sub 5 Sub sub tus 5 plus of course we need our error term so a good model here might look like coefficient plus all these other coefficients each times the price of salmon from one month ago two months ago all the way to 5 months ago because that's what the pacf plot tells us so the pacf plot is super powerful in helping us identify a good time series model to predict the price assignment today based on price assignment in some number of past periods okay so that is a pH CF plot of course you might be wondering why didn't we draw an ACF plot that is also useful for a different type of model we'll get there in the future so just as a kind of teaser uh this type of model we've drawn here where you predict the price you predict something based on past values of that thing is called an AR or Auto regressive Model Auto regressive because it's a regression Auto because it's based on values of itself in the past okay so that I hope was a good clarification for you all in what is the fundament Al difference between the autocorrelation and partial autocorrelation and also how to find the autocorrelation through the Pearson just regular method and how to find partial autocorrelation by taking your regression figuring out the coefficient of that term Okay so until next time

Original Description

Intuitive understanding of autocorrelation and partial autocorrelation in time series forecasting My Patreon : https://www.patreon.com/user?u=49277905
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from ritvikmath · ritvikmath · 45 of 60

1 Math Team Update
Math Team Update
ritvikmath
2 Single Variable Calculus Volume of a Sphere - Proof 1
Single Variable Calculus Volume of a Sphere - Proof 1
ritvikmath
3 Single Variable Calculus Volume of a Sphere - Proof 2
Single Variable Calculus Volume of a Sphere - Proof 2
ritvikmath
4 Multivariable Calculus Volume of a Sphere Proof - Triple Integrals
Multivariable Calculus Volume of a Sphere Proof - Triple Integrals
ritvikmath
5 Multivariable Calculus Volume of a Sphere Proof - Double Integrals
Multivariable Calculus Volume of a Sphere Proof - Double Integrals
ritvikmath
6 The Euclidian Algorithm
The Euclidian Algorithm
ritvikmath
7 Proving the Chain Rule
Proving the Chain Rule
ritvikmath
8 Proving the Fundamental Theorem of Calculus Part 1
Proving the Fundamental Theorem of Calculus Part 1
ritvikmath
9 Proving the Fundamental Theorem of Calculus Part 2
Proving the Fundamental Theorem of Calculus Part 2
ritvikmath
10 Math Puzzle - Poison Perplexity
Math Puzzle - Poison Perplexity
ritvikmath
11 Math Puzzle - Poison Perplexity - Solution
Math Puzzle - Poison Perplexity - Solution
ritvikmath
12 Expected Value and Variance of Continuous Random Variables (Calculus)
Expected Value and Variance of Continuous Random Variables (Calculus)
ritvikmath
13 Expected Value and Variance of Discrete Random Variables (No Calculus)
Expected Value and Variance of Discrete Random Variables (No Calculus)
ritvikmath
14 Array Method
Array Method
ritvikmath
15 Complex Power Series and their Derivatives
Complex Power Series and their Derivatives
ritvikmath
16 Distributions - Intro
Distributions - Intro
ritvikmath
17 The Poisson Distribution
The Poisson Distribution
ritvikmath
18 The Bernoulli Distribution
The Bernoulli Distribution
ritvikmath
19 The Binomial Distribution
The Binomial Distribution
ritvikmath
20 The Continuous Uniform Distribution
The Continuous Uniform Distribution
ritvikmath
21 The Geometric Distribution
The Geometric Distribution
ritvikmath
22 The Triangular Distribution
The Triangular Distribution
ritvikmath
23 The Exponential Distribution
The Exponential Distribution
ritvikmath
24 The Borel Distribution + Notes on Poisson Distribution
The Borel Distribution + Notes on Poisson Distribution
ritvikmath
25 The Gamma Distribution
The Gamma Distribution
ritvikmath
26 The Normal Distribution
The Normal Distribution
ritvikmath
27 The Laplace Distribution
The Laplace Distribution
ritvikmath
28 The Chi - Squared Distribution
The Chi - Squared Distribution
ritvikmath
29 Overfitting
Overfitting
ritvikmath
30 Vector Norms
Vector Norms
ritvikmath
31 Truths Behind the Titanic : K-Nearest Neighbor
Truths Behind the Titanic : K-Nearest Neighbor
ritvikmath
32 The Mathematics of Breakups
The Mathematics of Breakups
ritvikmath
33 Sillyfish
Sillyfish
ritvikmath
34 Finding Optimal Paths - Dynamic Programming
Finding Optimal Paths - Dynamic Programming
ritvikmath
35 HowToDataScience : Scraping Twitter Data
HowToDataScience : Scraping Twitter Data
ritvikmath
36 Decision Trees
Decision Trees
ritvikmath
37 Perceptron
Perceptron
ritvikmath
38 Naive Bayes
Naive Bayes
ritvikmath
39 K-Nearest Neighbor
K-Nearest Neighbor
ritvikmath
40 Evaluating Machine Learning Models
Evaluating Machine Learning Models
ritvikmath
41 Decision Tree Pruning
Decision Tree Pruning
ritvikmath
42 K-Means Clustering
K-Means Clustering
ritvikmath
43 Gaussian Mixture Model
Gaussian Mixture Model
ritvikmath
44 Data Science - Fuzzy Record Matching
Data Science - Fuzzy Record Matching
ritvikmath
Time Series Talk : Autocorrelation and Partial Autocorrelation
Time Series Talk : Autocorrelation and Partial Autocorrelation
ritvikmath
46 Time Series Talk : Autoregressive Model
Time Series Talk : Autoregressive Model
ritvikmath
47 Time Series Talk : Moving Average Model
Time Series Talk : Moving Average Model
ritvikmath
48 Time Series Talk : ARMA Model
Time Series Talk : ARMA Model
ritvikmath
49 Time Series Talk : ARCH Model
Time Series Talk : ARCH Model
ritvikmath
50 Time Series Talk : White Noise
Time Series Talk : White Noise
ritvikmath
51 Time Series Talk : Stationarity
Time Series Talk : Stationarity
ritvikmath
52 Time Series Talk : ARIMA Model
Time Series Talk : ARIMA Model
ritvikmath
53 Time Series Talk : Lag Operator
Time Series Talk : Lag Operator
ritvikmath
54 Time Series Talk : What is Seasonality ?
Time Series Talk : What is Seasonality ?
ritvikmath
55 Time Series Talk : Seasonal ARIMA Model
Time Series Talk : Seasonal ARIMA Model
ritvikmath
56 So ... What Actually is a Matrix ? : Data Science Basics
So ... What Actually is a Matrix ? : Data Science Basics
ritvikmath
57 Derivative of a Matrix : Data Science Basics
Derivative of a Matrix : Data Science Basics
ritvikmath
58 Basics of PCA (Principal Component Analysis) : Data Science Concepts
Basics of PCA (Principal Component Analysis) : Data Science Concepts
ritvikmath
59 Eigenvalues & Eigenvectors : Data Science Basics
Eigenvalues & Eigenvectors : Data Science Basics
ritvikmath
60 The Covariance Matrix : Data Science Basics
The Covariance Matrix : Data Science Basics
ritvikmath

This video provides an intuitive understanding of autocorrelation and partial autocorrelation in time series forecasting, and shows how to use PACF plots to identify a good time series model. The video covers the calculation of PACF values and the use of regression analysis to model time series data.

Key Takeaways
  1. Use a toy example to predict the average monthly price of salmon based on previous months' prices
  2. Draw a causal diagram to illustrate the relationship between the price of salmon in different months
  3. Write a regression model with lagged variables
  4. Calculate PACF values for different lags
  5. Plot PACF values with error bands
  6. Draw a PACF plot to identify a good time series model
  7. Use the PACF plot to determine the number of past periods to include in the model
  8. Build an AR model by including the coefficients of the past periods in the model
  9. Test the AR model to see if it is a good fit for the data
💡 The PACF plot is a powerful tool for identifying a good time series model, and can be used to determine the number of past periods to include in the model.

Related Reads

📰
Best YouTube Channels to Learn Data Engineering
Learn data engineering with these top YouTube channels and enhance your skills in handling large datasets
Medium · AI
📰
Best YouTube Channels to Learn Data Engineering
Discover top YouTube channels for learning data engineering and boost your skills in handling large datasets
Medium · Machine Learning
📰
When Does a Patient Become a Number? Insights from 500 Hospital Records
Learn how data analysis of 500 hospital records reveals insights into patient flow, clinical patterns, and financial performance, and why it matters for healthcare improvement
Medium · Data Science
📰
SQL Aggregate Functions: COUNT, SUM, MIN, MAX, and AVG Explained
Learn SQL aggregate functions to summarize large datasets and gain insights
Medium · Data Science
Up next
How to Track #woocommerce #sales with #google Tag Manager
Quick Tips - Web Desiign & Ai Tools
Watch →