code: def phillips_ouliaris(
      y: ArrayLike1D,
      x: ArrayLike2D,
      trend: UnitRootTrend = "c",
      *,
      test_type: Literal["Za", "Zt", "Pu", "Pz"] = "Zt",
      kernel: str = "bartlett",
      bandwidth: int | None = None,
      force_int: bool = False,
  ) -> PhillipsOuliarisTestResults:
      r"""
      Test for cointegration within a set of time series.
  
      Parameters
      ----------
      y : array_like
          The left-hand-side variable in the cointegrating regression.
      x : array_like
          The right-hand-side variables in the cointegrating regression.
      trend : {"n","c","ct","ctt"}, default "c"
          Trend to include in the cointegrating regression. Trends are:
  
          * "n": No deterministic terms
          * "c": Constant
          * "ct": Constant and linear trend
          * "ctt": Constant, linear and quadratic trends
      test_type : {"Za", "Zt", "Pu", "Pz"}, default "Zt"
          The test statistic to compute. Supported options are:
  
          * "Za": The Zα test based on the the debiased AR(1) coefficient.
          * "Zt": The Zt test based on the t-statistic from an AR(1).
          * "Pu": The Pᵤ variance-ratio test.
          * "Pz": The Pz test of the trace of the product of an estimate of the
            long-run residual variance and the inner-product of the data.
  
          See the notes for details on the test.
      kernel : str, default "bartlett"
          The string name of any of any known kernel-based long-run
          covariance estimators. Common choices are "bartlett" for the
          Bartlett kernel (Newey-West), "parzen" for the Parzen kernel
          and "quadratic-spectral" for the Quadratic Spectral kernel.
      bandwidth : int, default None
          The bandwidth to use. If not provided, the optimal bandwidth is
          estimated from the data. Setting the bandwidth to 0 and using
          "unadjusted" produces the classic OLS covariance estimator.
          Setting the bandwidth to 0 and using "robust" produces White's
          covariance estimator.
      force_int : bool, default False
          Whether the force the estimated optimal bandwidth to be an integer.
  
      Returns
      -------
      PhillipsOuliarisTestResults
          Results of the Phillips-Ouliaris test.
  
      See Also
      --------
      arch.unitroot.ADF
          Augmented Dickey-Fuller testing.
      arch.unitroot.PhillipsPerron
          Phillips & Perron's unit root test.
      arch.unitroot.cointegration.engle_granger
          Engle & Granger's cointegration test.
  
      Notes
      -----
  
      .. warning::
  
         The critical value simulation is on-going and so the critical values
         may change slightly as more simulations are completed. These are still
         based on far more simulations (minimum 2,000,000) than were possible
         in 1990 (5000) that are reported in [1]_.
  
      Supports 4 distinct tests.
  
      Define the cross-sectional regression
  
      .. math::
  
         y_t = x_t \beta + d_t \gamma + u_t
  
      where :math:`d_t` are any included deterministic terms. Let
      :math:`\hat{u}_t = y_t - x_t \hat{\beta} + d_t \hat{\gamma}`.
  
      The Zα and Zt statistics are defined as
  
      .. math::
  
         \hat{Z}_\alpha & = T \times z \\
         \hat{Z}_t & =  \frac{\hat{\sigma}_u}{\hat{\omega}^2} \times \sqrt{T} z \\
         z & = (\hat{\alpha} - 1) - \hat{\omega}^2_1 / \hat{\sigma}^2_u
  
      where :math:`\hat{\sigma}^2_u=T^{-1}\sum_{t=2}^T \hat{u}_t^2`,
      :math:`\hat{\omega}^2_1` is an estimate of the one-sided strict
      autocovariance, and :math:`\hat{\omega}^2` is an estimate of the long-run
      variance of the process.
  
      The :math:`\hat{P}_u` variance-ratio statistic is defined as
  
      .. math::
  
         \hat{P}_u = \frac{\hat{\omega}_{11\cdot2}}{\tilde{\sigma}^2_u}
  
      where :math:`\tilde{\sigma}^2_u=T^{-1}\sum_{t=1}^T \hat{u}_t^2` and
  
      .. math::
  
         \hat{\omega}_{11\cdot 2} = \hat{\omega}_{11}
                                   - \hat{\omega}'_{21} \hat{\Omega}_{22}^{-1}
                                     \hat{\omega}_{21}
  
      and
  
      .. math::
  
         \hat{\Omega}=\left[\begin{array}{cc} \hat{\omega}_{11} & \hat{\omega}'_{21}\\
                                              \hat{\omega}_{21} & \hat{\Omega}_{22}
                      \end{array}\right]
  
      is an estimate of the long-run covariance of :math:`\xi_t`, the residuals
      from an VAR(1) on :math:`z_t=[y_t,z_t]` that includes and trends included
      in the test.
  
      .. math::
  
         z_t = \Phi z_{t-1} + \xi_\tau
  
      The final test statistic is defined
  
      .. math::
  
         \hat{P}_z = T \times \mathrm{tr}(\hat{\Omega} M_{zz}^{-1})
  
      where :math:`M_{zz} = \sum_{t=1}^T \tilde{z}'_t \tilde{z}_t`,
      :math:`\tilde{z}_t` is the vector of data :math:`z_t=[y_t,x_t]` detrended
      using any trend terms included in the test,
      :math:`\tilde{z}_t = z_t - d_t \hat{\kappa}` and :math:`\hat{\Omega}` is
      defined above.
  
      The specification of the :math:`\hat{P}_z` test statistic when trend is "n"
      differs from the expression in [1]_. We recenter :math:`z_t` by subtracting
      the first observation, so that :math:`\tilde{z}_t = z_t - z_1`. This is
      needed to ensure that the initial value does not affect the distribution
      under the null. When the trend is anything other than "n", this set is not
      needed and the test statistics is identical whether the first observation
      is subtracted or not.
  
      References
      ----------
      .. [1] Phillips, P. C., & Ouliaris, S. (1990). Asymptotic properties of
         residual based tests for cointegration. Econometrica: Journal of the
         Econometric Society, 165-193.
      """
      test_type_key = test_type.lower()
      if test_type_key not in ("za", "zt", "pu", "pz"):
          raise ValueError(
              f"Unknown test_type: {test_type}. Only Za, Zt, Pu and Pz are supported."
          )
      kernel = kernel.lower().replace("-", "").replace("_", "")
      if kernel not in KERNEL_ESTIMATORS:
          raise ValueError(KERNEL_ERR)
      y_2d = ensure2d(y, "y")
      x = ensure2d(x, "x")
      xsection = _cross_section(y_2d, x, trend)
      data = xsection.model.data
      x_df = data.orig_exog.iloc[:, : x.shape[1]]
      z = pd.concat([data.orig_endog, x_df], axis=1)
      if test_type_key in ("pu", "pz"):
          return _po_ptests(
              z,
              xsection,
              cast(Literal["Pu", "Pz"], test_type),
              trend,
              kernel,
              bandwidth,
              force_int,
          )
      return _po_ztests(
          z,
          xsection,
          cast(Literal["Za", "Zt"], test_type),
          trend,
          kernel,
          bandwidth,
          force_int,
      )
  
imports: from __future__ import annotations
  from typing import cast
  import numpy
  import pandas
  from scipy import stats
  from statsmodels.iolib.summary import Summary
  from statsmodels.iolib.table import SimpleTable
  from statsmodels.regression.linear_model import RegressionResults
  import arch.covariance.kernel
  from arch.typing import ArrayLike1D, ArrayLike2D, Literal, UnitRootTrend
  from arch.unitroot._shared import KERNEL_ERR, KERNEL_ESTIMATORS, ResidualCointegrationTestResult, _cross_section
  from arch.unitroot.critical_values.phillips_ouliaris import CV_PARAMETERS, CV_TAU_MIN, PVAL_LARGE_P, PVAL_SMALL_P, PVAL_TAU_MAX, PVAL_TAU_MIN, PVAL_TAU_STAR
  from arch.unitroot.unitroot import TREND_DESCRIPTION
  from arch.utility.array import ensure2d
  from arch.utility.io import str_format
  from arch.utility.timeseries import add_trend
label_desc: Use image node_id 3 for calling a global function with example usage: phillips_ouliaris(y, x, trend) and returns: _po_ztests, _po_ptests