![]() |
VOOZH | about |
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 series relate to past observations while controlling for the influence of intervening values. This article clears the concept of PACF, its importance in modeling, and practical implementations using R.
Partial Autocorrelation measures the correlation between the observations at the time t and t-k, but after removing the effects of the values in between (e.g., at time t-1, t-2, β¦, t-(k-1)). It's particularly useful when building autoregressive (AR) models because it helps identify the order of the model (the number of lags to include).
Formula:
Here,
Feature | Autocorrelation (ACF) | Partial Autocorrelation (PACF) |
|---|---|---|
Definition | Measures the correlation between a time series and its past values across different lags. | Measures the direct correlation between a time series and its lag, removing the effect of intermediate lags. |
Purpose | Shows the overall relationship between values at various time lags. | Shows the direct relationship at specific lags, ignoring the influence of other lags. |
Plot Interpretation | Gradual decline in spikes indicates trend or seasonal patterns. | Sharp decline after a few lags suggests autoregressive order. |
Effect of Intermediate Lags | Includes the impact of all previous lags. | Ignores the effect of intermediate lags and focuses only on the direct correlation with a specific lag. |
Used for Identifying | Moving Average (MA) components in time series models. | Autoregressive (AR) components in time series models. |
Typical Plot Pattern | Often shows a gradual decay if there is a trend or seasonality. | Typically cuts off after a certain lag if the AR process is stationary. |
Example | Correlation between todayβs value and all past values (1 day ago, 2 days ago, etc.). | Correlation between todayβs value and a specific lag (like 2 days ago), excluding the effect of 1 day ago. |
Now we implement Partial Autocorrelation Function in Time Series Using R Programming Language.
First, install and load the necessary libraries.
Now load the dataset and check first few rows.
Output:
Jan Feb Mar Apr May Jun
1949 112 118 132 129 121 135
To visualize the data, we can plot the time series.
Output:
Before performing PACF or fitting an ARIMA model, we need to check whether the series is stationary.
Output:
Augmented Dickey-Fuller Test
data: AirPassengers
Dickey-Fuller = -7, Lag order = 5, p-value = 0.01
alternative hypothesis: stationary
If the p-value is greater than 0.05, the series is non-stationary, meaning it has trends or seasonality and needs differencing.
Now, to compute and plot the partial autocorrelation, use the pacf() function.
Output:
Here, A sharp cutoff after a few lags indicates the appropriate lag order for an autoregressive (AR) model. For example, if the PACF plot shows significant correlations only up to lag 1 or 2, you might consider an AR(1) or AR(2) model.
Now build a ARIMA Model from PACF.
Output:
Series: AirPassengers
ARIMA(2,1,0)
Coefficients:
ar1 ar2
0.381 -0.228
s.e. 0.082 0.083
sigma^2 = 991: log likelihood = -695
AIC=1397 AICc=1397 BIC=1405
Training set error measures:
ME RMSE MAE MPE MAPE MASE ACF1
Training set 2.04 31.2 24.5 0.416 8.68 0.764 -0.036
Next, we need to check the residuals to ensure that the model is adequate.
Output:
Ljung-Box test
data: Residuals from ARIMA(2,1,0)
Q* = 235, df = 22, p-value <2e-16
Model df: 2. Total lags used: 24
Box-Ljung test
data: residuals(model)
X-squared = 0.2, df = 1, p-value = 0.7
Now forecast the future values.
Output:
Now compare the actual vs forecasted values.
Output:
The Partial Autocorrelation Function (PACF) is a vital tool in time series analysis, providing valuable insights into the direct relationships between past and present values. By interpreting PACF plots, analysts can make informed decisions regarding model selection and forecasting. In combination with other tools like the Autocorrelation Function (ACF), PACF enhances our ability to understand and model complex time series data effectively.