title: Is this time series stationary or not?
body: <p>I want to check the stationary of a time series data saved in <a href="https://github.com/Apress/mastering-ml-w-python-in-six-steps/blob/master/Chapter_3_Code/Code/Data/TS.csv" rel="nofollow noreferrer">TS.csv</a>.</p>
  
  <p>However, R's <code>tseries::adf.test()</code> and Python's <code>statsmodels.tsa.stattools.adfuller()</code>
  give completely different results.</p>
  
  <p><code>adf.test()</code> shows it's stationary (p &lt; 0.05), while <code>adfuller()</code> shows it's non-stationary (p > 0.05).</p>
  
  <p>Is there any problems in the following codes?</p>
  
  <p>What's the right process to test stationary of a time series in R and Python?</p>
  
  <p>Thanks.</p>
  
  <p>R codes:</p>
  
  <pre><code>&gt; rd &lt;- read.table('Data/TS.csv', sep = ',', header = TRUE)
  &gt; inp &lt;- ts(rd$Sales, frequency = 12, start = c(1965, 1))
  &gt; inp
       Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
  1965 154  96  73  49  36  59  95 169 210 278 298 245
  1966 200 118  90  79  78  91 167 169 289 347 375 203
  1967 223 104 107  85  75  99 135 211 335 460 488 326
  1968 346 261 224 141 148 145 223 272 445 560 612 467
  1969 518 404 300 210 196 186 247 343 464 680 711 610
  1970 613 392 273 322 189 257 324 404 677 858 895 664
  1971 628 308 324 248 272
  &gt; library(tseries)
  &gt; adf.test(inp)
  
      Augmented Dickey-Fuller Test
  
  data:  inp
  Dickey-Fuller = -7.2564, Lag order = 4, p-value = 0.01
  alternative hypothesis: stationary
  </code></pre>
  
  <p>Python codes (from <a href="https://github.com/Apress/mastering-ml-w-python-in-six-steps/blob/master/Chapter_3_Code/Code/Time_Series.ipynb" rel="nofollow noreferrer">Time_Series.ipynb</a>):</p>
  
  <pre><code>import pandas as pd
  from statsmodels.tsa.stattools import adfuller
  df = pd.read_csv('Data/TS.csv')
  ts = pd.Series(list(df['Sales']), index=pd.to_datetime(df['Month'],format='%Y-%m'))
  s_test = adfuller(ts, autolag='AIC')
  print("p value &gt; 0.05 means data is non-stationary: ", s_test[1])
  # output: p value &gt; 0.05 means data is non-stationary:  0.988889420517
  </code></pre>
  
  <h2>Update</h2>
  
  <p>@gfgm give exellent explanations why results of R and Python are different, and how to make them the same by changing the parameters.</p>
  
  <p>For the second quetsion above: "What's the right process to test stationary of a time series in R and Python?".
  I'd like to provide some details:</p>
  
  <p>When forecast a time series, ARIMA model needs the input time series to be stationary.
  If the input isn't stationary, it should be <code>log()</code>ed or <code>diff()</code>ed to make it stationary,
  then fit it into the model.</p>
  
  <p>So the problem is:
  should I think the input is stationary (with R's default parameters) and fit it directly into ARIMA model,
  or think it's non-stationary (with Python's default parameters),
  and make it stationary with extra functions (like <code>log()</code> or <code>diff()</code>)?</p>