code: def kstest(
      rvs,
      cdf,
      args=(),
      N=20,
      alternative="two_sided",
      mode="approx",
      **kwds,
  ):
      """
      Perform the Kolmogorov-Smirnov test for goodness of fit
  
      This performs a test of the distribution G(x) of an observed
      random variable against a given distribution F(x). Under the null
      hypothesis the two distributions are identical, G(x)=F(x). The
      alternative hypothesis can be either 'two_sided' (default), 'less'
      or 'greater'. The KS test is only valid for continuous distributions.
  
      Parameters
      ----------
      rvs : str or array or callable
          string: name of a distribution in scipy.stats
  
          array: 1-D observations of random variables
  
          callable: function to generate random variables, requires keyword
          argument `size`
  
      cdf : str or callable
          string: name of a distribution in scipy.stats, if rvs is a string then
          cdf can evaluate to `False` or be the same as rvs
          callable: function to evaluate cdf
  
      args : tuple, sequence
          distribution parameters, used if rvs or cdf are strings
      N : int
          sample size if rvs is string or callable
      alternative : 'two_sided' (default), 'less' or 'greater'
          defines the alternative hypothesis (see explanation)
  
      mode : 'approx' (default) or 'asymp'
          defines the distribution used for calculating p-value
  
          'approx' : use approximation to exact distribution of test statistic
  
          'asymp' : use asymptotic distribution of test statistic
  
  
      Returns
      -------
      D : float
          KS test statistic, either D, D+ or D-
      p-value :  float
          one-tailed or two-tailed p-value
  
      Notes
      -----
  
      In the one-sided test, the alternative is that the empirical
      cumulative distribution function of the random variable is "less"
      or "greater" than the cumulative distribution function F(x) of the
      hypothesis, G(x)<=F(x), resp. G(x)>=F(x).
  
      Examples
      --------
  
      >>> from scipy import stats
      >>> import numpy as np
      >>> from scipy.stats import kstest
  
      >>> x = np.linspace(-15,15,9)
      >>> kstest(x,'norm')
      (0.44435602715924361, 0.038850142705171065)
  
      >>> np.random.seed(987654321) # set random seed to get the same result
      >>> kstest('norm','',N=100)
      (0.058352892479417884, 0.88531190944151261)
  
      is equivalent to this
  
      >>> np.random.seed(987654321)
      >>> kstest(stats.norm.rvs(size=100),'norm')
      (0.058352892479417884, 0.88531190944151261)
  
      Test against one-sided alternative hypothesis:
  
      >>> np.random.seed(987654321)
  
      Shift distribution to larger values, so that cdf_dgp(x)< norm.cdf(x):
  
      >>> x = stats.norm.rvs(loc=0.2, size=100)
      >>> kstest(x,'norm', alternative = 'less')
      (0.12464329735846891, 0.040989164077641749)
  
      Reject equal distribution against alternative hypothesis: less
  
      >>> kstest(x,'norm', alternative = 'greater')
      (0.0072115233216311081, 0.98531158590396395)
  
      Do not reject equal distribution against alternative hypothesis: greater
  
      >>> kstest(x,'norm', mode='asymp')
      (0.12464329735846891, 0.08944488871182088)
  
  
      Testing t distributed random variables against normal distribution:
  
      With 100 degrees of freedom the t distribution looks close to the normal
      distribution, and the kstest does not reject the hypothesis that the sample
      came from the normal distribution
  
      >>> np.random.seed(987654321)
      >>> stats.kstest(stats.t.rvs(100,size=100),'norm')
      (0.072018929165471257, 0.67630062862479168)
  
      With 3 degrees of freedom the t distribution looks sufficiently different
      from the normal distribution, that we can reject the hypothesis that the
      sample came from the normal distribution at a alpha=10% level
  
      >>> np.random.seed(987654321)
      >>> stats.kstest(stats.t.rvs(3,size=100),'norm')
      (0.131016895759829, 0.058826222555312224)
      """
      if isinstance(rvs, str):
          # cdf = getattr(stats, rvs).cdf
          if (not cdf) or (cdf == rvs):
              cdf = getattr(distributions, rvs).cdf
              rvs = getattr(distributions, rvs).rvs
          else:
              raise AttributeError(
                  "if rvs is string, cdf has to be the same distribution"
              )
  
      if isinstance(cdf, str):
          cdf = getattr(distributions, cdf).cdf
      if callable(rvs):
          kwds = {"size": N}
          vals = np.sort(rvs(*args, **kwds))
      else:
          vals = np.sort(rvs)
          N = len(vals)
      cdfvals = cdf(vals, *args)
  
      if alternative in ["two_sided", "greater"]:
          Dplus = (np.arange(1.0, N + 1) / N - cdfvals).max()
          if alternative == "greater":
              return Dplus, distributions.ksone.sf(Dplus, N)
  
      if alternative in ["two_sided", "less"]:
          Dmin = (cdfvals - np.arange(0.0, N) / N).max()
          if alternative == "less":
              return Dmin, distributions.ksone.sf(Dmin, N)
  
      if alternative == "two_sided":
          D = np.max([Dplus, Dmin])
          if mode == "asymp":
              return D, distributions.kstwobign.sf(D * np.sqrt(N))
          if mode == "approx":
              pval_two = distributions.kstwobign.sf(D * np.sqrt(N))
              if N > 2666 or pval_two > 0.80 - N * 0.3 / 1000.0:
                  return D, distributions.kstwobign.sf(D * np.sqrt(N))
              else:
                  return D, distributions.ksone.sf(D, N) * 2
  
imports: from statsmodels.compat.python import lmap
  import numpy
  from scipy.stats import distributions
  from statsmodels.tools.decorators import cache_readonly
  from scipy.special import kolmogorov
label_desc: Use image node_id 2 for calling a global function with example usage: kstest(rvs, cdf, args, N, alternative, mode) and returns: Dplus,  distributions, Dmin,  distributions, D,  distributions, D,  distributions, D,  unknown