Get startedGet started for free

Estimate Order of Model: PACF

One useful tool to identify the order of an AR model is to look at the Partial Autocorrelation Function (PACF). In this exercise, you will simulate two time series, an AR(1) and an AR(2), and calculate the sample PACF for each. You will notice that for an AR(1), the PACF should have a significant lag-1 value, and roughly zeros after that. And for an AR(2), the sample PACF should have significant lag-1 and lag-2 values, and zeros after that.

Just like you used the plot_acf function in earlier exercises, here you will use a function called plot_pacf in the statsmodels module.

This exercise is part of the course

Time Series Analysis in Python

View Course

Exercise instructions

  • Import the modules for simulating data and for plotting the PACF
  • Simulate an AR(1) with \(\small \phi=0.6\) (remember that the sign for the AR parameter is reversed)
  • Plot the PACF for simulated_data_1 using the plot_pacf function
  • Simulate an AR(2) with \(\small \phi_1=0.6, \phi_2=0.3\) (again, reverse the signs)
  • Plot the PACF for simulated_data_2 using the plot_pacf function

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import the modules for simulating data and for plotting the PACF
from statsmodels.tsa.arima_process import ArmaProcess
from statsmodels.graphics.tsaplots import plot_pacf

# Simulate AR(1) with phi=+0.6
ma = np.array([1])
ar = np.array([1, -0.6])
AR_object = ArmaProcess(ar, ma)
simulated_data_1 = ___.generate_sample(nsample=5000)

# Plot PACF for AR(1)
plot_pacf(___, lags=20)
plt.show()

# Simulate AR(2) with phi1=+0.6, phi2=+0.3
ma = np.array([1])
ar = np.array([1, ___, ___])
AR_object = ArmaProcess(ar, ma)
simulated_data_2 = ___.generate_sample(nsample=5000)

# Plot PACF for AR(2)
plot_pacf(___, lags=20)
plt.show()
Edit and Run Code