Open In App

Autocorrelation and Partial Autocorrelation

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.



Here:

Interpretation

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.

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

                    

Output:

Autocorrelation

Now Plot ACF

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

                    

Output:

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.

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.

Here:

Interpretation

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

                    

Output:

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.

Perform both on a Time series dataset to compare

# 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:

Time Series Plot

Plot ACF

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

                    

Output:

Autocorrelation Plot

Plot PACF for differenced time series

# 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:

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.

Additional Considerations

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.



Article Tags :