class_docstr: Conduct a PP test for stationarity.
  
  In statistics, the Phillips–Perron test (named after Peter C. B.
  Phillips and Pierre Perron) is a unit root test. It is used in time series
  analysis to test the null hypothesis that a time series is integrated of
  order 1. It builds on the Dickey–Fuller test of the null hypothesis
  ``p = 0``.
  
  Parameters
  ----------
  alpha : float, optional (default=0.05)
      Level of the test
  
  lshort : bool, optional (default=True)
      Whether or not to truncate the ``l`` value in the C code.
  
  Notes
  -----
  This test is generally used indirectly via the
  :func:`pmdarima.arima.ndiffs` function, which computes the
  differencing term, ``d``.
  
  The R code allows for two types of tests: 'Z(alpha)' and 'Z(t_alpha)'.
  Since sklearn does not allow extraction of std errors from the linear
  model fit, ``t_alpha`` is much more difficult to achieve, so we do not
  allow that variant.
  
  References
  ----------
  .. [1] R's tseries PP test source code: http://bit.ly/2wbzx6V
class_docstr_tok: ["Conduct","a","PP","test","for","stationarity",".","In","statistics",",","the","Phillips\u2013Perron","test","(","named","after","Peter","C.","B.","Phillips","and","Pierre","Perron",")","is","a","unit","root","test",".","It","is","used","in","time","series","analysis","to","test","the","null","hypothesis","that","a","time","series","is","integrated","of","order","1",".","It","builds","on","the","Dickey\u2013Fuller","test","of","the","null","hypothesis","``","p","=","0","``",".","Parameters","--","--","--","--","--","alpha",":","float",",","optional","(","default=0.05",")","Level","of","the","test","lshort",":","bool",",","optional","(","default=True",")","Whether","or","not","to","truncate","the","``","l","``","value","in","the","C","code",".","Notes","--","--","-","This","test","is","generally","used","indirectly","via","the",":","func",":","`","pmdarima.arima.ndiffs","`","function",",","which","computes","the","differencing","term",",","``","d","``",".","The","R","code","allows","for","two","types","of","tests",":","'","Z","(","alpha",")","'","and","'","Z","(","t_alpha",")","'",".","Since","sklearn","does","not","allow","extraction","of","std","errors","from","the","linear","model","fit",",","``","t_alpha","``","is","much","more","difficult","to","achieve",",","so","we","do","not","allow","that","variant",".","References","--","--","--","--","--","..","[","1","]","R","'s","tseries","PP","test","source","code",":","http",":","\/\/bit.ly\/2wbzx6V"]
docstr: Test whether the time series is stationary or needs differencing.
  
  Parameters
  ----------
  x : array-like, shape=(n_samples,)
      The time series vector.
  
  Returns
  -------
  pval : float
      The computed P-value of the test.
  
  sig : bool
      Whether the P-value is significant at the ``alpha`` level.
      More directly, whether to difference the time series.
docstr_tok: ["Test","whether","the","time","series","is","stationary","or","needs","differencing",".","Parameters","--","--","--","--","--","x",":","array-like",",","shape=","(","n_samples",",",")","The","time","series","vector",".","Returns","--","--","--","-","pval",":","float","The","computed","P-value","of","the","test",".","sig",":","bool","Whether","the","P-value","is","significant","at","the","``","alpha","``","level",".","More","directly",",","whether","to","difference","the","time","series","."]
code: def should_diff(self, x):
      """Test whether the time series is stationary or needs differencing.
  
      Parameters
      ----------
      x : array-like, shape=(n_samples,)
          The time series vector.
  
      Returns
      -------
      pval : float
          The computed P-value of the test.
  
      sig : bool
          Whether the P-value is significant at the ``alpha`` level.
          More directly, whether to difference the time series.
      """
      if not self._base_case(x):
          return np.nan, False
  
      # ensure vector
      x = check_endog(x, dtype=DTYPE, preserve_series=False)
  
      # embed the vector. This is some funkiness that goes on in the R
      # code... basically, make a matrix where the column (rows if not T)
      # are lagged windows of x
      z = self._embed(x, 2)  # Same as R t(embed(x, k))
      yt = z[0, :]
      yt1 = z[1, :]  # type: np.ndarray
  
      # fit a linear model to a predictor matrix
      n = yt.shape[0]
      tt = (np.arange(n) + 1) - (n / 2.0)
      X = np.array([np.ones(n), tt, yt1]).T
      res = LinearRegression().fit(X, yt)  # lm(yt ~ 1 + tt + yt1)
      coef = res.coef_
  
      # check for singularities - do we want to do this??? in the R code,
      # it happens. but the very same lm in the R code is rank 3, and here
      # it is rank 2. Should we just ignore?...
      # if res.rank_ < 3:
      #     raise ValueError('singularities in regression')
  
      u = yt - res.predict(X)  # residuals
      ssqru = (u * u).sum() / float(n)
  
      scalar = 12 if not self.lshort else 4
      l_ = int(np.trunc(scalar * np.power(n / 100.0, 0.25)))
      ssqrtl = C_tseries_pp_sum(u, n, l_, ssqru)
  
      # define trm vals
      n2 = n * n
      syt11n = (yt1 * (np.arange(n) + 1)).sum()  # sum(yt1*(1:n))
      trm1 = n2 * (n2 - 1) * (yt1**2).sum() / 12.0
  
      # R code: # n*sum(yt1*(1:n))^2
      trm2 = n * (syt11n**2)
  
      # R code: n*(n+1)*sum(yt1*(1:n))*sum(yt1)
      trm3 = n * (n + 1) * syt11n * yt1.sum()
      trm4 = (n * (n + 1) * (2 * n + 1) * (yt1.sum() ** 2)) / 6.0
      dx = trm1 - trm2 + trm3 - trm4
  
      # if self.typ == 'alpha':
      alpha = coef[2]  # it's the last col...
      STAT = n * (alpha - 1) - (n**6) / (24.0 * dx) * (ssqrtl - ssqru)
  
      tableipl = np.array(
          [
              approx(self.tableT, self.table[:, i], xout=n, rule=2)[1]
              for i in range(self.tablen)
          ]
      )
  
      # we don't do 1 - pval, so check for GREATER THAN
      _, interpol = approx(tableipl, self.tablep, xout=STAT, rule=2)
      pval = interpol[0]
  
      # in the R code, here is where the P value warning is tested again...
      return pval, pval > self.alpha
  
imports: from sklearn.base import BaseEstimator
  from sklearn.linear_model import LinearRegression
  from statsmodels import api
  from abc import ABCMeta, abstractmethod
  import numpy
  from ..compat.numpy import DTYPE
  from ..decorators import deprecated
  from ..utils.array import c, diff, check_endog
  from .approx import approx
  from ._arima import C_tseries_pp_sum
label_desc: Use image node_id 2 for calling the PPTest obj's underlying member method code with example usage: obj.should_diff(x) and returns: pval,  unknown, np,  False