code: def compute_esci(
      stat=None,
      nx=None,
      ny=None,
      paired=False,
      eftype="cohen",
      confidence=0.95,
      decimals=2,
      alternative="two-sided",
  ):
      """Parametric confidence intervals around a Cohen d or a correlation coefficient.
  
      Parameters
      ----------
      stat : float
          Original effect size. Must be either a correlation coefficient or a Cohen-type effect size
          (Cohen d or Hedges g).
      nx, ny : int
          Length of vector x and y.
      paired : bool
          Indicates if the effect size was estimated from a paired sample. This is only relevant for
          cohen or hedges effect size.
      eftype : string
          Effect size type. Must be "r" (correlation) or "cohen" (Cohen d or Hedges g).
      confidence : float
          Confidence level (0.95 = 95%)
      decimals : int
          Number of rounded decimals.
      alternative : string
          Defines the alternative hypothesis, or tail for the correlation coefficient. Must be one of
          "two-sided" (default), "greater" or "less". This parameter only has an effect if ``eftype``
          is "r".
  
      Returns
      -------
      ci : array
          Desired converted effect size
  
      Notes
      -----
      To compute the parametric confidence interval around a **Pearson r correlation** coefficient,
      one must first apply a Fisher's r-to-z transformation:
  
      .. math:: z = 0.5 \\cdot \\ln \\frac{1 + r}{1 - r} = \\text{arctanh}(r)
  
      and compute the standard error:
  
      .. math:: \\text{SE} = \\frac{1}{\\sqrt{n - 3}}
  
      where :math:`n` is the sample size.
  
      The lower and upper confidence intervals - *in z-space* - are then given by:
  
      .. math:: \\text{ci}_z = z \\pm \\text{crit} \\cdot \\text{SE}
  
      where :math:`\\text{crit}` is the critical value of the normal distribution corresponding to
      the desired confidence level (e.g. 1.96 in case of a 95% confidence interval).
  
      These confidence intervals can then be easily converted back to *r-space*:
  
      .. math::
  
          \\text{ci}_r = \\frac{\\exp(2 \\cdot \\text{ci}_z) - 1}
          {\\exp(2 \\cdot \\text{ci}_z) + 1} = \\text{tanh}(\\text{ci}_z)
  
      A formula for calculating the confidence interval for a **Cohen d effect size** is given by
      Hedges and Olkin (1985, p86). If the effect size estimate from the sample is :math:`d`, then
      it follows a T distribution with standard error:
  
      .. math::
  
          \\text{SE} = \\sqrt{\\frac{n_x + n_y}{n_x \\cdot n_y} +
          \\frac{d^2}{2 (n_x + n_y)}}
  
      where :math:`n_x` and :math:`n_y` are the sample sizes of the two groups.
  
      In one-sample test or paired test, this becomes:
  
      .. math::
  
          \\text{SE} = \\sqrt{\\frac{1}{n_x} + \\frac{d^2}{2 n_x}}
  
      The lower and upper confidence intervals are then given by:
  
      .. math:: \\text{ci}_d = d \\pm \\text{crit} \\cdot \\text{SE}
  
      where :math:`\\text{crit}` is the critical value of the T distribution corresponding to the
      desired confidence level.
  
      References
      ----------
      * https://en.wikipedia.org/wiki/Fisher_transformation
  
      * Hedges, L., and Ingram Olkin. "Statistical models for meta-analysis." (1985).
  
      * http://www.leeds.ac.uk/educol/documents/00002182.htm
  
      * https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5133225/
  
      Examples
      --------
      1. Confidence interval of a Pearson correlation coefficient
  
      >>> import pingouin as pg
      >>> x = [3, 4, 6, 7, 5, 6, 7, 3, 5, 4, 2]
      >>> y = [4, 6, 6, 7, 6, 5, 5, 2, 3, 4, 1]
      >>> nx, ny = len(x), len(y)
      >>> stat = pg.compute_effsize(x, y, eftype='r')
      >>> ci = pg.compute_esci(stat=stat, nx=nx, ny=ny, eftype='r')
      >>> print(round(stat, 4), ci)
      0.7468 [0.27 0.93]
  
      2. Confidence interval of a Cohen d
  
      >>> stat = pg.compute_effsize(x, y, eftype='cohen')
      >>> ci = pg.compute_esci(stat, nx=nx, ny=ny, eftype='cohen', decimals=3)
      >>> print(round(stat, 4), ci)
      0.1538 [-0.737  1.045]
      """
      from scipy.stats import norm, t
  
      assert eftype.lower() in [
          "r",
          "pearson",
          "spearman",
          "cohen",
          "d",
          "g",
          "hedges",
      ]
      assert alternative in [
          "two-sided",
          "greater",
          "less",
      ], "Alternative must be one of 'two-sided' (default), 'greater' or 'less'."
      assert stat is not None and nx is not None
      assert isinstance(confidence, float)
      assert 0 < confidence < 1, "confidence must be between 0 and 1."
  
      if eftype.lower() in ["r", "pearson", "spearman"]:
          z = np.arctanh(stat)  # R-to-z transform
          se = 1 / np.sqrt(nx - 3)
          # See https://github.com/SurajGupta/r-source/blob/master/src/library/stats/R/cor.test.R
          if alternative == "two-sided":
              crit = np.abs(norm.ppf((1 - confidence) / 2))
              ci_z = np.array([z - crit * se, z + crit * se])
          elif alternative == "greater":
              crit = norm.ppf(confidence)
              ci_z = np.array([z - crit * se, np.inf])
          else:  # alternative = "less"
              crit = norm.ppf(confidence)
              ci_z = np.array([-np.inf, z + crit * se])
          ci = np.tanh(ci_z)  # Transform back to r
      else:
          # Cohen d. Results are different than JASP which uses a non-central T
          # distribution. See github.com/jasp-stats/jasp-issues/issues/525
          if ny == 1 or paired:
              # One-sample or paired. Results vary slightly from the cohen.d R
              # function which uses instead:
              # >>> sqrt((n / (n / 2)^2) + .5*(dd^2 / n)) -- one-sample
              # >>> sqrt( (1/n1 + dd^2/(2*n1))*(2-2*r)); -- paired
              # where r is the correlation between samples
              # https://github.com/mtorchiano/effsize/blob/master/R/CohenD.R
              # However, Pingouin uses the formulas on www.real-statistics.com
              se = np.sqrt(1 / nx + stat**2 / (2 * nx))
              dof = nx - 1
          else:
              # Independent two-samples: give same results as R:
              # >>> cohen.d(..., paired = FALSE, noncentral=FALSE)
              se = np.sqrt(
                  ((nx + ny) / (nx * ny))
                  + (stat**2) / (2 * (nx + ny))
              )
              dof = nx + ny - 2
          crit = np.abs(t.ppf((1 - confidence) / 2, dof))
          ci = np.array([stat - crit * se, stat + crit * se])
      return np.round(ci, decimals)
  
file_path: pingouin/pingouin/effsize.py
imports: import warnings
  import numpy
  from scipy.stats import pearsonr
  from pingouin.utils import _check_eftype, remove_na
label_desc: Use image node_id 1 for calling a global function with example usage: compute_esci(stat, nx, ny, paired, eftype, confidence, decimals, alternative) and returns: np