Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Science
  • Data Science Projects
  • Data Analysis
  • Data Visualization
  • Machine Learning
  • ML Projects
  • Deep Learning
  • NLP
  • Computer Vision
  • Artificial Intelligence
Open In App
Next Article:
Autocorrelation and Partial Autocorrelation
Next article icon

Autocorrelation and Partial Autocorrelation

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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.



Next Article
Autocorrelation and Partial Autocorrelation

M

manojjai07nu
Improve
Article Tags :
  • Geeks Premier League
  • R Machine Learning
  • AI-ML-DS
  • Geeks Premier League 2023

Similar Reads

    Partial Autocorrelation Function in R
    In time series analysis, understanding the relationships between data points over time is crucial for making accurate predictions and informed decisions. One of the key tools in this analysis is the Partial Autocorrelation Function (PACF). PACF helps us gauge how current observations in a time serie
    6 min read
    How to Calculate Autocorrelation in R?
    In this article, we will calculate autocorrelation in R programming language Autocorrelation is used to measure the degree of similarity between a time series and a lagged version of itself over the given range of time intervals. We can also call autocorrelation as  “serial correlation” or “lagged c
    2 min read
    How to Calculate Partial Correlation in Excel?
    Partial correlation helps find the correlation between the two variables by removing the effect of the third variable. There can be situations when the relations between variables can be many. This could reduce the accuracy of correlation or could also give wrong results. Partial correlation removes
    5 min read
    Correlation and Regression
    Correlation and regression are essential statistical tools used to analyze the relationship between variables. Correlation measures the strength and direction of a linear relationship between two variables, indicating how one variable changes in response to another. Regression, on the other hand, go
    8 min read
    How to Calculate Partial Correlation in R?
    In this article, we will discuss how to calculate Partial Correlation in the R Programming Language. Partial Correlation helps measure the degree of association between two random variables when there is the effect of other variables that control them. in partial correlation in machine learning It g
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences