class_docstr: Perform an OCSB test of seasonality.
  
  Compute the Osborn, Chui, Smith, and Birchenhall (OCSB) test for an input
  time series to determine whether it needs seasonal differencing. The
  regression equation may include lags of the dependent variable. When
  ``lag_method`` = "fixed", the lag order is fixed to ``max_lag``; otherwise,
  ``max_lag`` is the maximum number of lags considered in a lag selection
  procedure that minimizes the ``lag_method`` criterion, which can be
  "aic", "bic" or corrected AIC, "aicc".
  
  Critical values for the test are based on simulations, which have been
  smoothed over to produce critical values for all seasonal periods
  
  Parameters
  ----------
  m : int
      The seasonal differencing term. For monthly data, e.g., this would be
      12. For quarterly, 4, etc. For the OCSB test to work, ``m`` must
      exceed 1.
  
  lag_method : str, optional (default="aic")
      The lag method to use. One of ("fixed", "aic", "bic", "aicc"). The
      metric for assessing model performance after fitting a linear model.
  
  max_lag : int, optional (default=3)
      The maximum lag order to be considered by ``lag_method``.
  
  References
  ----------
  .. [1] Osborn DR, Chui APL, Smith J, and Birchenhall CR (1988)
         "Seasonality and the order of integration for consumption",
         Oxford Bulletin of Economics and Statistics 50(4):361-377.
  
  .. [2] R's forecast::OCSB test source code: https://bit.ly/2QYQHno
class_docstr_tok: ["Perform","an","OCSB","test","of","seasonality",".","Compute","the","Osborn",",","Chui",",","Smith",",","and","Birchenhall","(","OCSB",")","test","for","an","input","time","series","to","determine","whether","it","needs","seasonal","differencing",".","The","regression","equation","may","include","lags","of","the","dependent","variable",".","When","``","lag_method","``","=","``","fixed","''",",","the","lag","order","is","fixed","to","``","max_lag","``",";","otherwise",",","``","max_lag","``","is","the","maximum","number","of","lags","considered","in","a","lag","selection","procedure","that","minimizes","the","``","lag_method","``","criterion",",","which","can","be","''","aic","''",",","``","bic","''","or","corrected","AIC",",","``","aicc","''",".","Critical","values","for","the","test","are","based","on","simulations",",","which","have","been","smoothed","over","to","produce","critical","values","for","all","seasonal","periods","Parameters","--","--","--","--","--","m",":","int","The","seasonal","differencing","term",".","For","monthly","data",",","e.g.",",","this","would","be","12",".","For","quarterly",",","4",",","etc",".","For","the","OCSB","test","to","work",",","``","m","``","must","exceed","1.","lag_method",":","str",",","optional","(","default=","''","aic","''",")","The","lag","method","to","use",".","One","of","(","``","fixed","''",",","``","aic","''",",","``","bic","''",",","``","aicc","''",")",".","The","metric","for","assessing","model","performance","after","fitting","a","linear","model",".","max_lag",":","int",",","optional","(","default=3",")","The","maximum","lag","order","to","be","considered","by","``","lag_method","``",".","References","--","--","--","--","--","..","[","1","]","Osborn","DR",",","Chui","APL",",","Smith","J",",","and","Birchenhall","CR","(","1988",")","``","Seasonality","and","the","order","of","integration","for","consumption","''",",","Oxford","Bulletin","of","Economics","and","Statistics","50","(","4",")",":361-377",".","..","[","2","]","R","'s","forecast",":",":OCSB","test","source","code",":","https",":","\/\/bit.ly\/2QYQHno"]
docstr: Fit the linear model used to compute the test statistic
docstr_tok: ["Fit","the","linear","model","used","to","compute","the","test","statistic"]
code: def _fit_ocsb(x, m, lag, max_lag):
      """Fit the linear model used to compute the test statistic"""
      y_first_order_diff = diff(x, m)
  
      # if there are no more samples, we have to bail
      if y_first_order_diff.shape[0] == 0:
          raise ValueError(
              "There are no more samples after a first-order "
              "seasonal differencing. See http://alkaline-ml.com/pmdarima/"
              "seasonal-differencing-issues.html for a more in-depth "
              "explanation and potential work-arounds."
          )
  
      y = diff(y_first_order_diff)
      ylag = OCSBTest._gen_lags(y, lag)
  
      if max_lag > -1:
          # y = tail(y, -maxlag)
          y = y[max_lag:]
  
      # A constant term is added in the R code's lm formula. We do that in
      # the linear model's constructor
      mf = ylag[: y.shape[0]]
      ar_fit = sm.OLS(y, add_constant(mf)).fit(method="qr")
  
      # Create Z4
      z4_y = y_first_order_diff[lag:]  # new endog
      z4_lag = OCSBTest._gen_lags(y_first_order_diff, lag)[
          : z4_y.shape[0], :
      ]
      z4_preds = ar_fit.predict(add_constant(z4_lag))  # preds
      z4 = z4_y - z4_preds  # test residuals
  
      # Create Z5. Looks odd because y and lag depend on each other and go
      # back and forth for two stages
      z5_y = diff(x)
      z5_lag = OCSBTest._gen_lags(z5_y, lag)
      z5_y = z5_y[lag:]
      z5_lag = z5_lag[: z5_y.shape[0], :]
      z5_preds = ar_fit.predict(add_constant(z5_lag))
      z5 = z5_y - z5_preds
  
      # Finally, fit a linear regression on mf with z4 & z5 features added
      data = np.hstack(
          (
              mf,
              z4[: mf.shape[0]].reshape(-1, 1),
              z5[: mf.shape[0]].reshape(-1, 1),
          )
      )
  
      return sm.OLS(y, data).fit(method="qr")
  
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 5 for calling the OCSBTest obj's underlying member method code with example usage: obj._fit_ocsb(x, m, lag, max_lag) and returns: sm