Autocorrelation and Partial Autocorrelation

Last Updated : 22 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Autocorrelation and partial autocorrelation are statistical measures that help analyze the relationship between a time series and its lagged values. In R Programming Language, the acf() and pacf() functions can be used to compute and visualize autocorrelation and partial autocorrelation, respectively.

Autocorrelation

Autocorrelation measures the linear relationship between a time series and its lagged values. In simpler terms, it assesses how much the current value of a series depends on its past values. Autocorrelation is fundamental in time series analysis, helping identify patterns and dependencies within the data.

Mathematical Representation

The autocorrelation function (ACF) at lag k for a time series.

\rho_k = \frac{\text{Cov}(X_t, X_{t-k})}{\sqrt{\text{Var}(X_t) \cdot \text{Var}(X_{t-k})}}

Here:

  • Cov() is the covariance function.
  • Var() is the variance function.
  • k is the lag.
  • x_t​ is the value of the time series at time t.
  • x_{t-k} is the value of the time series at time t-k

Interpretation

  • Positive ACF: A positive ACF at lag k indicates a positive correlation between the current observation and the observation at lag k.
  • Negative ACF: A negative ACF at lag k indicates a negative correlation between the current observation and the observation at lag k.
  • Decay in ACF: The decay in autocorrelation as lag increases often signifies the presence of a trend or seasonality in the time series.
  • Significance: Significant ACF values at certain lags may suggest potential patterns or relationships in the time series.

Let’s take an example with a real-world dataset to illustrate the differences between the Autocorrelation Function (ACF) and Partial Autocorrelation Function (PACF). In this example, we’ll use the “AirPassengers” dataset in R, which represents monthly totals of international airline passengers.

R

# Load necessary libraries
library(forecast)
 
# Load AirPassengers dataset
data("AirPassengers")
 
# Plot the time series
plot(AirPassengers, main = "Monthly International Airline Passengers")

                    

Output:

gh

Autocorrelation

Now Plot ACF

R

# Plot ACF
acf(AirPassengers, main = "Autocorrelation Function (ACF) for AirPassengers")

                    

Output:

gh

Autocorrelation

we use the same “AirPassengers” dataset and plot the PACF. The PACF plot shows the direct correlation at each lag, helping identify the order of autoregressive terms.

  • The ACF plot reveals a decaying pattern, indicating a potential seasonality in the data. Peaks at multiples of 12 (12, 24, …) suggest a yearly cycle, reflecting the seasonal nature of airline passenger data.
  • The ACF plot gives a comprehensive view of the correlation at all lags, showing how each observation relates to its past values.

Partial Autocorrelation

Partial autocorrelation removes the influence of intermediate lags, providing a clearer picture of the direct relationship between a variable and its past values. Unlike autocorrelation, partial autocorrelation focuses on the direct correlation at each lag.

Mathematical Representation

The partial autocorrelation function (PACF) at lag k for a time series.

\phi_k = \frac{\text{cov}(X_t, X_{t-k} \mid X_{t-1}, X_{t-2}, \ldots, X_{t-k+1})}{\sqrt{\text{var}(X_t \mid X_{t-1}, X_{t-2}, \ldots, X_{t-k+1}) \cdot \text{var}(X_{t-k} \mid X_{t-1}, X_{t-2}, \ldots, X_{t-k+1})}}

Here:

  • X_t is the value of the time series at time.
  • X_{t-k}​: is the value of the time series at time (t-k)
  • \text{cov}(X_t, X_{t-k} \mid X_{t-1}, X_{t-2}, \ldots, X_{t-k+1}) is the conditional covariance between X_t and X_{t-k} given the values of the intermediate lags.
  • \text{var}(X_t \mid X_{t-1}, X_{t-2}, \ldots, X_{t-k+1}) is the conditional variance of X_t given the values of the intermediate lags.
  • \text{var}(X_{t-k} \mid X_{t-1}, X_{t-2}, \ldots, X_{t-k+1}) is the conditional variance of X_{t-k} given the values of the intermediate lags.

Interpretation

  • Direct Relationship: PACF isolates the direct correlation between the current observation and the observation at lag k, controlling for the influence of lags in between.
  • AR Process Identification: Peaks or significant values in PACF at specific lags can indicate potential orders for autoregressive (AR) terms in time series models.
  • Modeling Considerations: Analysts often examine PACF to guide the selection of lag orders in autoregressive integrated moving average (ARIMA) models.

R

# Load necessary libraries
library(forecast)
 
# Load AirPassengers dataset
data("AirPassengers")
 
# Plot PACF
pacf_result <- pacf(AirPassengers,
                    main = "Partial Autocorrelation Function (PACF) for AirPassengers")

                    

