class_docstr: Class wrapper for Zivot-Andrews structural-break unit-root test
class_docstr_tok: ["Class","wrapper","for","Zivot-Andrews","structural-break","unit-root","test"]
docstr: Zivot-Andrews structural-break unit-root test.
  
  The Zivot-Andrews test tests for a unit root in a univariate process
  in the presence of serial correlation and a single structural break.
  
  Parameters
  ----------
  x : array_like
      The data series to test.
  trim : float
      The percentage of series at begin/end to exclude from break-period
      calculation in range [0, 0.333] (default=0.15).
  maxlag : int
      The maximum lag which is included in test, default is
      12*(nobs/100)^{1/4} (Schwert, 1989).
  regression : {"c","t","ct"}
      Constant and trend order to include in regression.
  
      * "c" : constant only (default).
      * "t" : trend only.
      * "ct" : constant and trend.
  autolag : {"AIC", "BIC", "t-stat", None}
      The method to select the lag length when using automatic selection.
  
      * if None, then maxlag lags are used,
      * if "AIC" (default) or "BIC", then the number of lags is chosen
        to minimize the corresponding information criterion,
      * "t-stat" based choice of maxlag.  Starts with maxlag and drops a
        lag until the t-statistic on the last lag length is significant
        using a 5%-sized test.
  
  Returns
  -------
  zastat : float
      The test statistic.
  pvalue : float
      The pvalue based on MC-derived critical values.
  cvdict : dict
      The critical values for the test statistic at the 1%, 5%, and 10%
      levels.
  baselag : int
      The number of lags used for period regressions.
  bpidx : int
      The index of x corresponding to endogenously calculated break period
      with values in the range [0..nobs-1].
  
  Notes
  -----
  H0 = unit root with a single structural break
  
  Algorithm follows Baum (2004/2015) approximation to original
  Zivot-Andrews method. Rather than performing an autolag regression at
  each candidate break period (as per the original paper), a single
  autolag regression is run up-front on the base model (constant + trend
  with no dummies) to determine the best lag length. This lag length is
  then used for all subsequent break-period regressions. This results in
  significant run time reduction but also slightly more pessimistic test
  statistics than the original Zivot-Andrews method, although no attempt
  has been made to characterize the size/power trade-off.
  
  References
  ----------
  .. [1] Baum, C.F. (2004). ZANDREWS: Stata module to calculate
     Zivot-Andrews unit root test in presence of structural break,"
     Statistical Software Components S437301, Boston College Department
     of Economics, revised 2015.
  
  .. [2] Schwert, G.W. (1989). Tests for unit roots: A Monte Carlo
     investigation. Journal of Business & Economic Statistics, 7:
     147-159.
  
  .. [3] Zivot, E., and Andrews, D.W.K. (1992). Further evidence on the
     great crash, the oil-price shock, and the unit-root hypothesis.
     Journal of Business & Economic Studies, 10: 251-270.
docstr_tok: ["Zivot-Andrews","structural-break","unit-root","test",".","The","Zivot-Andrews","test","tests","for","a","unit","root","in","a","univariate","process","in","the","presence","of","serial","correlation","and","a","single","structural","break",".","Parameters","--","--","--","--","--","x",":","array_like","The","data","series","to","test",".","trim",":","float","The","percentage","of","series","at","begin\/end","to","exclude","from","break-period","calculation","in","range","[","0",",","0.333","]","(","default=0.15",")",".","maxlag",":","int","The","maximum","lag","which","is","included","in","test",",","default","is","12","*","(","nobs\/100",")","^","{","1\/4","}","(","Schwert",",","1989",")",".","regression",":","{","``","c","''",",","''","t","''",",","''","ct","''","}","Constant","and","trend","order","to","include","in","regression",".","*","``","c","''",":","constant","only","(","default",")",".","*","``","t","''",":","trend","only",".","*","``","ct","''",":","constant","and","trend",".","autolag",":","{","``","AIC","''",",","``","BIC","''",",","``","t-stat","''",",","None","}","The","method","to","select","the","lag","length","when","using","automatic","selection",".","*","if","None",",","then","maxlag","lags","are","used",",","*","if","``","AIC","''","(","default",")","or","``","BIC","''",",","then","the","number","of","lags","is","chosen","to","minimize","the","corresponding","information","criterion",",","*","``","t-stat","''","based","choice","of","maxlag",".","Starts","with","maxlag","and","drops","a","lag","until","the","t-statistic","on","the","last","lag","length","is","significant","using","a","5","%","-sized","test",".","Returns","--","--","--","-","zastat",":","float","The","test","statistic",".","pvalue",":","float","The","pvalue","based","on","MC-derived","critical","values",".","cvdict",":","dict","The","critical","values","for","the","test","statistic","at","the","1","%",",","5","%",",","and","10","%","levels",".","baselag",":","int","The","number","of","lags","used","for","period","regressions",".","bpidx",":","int","The","index","of","x","corresponding","to","endogenously","calculated","break","period","with","values","in","the","range","[","0","..","nobs-1","]",".","Notes","--","--","-","H0","=","unit","root","with","a","single","structural","break","Algorithm","follows","Baum","(","2004\/2015",")","approximation","to","original","Zivot-Andrews","method",".","Rather","than","performing","an","autolag","regression","at","each","candidate","break","period","(","as","per","the","original","paper",")",",","a","single","autolag","regression","is","run","up-front","on","the","base","model","(","constant","+","trend","with","no","dummies",")","to","determine","the","best","lag","length",".","This","lag","length","is","then","used","for","all","subsequent","break-period","regressions",".","This","results","in","significant","run","time","reduction","but","also","slightly","more","pessimistic","test","statistics","than","the","original","Zivot-Andrews","method",",","although","no","attempt","has","been","made","to","characterize","the","size\/power","trade-off",".","References","--","--","--","--","--","..","[","1","]","Baum",",","C.F",".","(","2004",")",".","ZANDREWS",":","Stata","module","to","calculate","Zivot-Andrews","unit","root","test","in","presence","of","structural","break",",","''","Statistical","Software","Components","S437301",",","Boston","College","Department","of","Economics",",","revised","2015",".","..","[","2","]","Schwert",",","G.W",".","(","1989",")",".","Tests","for","unit","roots",":","A","Monte","Carlo","investigation",".","Journal","of","Business","&","Economic","Statistics",",","7",":","147-159",".","..","[","3","]","Zivot",",","E.",",","and","Andrews",",","D.W.K",".","(","1992",")",".","Further","evidence","on","the","great","crash",",","the","oil-price","shock",",","and","the","unit-root","hypothesis",".","Journal","of","Business","&","Economic","Studies",",","10",":","251-270","."]
code: def run(
      self, x, trim=0.15, maxlag=None, regression="c", autolag="AIC"
  ):
      """
      Zivot-Andrews structural-break unit-root test.
  
      The Zivot-Andrews test tests for a unit root in a univariate process
      in the presence of serial correlation and a single structural break.
  
      Parameters
      ----------
      x : array_like
          The data series to test.
      trim : float
          The percentage of series at begin/end to exclude from break-period
          calculation in range [0, 0.333] (default=0.15).
      maxlag : int
          The maximum lag which is included in test, default is
          12*(nobs/100)^{1/4} (Schwert, 1989).
      regression : {"c","t","ct"}
          Constant and trend order to include in regression.
  
          * "c" : constant only (default).
          * "t" : trend only.
          * "ct" : constant and trend.
      autolag : {"AIC", "BIC", "t-stat", None}
          The method to select the lag length when using automatic selection.
  
          * if None, then maxlag lags are used,
          * if "AIC" (default) or "BIC", then the number of lags is chosen
            to minimize the corresponding information criterion,
          * "t-stat" based choice of maxlag.  Starts with maxlag and drops a
            lag until the t-statistic on the last lag length is significant
            using a 5%-sized test.
  
      Returns
      -------
      zastat : float
          The test statistic.
      pvalue : float
          The pvalue based on MC-derived critical values.
      cvdict : dict
          The critical values for the test statistic at the 1%, 5%, and 10%
          levels.
      baselag : int
          The number of lags used for period regressions.
      bpidx : int
          The index of x corresponding to endogenously calculated break period
          with values in the range [0..nobs-1].
  
      Notes
      -----
      H0 = unit root with a single structural break
  
      Algorithm follows Baum (2004/2015) approximation to original
      Zivot-Andrews method. Rather than performing an autolag regression at
      each candidate break period (as per the original paper), a single
      autolag regression is run up-front on the base model (constant + trend
      with no dummies) to determine the best lag length. This lag length is
      then used for all subsequent break-period regressions. This results in
      significant run time reduction but also slightly more pessimistic test
      statistics than the original Zivot-Andrews method, although no attempt
      has been made to characterize the size/power trade-off.
  
      References
      ----------
      .. [1] Baum, C.F. (2004). ZANDREWS: Stata module to calculate
         Zivot-Andrews unit root test in presence of structural break,"
         Statistical Software Components S437301, Boston College Department
         of Economics, revised 2015.
  
      .. [2] Schwert, G.W. (1989). Tests for unit roots: A Monte Carlo
         investigation. Journal of Business & Economic Statistics, 7:
         147-159.
  
      .. [3] Zivot, E., and Andrews, D.W.K. (1992). Further evidence on the
         great crash, the oil-price shock, and the unit-root hypothesis.
         Journal of Business & Economic Studies, 10: 251-270.
      """
      x = array_like(x, "x")
      trim = float_like(trim, "trim")
      maxlag = int_like(maxlag, "maxlag", optional=True)
      regression = string_like(
          regression, "regression", options=("c", "t", "ct")
      )
      autolag = string_like(
          autolag,
          "autolag",
          options=("aic", "bic", "t-stat"),
          optional=True,
      )
      if trim < 0 or trim > (1.0 / 3.0):
          raise ValueError(
              "trim value must be a float in range [0, 1/3)"
          )
      nobs = x.shape[0]
      if autolag:
          adf_res = adfuller(
              x, maxlag=maxlag, regression="ct", autolag=autolag
          )
          baselags = adf_res[2]
      elif maxlag:
          baselags = maxlag
      else:
          baselags = int(12.0 * np.power(nobs / 100.0, 1 / 4.0))
      trimcnt = int(nobs * trim)
      start_period = trimcnt
      end_period = nobs - trimcnt
      if regression == "ct":
          basecols = 5
      else:
          basecols = 4
      # normalize constant and trend terms for stability
      c_const = 1 / np.sqrt(nobs)
      t_const = np.arange(1.0, nobs + 2)
      t_const *= np.sqrt(3) / nobs ** (3 / 2)
      # format the auxiliary regression data
      endog, exog = self._format_regression_data(
          x, nobs, c_const, t_const, basecols, baselags
      )
      # iterate through the time periods
      stats = np.full(end_period + 1, np.inf)
      for bp in range(start_period + 1, end_period + 1):
          # update intercept dummy / trend / trend dummy
          exog = self._update_regression_exog(
              exog,
              regression,
              bp,
              nobs,
              c_const,
              t_const,
              basecols,
              baselags,
          )
          # check exog rank on first iteration
          if bp == start_period + 1:
              o = OLS(endog[baselags:], exog, hasconst=1).fit()
              if o.df_model < exog.shape[1] - 1:
                  raise ValueError(
                      "ZA: auxiliary exog matrix is not full rank.\n"
                      "  cols (exc intercept) = {}  rank = {}".format(
                          exog.shape[1] - 1, o.df_model
                      )
                  )
              stats[bp] = o.tvalues[basecols - 1]
          else:
              stats[bp] = self._quick_ols(endog[baselags:], exog)[
                  basecols - 1
              ]
      # return best seen
      zastat = np.min(stats)
      bpidx = np.argmin(stats) - 1
      crit = self._za_crit(zastat, regression)
      pval = crit[0]
      cvdict = crit[1]
      return zastat, pval, cvdict, baselags, bpidx
  
