code: def pacf(
      x: ArrayLike1D,
      nlags: int | None = None,
      method: Literal[
          "yw",
          "ywadjusted",
          "ols",
          "ols-inefficient",
          "ols-adjusted",
          "ywm",
          "ywmle",
          "ld",
          "ldadjusted",
          "ldb",
          "ldbiased",
          "burg",
      ] = "ywadjusted",
      alpha: float | None = None,
  ) -> np.ndarray | tuple[np.ndarray, np.ndarray]:
      """
      Partial autocorrelation estimate.
  
      Parameters
      ----------
      x : array_like
          Observations of time series for which pacf is calculated.
      nlags : int, optional
          Number of lags to return autocorrelation for. If not provided,
          uses min(10 * np.log10(nobs), nobs // 2 - 1). The returned value
          includes lag 0 (ie., 1) so size of the pacf vector is (nlags + 1,).
      method : str, default "ywunbiased"
          Specifies which method for the calculations to use.
  
          - "yw" or "ywadjusted" : Yule-Walker with sample-size adjustment in
            denominator for acovf. Default.
          - "ywm" or "ywmle" : Yule-Walker without adjustment.
          - "ols" : regression of time series on lags of it and on constant.
          - "ols-inefficient" : regression of time series on lags using a single
            common sample to estimate all pacf coefficients.
          - "ols-adjusted" : regression of time series on lags with a bias
            adjustment.
          - "ld" or "ldadjusted" : Levinson-Durbin recursion with bias
            correction.
          - "ldb" or "ldbiased" : Levinson-Durbin recursion without bias
            correction.
          - "burg" :  Burg"s partial autocorrelation estimator.
  
      alpha : float, optional
          If a number is given, the confidence intervals for the given level are
          returned. For instance if alpha=.05, 95 % confidence intervals are
          returned where the standard deviation is computed according to
          1/sqrt(len(x)).
  
      Returns
      -------
      pacf : ndarray
          The partial autocorrelations for lags 0, 1, ..., nlags. Shape
          (nlags+1,).
      confint : ndarray, optional
          Confidence intervals for the PACF at lags 0, 1, ..., nlags. Shape
          (nlags + 1, 2). Returned if alpha is not None.
  
      See Also
      --------
      statsmodels.tsa.stattools.acf
          Estimate the autocorrelation function.
      statsmodels.tsa.stattools.pacf
          Partial autocorrelation estimation.
      statsmodels.tsa.stattools.pacf_yw
           Partial autocorrelation estimation using Yule-Walker.
      statsmodels.tsa.stattools.pacf_ols
          Partial autocorrelation estimation using OLS.
      statsmodels.tsa.stattools.pacf_burg
          Partial autocorrelation estimation using Burg"s method.
  
      Notes
      -----
      Based on simulation evidence across a range of low-order ARMA models,
      the best methods based on root MSE are Yule-Walker (MLW), Levinson-Durbin
      (MLE) and Burg, respectively. The estimators with the lowest bias included
      included these three in addition to OLS and OLS-adjusted.
  
      Yule-Walker (adjusted) and Levinson-Durbin (adjusted) performed
      consistently worse than the other options.
      """
      nlags = int_like(nlags, "nlags", optional=True)
      methods = (
          "ols",
          "ols-inefficient",
          "ols-adjusted",
          "yw",
          "ywa",
          "ld",
          "ywadjusted",
          "yw_adjusted",
          "ywm",
          "ywmle",
          "yw_mle",
          "lda",
          "ldadjusted",
          "ld_adjusted",
          "ldb",
          "ldbiased",
          "ld_biased",
          "burg",
      )
      x = array_like(x, "x", maxdim=2)
      method = string_like(method, "method", options=methods)
      alpha = float_like(alpha, "alpha", optional=True)
  
      nobs = x.shape[0]
      if nlags is None:
          nlags = min(int(10 * np.log10(nobs)), nobs // 2 - 1)
      nlags = max(nlags, 1)
      if nlags > x.shape[0] // 2:
          raise ValueError(
              "Can only compute partial correlations for lags up to 50% of the "
              f"sample size. The requested nlags {nlags} must be < "
              f"{x.shape[0] // 2}."
          )
      if method in ("ols", "ols-inefficient", "ols-adjusted"):
          efficient = "inefficient" not in method
          adjusted = "adjusted" in method
          ret = pacf_ols(
              x, nlags=nlags, efficient=efficient, adjusted=adjusted
          )
      elif method in ("yw", "ywa", "ywadjusted", "yw_adjusted"):
          ret = pacf_yw(x, nlags=nlags, method="adjusted")
      elif method in ("ywm", "ywmle", "yw_mle"):
          ret = pacf_yw(x, nlags=nlags, method="mle")
      elif method in ("ld", "lda", "ldadjusted", "ld_adjusted"):
          acv = acovf(x, adjusted=True, fft=False)
          ld_ = levinson_durbin(acv, nlags=nlags, isacov=True)
          ret = ld_[2]
      elif method == "burg":
          ret, _ = pacf_burg(x, nlags=nlags, demean=True)
      # inconsistent naming with ywmle
      else:  # method in ("ldb", "ldbiased", "ld_biased")
          acv = acovf(x, adjusted=False, fft=False)
          ld_ = levinson_durbin(acv, nlags=nlags, isacov=True)
          ret = ld_[2]
      if alpha is not None:
          varacf = 1.0 / len(x)  # for all lags >=1
          interval = stats.norm.ppf(1.0 - alpha / 2.0) * np.sqrt(varacf)
          confint = np.array(lzip(ret - interval, ret + interval))
          confint[0] = ret[
              0
          ]  # fix confidence interval for lag 0 to varpacf=0
          return ret, confint
      else:
          return ret
  
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 9 for calling a global function with example usage: pacf(x, nlags, method, alpha) and returns: ret,  confint, ret