Is Temperature a Random Walk (with Drift)?
An ARMA model is a simplistic approach to forecasting climate changes, but it illustrates many of the topics covered in this class.
The DataFrame temp_NY
contains the average annual temperature in Central Park, NY from 1870-2016 (the data was downloaded from the NOAA here). Plot the data and test whether it follows a random walk (with drift).
Diese Übung ist Teil des Kurses
Time Series Analysis in Python
Anleitung zur Übung
- Convert the index of years into a datetime object using
pd.to_datetime()
, and since the data is annual, pass the argumentformat='%Y'
. - Plot the data using
.plot()
- Compute the p-value the Augmented Dickey Fuller test using the
adfuller
function. - Save the results of the ADF test in
result
, and print out the p-value inresult[1]
.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Import the adfuller function from the statsmodels module
from statsmodels.tsa.stattools import adfuller
# Convert the index to a datetime object
temp_NY.index = pd.to_datetime(___.___, format=___)
# Plot average temperatures
temp_NY.___
plt.show()
# Compute and print ADF p-value
result = ___(temp_NY['TAVG'])
print("The p-value for the ADF test is ", result[1])