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.
Diese Übung ist Teil des Kurses
Time Series Analysis in Python
Anleitung zur Übung
- 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_1using theplot_pacffunction - Simulate an AR(2) with \(\small \phi_1=0.6, \phi_2=0.3\) (again, reverse the signs)
- Plot the PACF for
simulated_data_2using theplot_pacffunction
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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()