Modellordnung schätzen: PACF
Ein hilfreiches Werkzeug, um die Ordnung eines AR-Modells zu bestimmen, ist die Partielle Autokorrelationsfunktion (PACF). In dieser Übung simulierst du zwei Zeitreihen, eine AR(1) und eine AR(2), und berechnest die Stichproben-PACF für beide. Du wirst sehen: Für ein AR(1) sollte die PACF bei Lag 1 einen signifikanten Wert haben und danach ungefähr null sein. Für ein AR(2) sollte die Stichproben-PACF bei Lag 1 und Lag 2 signifikante Werte haben und danach null sein.
Ähnlich wie du zuvor die Funktion plot_acf verwendet hast, nutzt du hier eine Funktion namens plot_pacf aus dem statsmodels-Modul.
Diese Übung ist Teil des Kurses
Zeitreihenanalyse in Python
Anleitung zur Übung
- Importiere die Module zum Simulieren von Daten und zum Plotten der PACF
- Simuliere ein AR(1) mit \(\small \phi=0.6\) (denk daran: Das Vorzeichen des AR-Parameters ist umgekehrt)
- Plotte die PACF für
simulated_data_1mit der Funktionplot_pacf - Simuliere ein AR(2) mit \(\small \phi_1=0.6, \phi_2=0.3\) (auch hier: Vorzeichen umkehren)
- Plotte die PACF für
simulated_data_2mit der Funktionplot_pacf
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()