imports: from __future__ import annotations
  from statsmodels.compat.numpy import lstsq
  from statsmodels.compat.pandas import deprecate_kwarg
  from statsmodels.compat.python import Literal, lzip
  from statsmodels.compat.scipy import _next_regular
  from typing import Union
  import warnings
  import numpy
  from numpy.linalg import LinAlgError
  import pandas
  from scipy import stats
  from scipy.interpolate import interp1d
  from scipy.signal import correlate
  from statsmodels.regression.linear_model import OLS, yule_walker
  from statsmodels.tools.sm_exceptions import CollinearityWarning, InfeasibleTestError, InterpolationWarning, MissingDataError, ValueWarning
  from statsmodels.tools.tools import Bunch, add_constant
  from statsmodels.tools.validation import array_like, bool_like, dict_like, float_like, int_like, string_like
  from statsmodels.tsa._bds import bds
  from statsmodels.tsa._innovations import innovations_algo, innovations_filter
  from statsmodels.tsa.adfvalues import mackinnoncrit, mackinnonp
  from statsmodels.tsa.tsatools import add_trend, lagmat, lagmat2ds
label_desc: Use image node_id 6 for calling the ZivotAndrewsUnitRoot obj's underlying member method code with example usage: obj.run(x, trim, maxlag, regression, autolag) and returns: zastat,  pval,  cvdict,  baselags,  bpidx