class_docstr: Conduct a CH test for seasonality.
  
  The Canova-Hansen test for seasonal differences. Canova and Hansen
  (1995) proposed a test statistic for the null hypothesis that the seasonal
  pattern is stable. The test statistic can be formulated in terms of
  seasonal dummies or seasonal cycles. The former allows us to identify
  seasons (e.g. months or quarters) that are not stable, while the latter
  tests the stability of seasonal cycles (e.g. cycles of period 2 and 4
  quarters in quarterly data). [1]
  
  Parameters
  ----------
  m : int
      The seasonal differencing term. For monthly data, e.g., this would be
      12. For quarterly, 4, etc. For the Canova-Hansen test to work,
      ``m`` must exceed 1.
  
  Notes
  -----
  This test is generally not used directly, but in conjunction with
  :func:`pmdarima.arima.nsdiffs`, which directly estimates the number
  of seasonal differences.
  
  References
  ----------
  .. [1] Testing for seasonal stability using the Canova
         and Hansen test statistic: http://bit.ly/2wKkrZo
  
  .. [2] R source code for CH test:
         https://github.com/robjhyndman/forecast/blob/master/R/arima.R#L148
class_docstr_tok: ["Conduct","a","CH","test","for","seasonality",".","The","Canova-Hansen","test","for","seasonal","differences",".","Canova","and","Hansen","(","1995",")","proposed","a","test","statistic","for","the","null","hypothesis","that","the","seasonal","pattern","is","stable",".","The","test","statistic","can","be","formulated","in","terms","of","seasonal","dummies","or","seasonal","cycles",".","The","former","allows","us","to","identify","seasons","(","e.g",".","months","or","quarters",")","that","are","not","stable",",","while","the","latter","tests","the","stability","of","seasonal","cycles","(","e.g",".","cycles","of","period","2","and","4","quarters","in","quarterly","data",")",".","[","1","]","Parameters","--","--","--","--","--","m",":","int","The","seasonal","differencing","term",".","For","monthly","data",",","e.g.",",","this","would","be","12",".","For","quarterly",",","4",",","etc",".","For","the","Canova-Hansen","test","to","work",",","``","m","``","must","exceed","1",".","Notes","--","--","-","This","test","is","generally","not","used","directly",",","but","in","conjunction","with",":","func",":","`","pmdarima.arima.nsdiffs","`",",","which","directly","estimates","the","number","of","seasonal","differences",".","References","--","--","--","--","--","..","[","1","]","Testing","for","seasonal","stability","using","the","Canova","and","Hansen","test","statistic",":","http",":","\/\/bit.ly\/2wKkrZo","..","[","2","]","R","source","code","for","CH","test",":","https",":","\/\/github.com\/robjhyndman\/forecast\/blob\/master\/R\/arima.R","#","L148"]
code: def _sd_test(wts, s):
      # assume no NaN values since called internally
      # also assume s > 1 since called internally
      n = wts.shape[0]
  
      # no use checking, because this is an internal method
      # if n <= s:  raise ValueError('too few samples (%i<=%i)' % (n, s))
      frec = np.ones(int((s + 1) / 2), dtype=int)
      ltrunc = int(np.round(s * ((n / 100.0) ** 0.25)))
      R1 = CHTest._seas_dummy(wts, s)
  
      # fit model, get residuals
      lmch = make_pipeline(
          StandardScaler(with_mean=False), LinearRegression()
      ).fit(R1, wts)
      # lmch = sm.OLS(wts, R1).fit(method='qr')
      residuals = wts - lmch.predict(R1)
  
      # translated R code:
      # multiply the residuals by the column vectors
      # Fhataux = Fhat.copy()
      # for i in range(Fhat.shape[1]):  # for (i in 1:(s-1))
      #     Fhataux[:, i] = R1[:, i] * residuals
  
      # more efficient numpy:
      Fhataux = (R1.T * residuals).T.astype(np.float64)
  
      # translated R code
      # matrix row cumsums
      # Fhat = np.ones((n, s - 1)) * np.nan
      # for i in range(n):
      #    for n in range(Fhataux.shape[1]):
      #         Fhat[i, n] = Fhataux[:i, n].sum()
  
      # more efficient numpy:
      Ne = Fhataux.shape[0]
  
      # As of v0.9.1, use the C_canova_hansen_sd_test function to compute
      # Omnw, Omfhat, A, frecob. This avoids the overhead of multiple calls
      # to C functions
      A, AtOmfhatA = C_canova_hansen_sd_test(
          ltrunc, Ne, Fhataux, frec, s
      )
  
      # UPDATE 01/04/2018 - we can get away without computing u, v
      # (this is also MUCH MUCH faster!!!)
      sv = svd(AtOmfhatA, compute_uv=False)  # type: np.ndarray
  
      # From R:
      # double.eps: the smallest positive floating-point number ‘x’ such that
      # ‘1 + x != 1’.  It equals ‘double.base ^ ulp.digits’ if either
      # ‘double.base’ is 2 or ‘double.rounding’ is 0; otherwise, it
      # is ‘(double.base ^ double.ulp.digits) / 2’.  Normally
      # ‘2.220446e-16’.
      # Numpy's float64 has an eps of 2.2204460492503131e-16
      if sv.min() < np.finfo(sv.dtype).eps:  # machine min eps
          return 0
  
      # solve against the identity matrix, then produce
      # a nasty mess of dot products... this is the (horrendous) R code:
      # (1/N^2) * sum(diag(solve(tmp) %*% t(A) %*% t(Fhat) %*% Fhat %*% A))
      # https://github.com/robjhyndman/forecast/blob/master/R/arima.R#L321
      Fhat = Fhataux.cumsum(axis=0)
      solved = solve(AtOmfhatA, np.identity(AtOmfhatA.shape[0]))
      return (1.0 / n**2) * solved.dot(A.T).dot(Fhat.T).dot(Fhat).dot(
          A
      ).diagonal().sum()
  
imports: from collections import namedtuple
  import math
  from sklearn.linear_model import LinearRegression
  from sklearn.pipeline import make_pipeline
  from sklearn.preprocessing import StandardScaler
  from scipy.linalg import svd
  from statsmodels import api
  from statsmodels.tools import add_constant
  from abc import ABCMeta, abstractmethod
  from numpy.linalg import solve
  import numpy
  from .arima import _aicc
  from ..compat.numpy import DTYPE
  from .stationarity import _BaseStationarityTest
  from ..utils.array import c, diff, check_endog
  from ._arima import C_canova_hansen_sd_test
label_desc: Use image node_id 2 for calling the CHTest obj's underlying member method code with example usage: obj._sd_test(wts, s) and returns: unknown, int