Output:

gh

Partial Autocorrelation

we use the same “AirPassengers” dataset and plot the PACF. The PACF plot shows the direct correlation at each lag, helping identify the order of autoregressive terms.

  • The PACF plot helps identify the direct correlation at each lag. Peaks at lags 1 and 12 suggest potential autoregressive terms related to the monthly and yearly patterns in the data.
  • The PACF plot, on the other hand, focuses on the direct correlation at each lag, providing insights into the order of autoregressive terms.
  • By comparing the two plots, you can observe how they complement each other in revealing the temporal dependencies within the time series. The ACF helps identify overall patterns, while the PACF refines the analysis by highlighting direct correlations.

Perform both on a Time series dataset to compare

R

# Load necessary libraries
library(fpp2)
 
# Load the "ausbeer" dataset from fpp2 package
data("ausbeer")
 
# Plot the time series
autoplot(ausbeer, main = "Monthly Australian Beer Production")

                    

Output:

gh

Time Series Plot

Plot ACF

R

# Plot ACF
acf(ausbeer, main = "Autocorrelation Function (ACF) for Australian Beer Production")

                    

Output:

gh

Autocorrelation Plot

Plot PACF for differenced time series

R

# Load PACF from the forecast package
library(forecast)
 
# Plot PACF for differenced time series
diff_ausbeer <- diff(ausbeer)
pacf_result <- pacf(diff_ausbeer,main = "Partial Autocorrelation Function (PACF) for
                                  Differenced Australian Beer Production")

                    

Output:

gh

Partial Autocorrelation Plot

In this example, we use the “ausbeer” dataset from the fpp2 package, which represents monthly Australian beer production. The ACF plot can provide insights into the potential seasonality and trends in beer production.

  • Autocorrelation (ACF): The ACF plot for Australian beer production may reveal patterns related to seasonality, trends, or cyclic behavior. Peaks at certain lags could indicate recurring patterns in beer production.
  • Partial Autocorrelation (PACF): Differencing the time series and examining the PACF helps identify potential autoregressive terms that capture the direct correlation at each lag, after removing the influence of trends.

Additional Considerations

    • Seasonal Differencing: In some cases, it might be beneficial to apply seasonal differencing (e.g., differencing by 12 for monthly data) to handle seasonality properly.
    • Seasonal Differencing: In some cases, it might be beneficial to apply seasonal differencing (e.g., differencing by 12 for monthly data) to handle seasonality properly.
    • Model Selection: The combination of ACF and PACF analysis can guide the selection of parameters in time series models, such as autoregressive integrated moving average (ARIMA) models.
    • Interpretation: Understanding the patterns revealed by ACF and PACF is crucial for interpreting the underlying dynamics of a time series and building accurate forecasting models.

Difference between Autocorrelation and Partial Autocorrelation

Autocorrelation (ACF) and Partial Autocorrelation (PACF) are both measures used in time series analysis to understand the relationships between observations at different time points.

Autocorrelation

Partial Autocorrelation

Used for identifying the order of a moving average (MA) process.

Used for identifying the order of an autoregressive (AR) process.

Represents the overall correlation structure of the time series.

Highlights the direct relationships between observations at specific lags.

Autocorrelation measures the linear relationship between an observation and its previous observations at different lags.

Partial Autocorrelation measures the direct linear relationship between an observation and its previous observations at a specific lag, excluding the contributions from intermediate lags.

Conclusion

ACF and PACF are critical tools in time series analysis, providing insights into temporal dependencies within a dataset. These functions aid in understanding the structure of the data, identifying potential patterns, and guiding the construction of time series models for accurate forecasting. By examining ACF and PACF, analysts gain valuable information about the underlying dynamics of the time series they are studying.




Similar Reads

Understanding Partial Autocorrelation Functions (PACF) in Time Series Data
Partial autocorrelation functions (PACF) play a pivotal role in time series analysis, offering crucial insights into the relationship between variables while mitigating confounding influences. In essence, PACF elucidates the direct correlation between a variable and its lagged values after removing the effects of intermediary time steps. This stati
9 min read
Types of Autocorrelation
Autocorrelation: As we discussed in this article, Autocorrelation is defined as the measure of the degree of similarity between a given time series and the lagged version of that time series over successive time periods. Autocorrelation measures the degree of similarity between a time series and the lagged version of that time series at different i
4 min read
AutoCorrelation
Autocorrelation is a fundamental concept in time series analysis. Autocorrelation is a statistical concept that assesses the degree of correlation between the values of variable at different time points. The article aims to discuss the fundamentals and working of Autocorrelation. Table of Content What is Autocorrelation?What is Partial Autocorrelat
10 min read
How to Test the Autocorrelation of the Residuals in R?
Autocorrelation in residuals is a critical aspect of time series analysis and regression modeling. It refers to the correlation of a signal with a delayed copy of itself as a function of delay. Autocorrelation in residuals indicates that there is some pattern left in the residuals that the model has not captured, which can lead to inefficiency in t
4 min read
NLP | Partial parsing with Regex
Defining a grammar to parse 3 phrase types. ChunkRule class that looks for an optional determiner followed by one or more nouns is used for noun phrases. To add an adjective to the front of a noun chunk, MergeRule class is used. Any IN word is simply chunked for the prepositional phrases. an optional modal word (such as should) followed by a verb i
2 min read
Partial Least Squares Singular Value Decomposition (PLSSVD)
Partial Least Squares Singular Value Decomposition (PLSSVD) is a sophisticated statistical technique employed in the realms of multivariate analysis and machine learning. This method merges the strengths of Partial Least Squares (PLS) and Singular Value Decomposition (SVD), offering a powerful tool to extract crucial information from high-dimension
9 min read
Partial Least Squares (PLS) Canonical
In the realm of machine learning, it’s essential to have a diverse toolkit to solve various complex problems. Partial Least Squares (PLS) Canonical, a technique rooted in both regression and dimensionality reduction, has gained significant traction in recent years. This method, which finds patterns in data by projecting it onto a lower-dimensional
7 min read
Partial Least Squares Regression (PLSRegression) using Sklearn
Partial least square regression is a Machine learning Algorithm used for modelling the relationship between independent and dependent variables. This is mainly used when there are many interrelated independent variables. It is more commonly used in regression and latent variable modelling. It finds the directions (latent variables) in the independe
8 min read
Partial differential equations (PDEs) in Deep Larning
Partial Differential Equations (PDEs) are fundamental in modeling various phenomena in science and engineering, ranging from fluid dynamics to heat transfer and quantum mechanics. Traditional numerical methods for solving PDEs, such as the finite difference method, finite element method, and finite volume method, have been effective but often compu
8 min read
How to Create a 2D Partial Dependence Plot on a Trained Random Forest Model in R
Random Forest, a powerful ensemble learning algorithm, is widely used for regression and classification tasks due to its robustness and ability to handle complex data. However, understanding how individual features influence the model's predictions can be challenging. Partial Dependence Plots (PDPs) provide a valuable tool for visualizing the relat
3 min read
MANOVA Effect Size (Partial Eta Squared) in R
Multivariate Analysis of Variance (MANOVA) is the statistical analysis method that generalizes the ANOVA test for cases when there is more than one variable to compare. In one way, it assists in determining whether the means of several groups are statistically different on several dependent variables. What is Partial Eta Squared?Partial eta squared
3 min read
Partial derivatives in Machine Learning
Partial derivatives play a vital role in the area of machine learning, notably in optimization methods like gradient descent. These derivatives help us grasp how a function changes considering its input variables. In machine learning, where we commonly deal with complicated models and high-dimensional data, knowing partial derivatives becomes vital
4 min read
How to Create a Partial Dependence Plot for a Categorical Variable in R?
Partial Dependence Plots (PDPs) are a powerful tool for understanding the relationship between predictor variables and the predicted outcome in machine learning models. PDPs are particularly useful for visualizing how a feature affects the predictions, holding other features constant. While they are commonly used for continuous variables, PDPs can
4 min read
Partial Dependence Plot from an XGBoost Model in R
Partial Dependence Plots (PDPs) are a powerful tool for interpreting complex machine-learning models. They help visualize the relationship between a subset of features and the predicted outcome, holding other features constant. In the context of XGBoost models, PDPs can provide insights into how specific features influence the model's predictions.
4 min read
Need of Data Structures and Algorithms for Deep Learning and Machine Learning
Deep Learning is a field that is heavily based on Mathematics and you need to have a good understanding of Data Structures and Algorithms to solve the mathematical problems optimally. Data Structures and Algorithms can be used to determine how a problem is represented internally or how the actual storage pattern works &amp; what is happening under
6 min read
Black and white image colorization with OpenCV and Deep Learning
In this article, we'll create a program to convert a black &amp; white image i.e grayscale image to a colour image. We're going to use the Caffe colourization model for this program. And you should be familiar with basic OpenCV functions and uses like reading an image or how to load a pre-trained model using dnn module etc. Now let's discuss the pr
3 min read
How to Implement Softmax and Cross-Entropy in Python and PyTorch
Multiclass classification is an application of deep learning/machine learning where the model is given input and renders a categorical output corresponding to one of the labels that form the output. For example, providing a set of images of animals and classifying it among cats, dogs, horses, etc. For this purpose, where the model outputs multiple
7 min read
Ethics in Data Science and Proper Privacy and Usage of Data
As we know, these days Data Science has become more popular and it is one of the emerging technologies. According to the latest estimation 328.77 million terabytes are generated every day so just think of how large the volume is. , this data may also consist of your data such as your Identity cards or your Banking information or it may be any other
8 min read
Univariate, Bivariate and Multivariate data and its analysis
In this article,we will be discussing univariate, bivariate, and multivariate data and their analysis. Univariate data: Univariate data refers to a type of data in which each observation or data point corresponds to a single variable. In other words, it involves the measurement or observation of a single characteristic or attribute for each individ
5 min read
How to sample large database and implement K-means and Knn in R
Sample large database becomes essential to reduce the amount of data for better and faster prediction. The goal is to extract a representative subset of data from a larger dataset for analysis, as it might be impractical or time-consuming to analyze the entire dataset. Whereas R is an open-source programming language and software environment for da
13 min read
Databricks Security and Governance: Ensuring Data Integrity and Compliance
In today's data-driven world, organizations are increasingly relying on platforms like Databricks to manage and analyze their data. However, with the growing volume of data comes the critical need for robust security and governance measures. This article delves into the security and governance features of Databricks, providing a comprehensive overv
8 min read
Difference between Propositional and First-Order Logic and How are they used in Knowledge Representation?
In artificial intelligence and computational logic, two fundamental types of logic are widely used for knowledge representation: propositional logic and first-order logic. These logical systems provide the foundation for constructing and manipulating knowledge in a formal and precise manner. This article explores the key differences between proposi
7 min read
Optimizing Customer Experience with AI and Big Data: Strategies and Tools
In today’s hyper-competitive business landscape, delivering an exceptional customer experience (CX) has become a critical differentiator. As customer expectations continue to evolve, companies are increasingly turning to advanced technologies such as Artificial Intelligence (AI) and Big Data to enhance their CX strategies. These technologies offer
7 min read
Graphs, Automatic Differentiation and Autograd in PyTorch
Graphs, Automatic Differentiation and Autograd are powerful tools in PyTorch that can be used to train deep learning models. Graphs are used to represent the computation of a model, while Automatic Differentiation and Autograd allow the model to learn by updating its parameters during training. In this article, we will explore the concepts behind t
7 min read
Integration of Artificial Intelligence and BlockChain
Artificial Intelligence and Blockchain are proving to be quite a powerful combination, improving virtually every industry in which they're implemented. These technologies can be combined to upgrade everything from food supply chain logistics and healthcare record sharing to media royalties and financial security. The integration of AI and Blockchai
8 min read
Python | How and where to apply Feature Scaling?
Feature Scaling or Standardization: It is a step of Data Pre Processing that is applied to independent variables or features of data. It helps to normalize the data within a particular range. Sometimes, it also helps in speeding up the calculations in an algorithm. Package Used: sklearn.preprocessing Import: from sklearn.preprocessing import Standa
2 min read
Feature Engineering: Scaling, Normalization, and Standardization
If you are an ML practitioner then you must have come across the term feature scaling which is considered as an unskippable part of the data processing cycle so, that we can achieve stable and fast training of our ML algorithm. In this article, we will learn about different techniques which are used to perform feature scaling in practice. What is F
6 min read
What is the difference between 'SAME' and 'VALID' padding in tf.nn.max_pool of tensorflow?
Padding is a technique used in convolutional neural networks (CNNs) to preserve the spatial dimensions of the input data and prevent the loss of information at the edges of the image. It involves adding additional rows and columns of pixels around the edges of the input data. There are several different ways to apply padding in Python, depending on
14 min read
Box plot visualization with Pandas and Seaborn
Box Plot is the visual representation of the depicting groups of numerical data through their quartiles. Boxplot is also used for detect the outlier in data set. It captures the summary of the data efficiently with a simple box and whiskers and allows us to compare easily across groups. Boxplot summarizes a sample data using 25th, 50th and 75th per
2 min read
ML | Mathematical explanation of RMSE and R-squared error
RMSE: Root Mean Square Error is the measure of how well a regression line fits the data points. RMSE can also be construed as Standard Deviation in the residuals. Consider the given data points: (1, 1), (2, 2), (2, 3), (3, 6). Let us break the above data points into 1-d lists. Input: x = [1, 2, 2, 3] y = [1, 2, 3, 6] Code: Regression Graph Python C
5 min read