0

I am trying to implement time series stationarity tests on my data. When I carry out ADF (Augmented Dickey-Fuller) and KPSS tests on my data the p values suggest time series stationarity. However, when I check for the trend in the data using the Mann-Kendall test, few of the variables exhibit trends significant at 95%. Here is my python code and data

import pandas as pd
from statsmodels.tsa.stattools import adfuller, kpss
import pymannkendall as mk

data=pd.read_csv("data.csv") for dt in data.columns: # ADF Test result = mk.original_test(data[dt].values) print(f'Has trend ?: {result[0]}') print(f'p-value: {result[2]}') if result[2] < 0.05: print("\033[91m" + "\033[1m" + dt," : is having trend and should be detrended" + "\033[0m" + "\033[00m") else: print("\033[1m"+"\033[92m" + dt, " : is having no trend significant at 95% \033[0m \033[00m")

This results in:

Has trend ?: increasing
p-value: 4.7239192265680074e-05
SH  : is having trend and should be detrended
Has trend ?: increasing
p-value: 8.777005788829229e-10
SM  : is having trend and should be detrended
Has trend ?: increasing
p-value: 0.0
ET  : is having trend and should be detrended
Has trend ?: no trend
p-value: 0.6203444180928148
T2M  : is having no trend significant at 95%  
Has trend ?: increasing
p-value: 0.0
LAI  : is having trend and should be detrended
Has trend ?: no trend
p-value: 0.5470185025475132
RAIN  : is having no trend significant at 95% 

and here are the results for KPSS And ADF tests:

for dt in data.columns:
    # ADF Test
    result = adfuller(data[dt].values, autolag='AIC')
    print(f'\033[1m ADF Statistic: [\033[0m {result[0]}')
    print(f'p-value: {result[1]}')
    for key, value in result[4].items():
        print('Critical Values:')
        print(f'   {key}, {value}')
    if result[1] < 0.05:
        print("\033[92m" + "\033[1m" + dt," : is stationary at 95% significance level" + "\033[0m" + "\033[00m")
    else:
        print("\033[1m \033[91m"  + dt, " : is non stationary \033[00m \033[0m")
#KPSS Test
result = kpss(data.SM.values, regression='ct')
print('\n \033[1m KPSS Statistic: \033[0m %f' % result[0])
print('p-value: %f' % result[1])
for key, value in result[3].items():
    print('Critial Values:')
    print(f'   {key}, {value}')
