Skip to content

Instantly share code, notes, and snippets.

@dBenedek
Created July 13, 2021 11:46
Show Gist options
  • Save dBenedek/f15773abe844a56e0751cce905ea9093 to your computer and use it in GitHub Desktop.
Save dBenedek/f15773abe844a56e0751cce905ea9093 to your computer and use it in GitHub Desktop.
[Stationary tests in Python] #python #tests #stationary #statistics
# Example of the Augmented Dickey-Fuller unit root test
from statsmodels.tsa.stattools import adfuller
data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
stat, p, lags, obs, crit, t = adfuller(data)
print('stat=%.3f, p=%.3f' % (stat, p))
if p > 0.05:
print('Probably not Stationary')
else:
print('Probably Stationary')
# Example of the Kwiatkowski-Phillips-Schmidt-Shin test
from statsmodels.tsa.stattools import kpss
data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
stat, p, lags, crit = kpss(data)
print('stat=%.3f, p=%.3f' % (stat, p))
if p > 0.05:
print('Probably not Stationary')
else:
print('Probably Stationary')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment