code: def het_goldfeldquandt(
      y,
      x,
      idx=None,
      split=None,
      drop=None,
      alternative="increasing",
      store=False,
  ):
      """
      Goldfeld-Quandt homoskedasticity test.
  
      This test examines whether the residual variance is the same in 2
      subsamples.
  
      Parameters
      ----------
      y : array_like
          endogenous variable
      x : array_like
          exogenous variable, regressors
      idx : int, default None
          column index of variable according to which observations are
          sorted for the split
      split : {int, float}, default None
          If an integer, this is the index at which sample is split.
          If a float in 0<split<1 then split is interpreted as fraction
          of the observations in the first sample. If None, uses nobs//2.
      drop : {int, float}, default None
          If this is not None, then observation are dropped from the middle
          part of the sorted series. If 0<split<1 then split is interpreted
          as fraction of the number of observations to be dropped.
          Note: Currently, observations are dropped between split and
          split+drop, where split and drop are the indices (given by rounding
          if specified as fraction). The first sample is [0:split], the
          second sample is [split+drop:]
      alternative : {"increasing", "decreasing", "two-sided"}
          The default is increasing. This specifies the alternative for the
          p-value calculation.
      store : bool, default False
          Flag indicating to return the regression results
  
      Returns
      -------
      fval : float
          value of the F-statistic
      pval : float
          p-value of the hypothesis that the variance in one subsample is
          larger than in the other subsample
      ordering : str
          The ordering used in the alternative.
      res_store : ResultsStore, optional
          Storage for the intermediate and final results that are calculated
  
      Notes
      -----
      The Null hypothesis is that the variance in the two sub-samples are the
      same. The alternative hypothesis, can be increasing, i.e. the variance
      in the second sample is larger than in the first, or decreasing or
      two-sided.
  
      Results are identical R, but the drop option is defined differently.
      (sorting by idx not tested yet)
      """
      x = np.asarray(x)
      y = np.asarray(y)  # **2
      nobs, nvars = x.shape
      if split is None:
          split = nobs // 2
      elif (0 < split) and (split < 1):
          split = int(nobs * split)
  
      if drop is None:
          start2 = split
      elif (0 < drop) and (drop < 1):
          start2 = split + int(nobs * drop)
      else:
          start2 = split + drop
  
      if idx is not None:
          xsortind = np.argsort(x[:, idx])
          y = y[xsortind]
          x = x[xsortind, :]
  
      resols1 = OLS(y[:split], x[:split]).fit()
      resols2 = OLS(y[start2:], x[start2:]).fit()
      fval = resols2.mse_resid / resols1.mse_resid
      # if fval>1:
      if alternative.lower() in ["i", "inc", "increasing"]:
          fpval = stats.f.sf(fval, resols1.df_resid, resols2.df_resid)
          ordering = "increasing"
      elif alternative.lower() in ["d", "dec", "decreasing"]:
          fpval = stats.f.sf(
              1.0 / fval, resols2.df_resid, resols1.df_resid
          )
          ordering = "decreasing"
      elif alternative.lower() in ["2", "2-sided", "two-sided"]:
          fpval_sm = stats.f.cdf(
              fval, resols2.df_resid, resols1.df_resid
          )
          fpval_la = stats.f.sf(
              fval, resols2.df_resid, resols1.df_resid
          )
          fpval = 2 * min(fpval_sm, fpval_la)
          ordering = "two-sided"
      else:
          raise ValueError("invalid alternative")
  
      if store:
          res = ResultsStore()
          res.__doc__ = (
              "Test Results for Goldfeld-Quandt test of" "heterogeneity"
          )
          res.fval = fval
          res.fpval = fpval
          res.df_fval = (resols2.df_resid, resols1.df_resid)
          res.resols1 = resols1
          res.resols2 = resols2
          res.ordering = ordering
          res.split = split
          res._str = """\
  The Goldfeld-Quandt test for null hypothesis that the variance in the second
  subsample is {} than in the first subsample:
  F-statistic ={:8.4f} and p-value ={:8.4f}""".format(
              ordering, fval, fpval
          )
  
          return fval, fpval, ordering, res
  
      return fval, fpval, ordering
  
imports: from statsmodels.compat.pandas import deprecate_kwarg
  from collections.abc import Iterable
  import numpy
  import pandas
  from scipy import stats
  from statsmodels.regression.linear_model import OLS, RegressionResultsWrapper
  from statsmodels.stats._adnorm import anderson_statistic, normal_ad
  from statsmodels.stats._lilliefors import kstest_exponential, kstest_fit, kstest_normal, lilliefors
  from statsmodels.tools.validation import array_like, bool_like, dict_like, float_like, int_like, string_like
  from statsmodels.tsa.tsatools import lagmat
label_desc: Use image node_id 13 for calling a global function with example usage: het_goldfeldquandt(y, x, idx, split, drop, alternative, store) and returns: fval,  fpval,  ordering, fval,  fpval,  ordering,  res