if result[1] &lt; 0.05:
    print(&quot;\033[91m&quot; + &quot;\033[1m&quot; + dt,&quot; : is non stationary&quot; + &quot;\033[0m&quot; + &quot;\033[00m&quot;)
else:
    print(&quot;\033[1m \033[92m&quot;  + dt, &quot; : is stationary \033[00m \033[0m&quot;)


 ADF Statistic: [ -7.436635144113321
p-value: 6.15875466200577e-11
Critical Values:
   1%, -3.4313487579541326
Critical Values:
   5%, -2.8619813660069457
Critical Values:
   10%, -2.5670049357030478
SH  : is stationary at 95% significance level

  KPSS Statistic:  0.018727
p-value: 0.100000
Critial Values:
   10%, 0.119
Critial Values:
   5%, 0.146
Critial Values:
   2.5%, 0.176
Critial Values:
   1%, 0.216
 SH  : is stationary  
/home/user/anaconda3/envs/tigra2/lib/python3.9/site-packages/statsmodels/tsa/stattools.py:2022: InterpolationWarning: The test statistic is outside of the range of p-values available in the
look-up table. The actual p-value is greater than the p-value returned.

  warnings.warn(
 ADF Statistic: [ -6.896930535564632
p-value: 1.3116185813576234e-09
Critical Values:
   1%, -3.4313502857070044
Critical Values:
   5%, -2.861982041030084
Critical Values:
   10%, -2.5670052950322177
SM  : is stationary at 95% significance level

  KPSS Statistic:  0.018727
p-value: 0.100000
Critial Values:
   10%, 0.119
Critial Values:
   5%, 0.146
Critial Values:
   2.5%, 0.176
Critial Values:
   1%, 0.216
 SM  : is stationary  
/home/user/anaconda3/envs/tigra2/lib/python3.9/site-packages/statsmodels/tsa/stattools.py:2022: InterpolationWarning: The test statistic is outside of the range of p-values available in the
look-up table. The actual p-value is greater than the p-value returned.

  warnings.warn(
 ADF Statistic: [ -6.4243082678570085
p-value: 1.7599855059051156e-08
Critical Values:
   1%, -3.4313501327214255
Critical Values:
   5%, -2.86198197343487
Critical Values:
   10%, -2.5670052590498456
ET  : is stationary at 95% significance level

  KPSS Statistic:  0.018727
p-value: 0.100000
Critial Values:
   10%, 0.119
Critial Values:
   5%, 0.146
Critial Values:
   2.5%, 0.176
Critial Values:
   1%, 0.216
 ET  : is stationary  
/home/user/anaconda3/envs/tigra2/lib/python3.9/site-packages/statsmodels/tsa/stattools.py:2022: InterpolationWarning: The test statistic is outside of the range of p-values available in the
look-up table. The actual p-value is greater than the p-value returned.

  warnings.warn(
 ADF Statistic: [ -6.930313520628159
p-value: 1.0883715043867705e-09
Critical Values:
   1%, -3.4313504387393934
Critical Values:
   5%, -2.8619821086459765
Critical Values:
   10%, -2.5670053310255985
T2M  : is stationary at 95% significance level

  KPSS Statistic:  0.018727
p-value: 0.100000
Critial Values:
   10%, 0.119
Critial Values:
   5%, 0.146
Critial Values:
   2.5%, 0.176
Critial Values:
   1%, 0.216
 T2M  : is stationary  
/home/user/anaconda3/envs/tigra2/lib/python3.9/site-packages/statsmodels/tsa/stattools.py:2022: InterpolationWarning: The test statistic is outside of the range of p-values available in the
look-up table. The actual p-value is greater than the p-value returned.

  warnings.warn(
 ADF Statistic: [ -7.5553044480136595
p-value: 3.110897529034228e-11
Critical Values:
   1%, -3.4313483005378655
Critical Values:
   5%, -2.8619811639018327
Critical Values:
   10%, -2.56700482811821
LAI  : is stationary at 95% significance level

  KPSS Statistic:  0.018727
p-value: 0.100000
Critial Values:
   10%, 0.119
Critial Values:
   5%, 0.146
Critial Values:
   2.5%, 0.176
Critial Values:
   1%, 0.216
 LAI  : is stationary  
/home/user/anaconda3/envs/tigra2/lib/python3.9/site-packages/statsmodels/tsa/stattools.py:2022: InterpolationWarning: The test statistic is outside of the range of p-values available in the
look-up table. The actual p-value is greater than the p-value returned.

  warnings.warn(
 ADF Statistic: [ -7.593516612804492
p-value: 2.495092068287024e-11
Critical Values:
   1%, -3.4313499797826355
Critical Values:
   5%, -2.8619819058603264
Critical Values:
   10%, -2.5670052230784766
RAIN  : is stationary at 95% significance level

  KPSS Statistic:  0.018727
p-value: 0.100000
Critial Values:
   10%, 0.119
Critial Values:
   5%, 0.146
Critial Values:
   2.5%, 0.176
Critial Values:
   1%, 0.216
 RAIN  : is stationary 

Which is true? does the trend in data doesn't signify stationarity? Can stationary time series have a trend?

  • I do not know Python and hence cannot say anything about what your code precisely does, but there are versions of ADF that test if the series is stationary around a linear trend, see e.g. https://stats.stackexchange.com/questions/213551/how-is-the-augmented-dickey-fuller-test-adf-table-of-critical-values-calculate/213589#213589 – Christoph Hanck Nov 04 '22 at 12:37
  • Thank you Christoph, Will check that out – Vinayak Huggannavar Nov 09 '22 at 10:35

0 Answers0