Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 400 and 401]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
   4  
   5  use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
   6  use PhpOffice\PhpSpreadsheet\Calculation\Exception;
   7  use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
   8  
   9  class Fisher
  10  {
  11      use ArrayEnabled;
  12  
  13      /**
  14       * FISHER.
  15       *
  16       * Returns the Fisher transformation at x. This transformation produces a function that
  17       *        is normally distributed rather than skewed. Use this function to perform hypothesis
  18       *        testing on the correlation coefficient.
  19       *
  20       * @param mixed $value Float value for which we want the probability
  21       *                      Or can be an array of values
  22       *
  23       * @return array|float|string
  24       *         If an array of numbers is passed as an argument, then the returned result will also be an array
  25       *            with the same dimensions
  26       */
  27      public static function distribution($value)
  28      {
  29          if (is_array($value)) {
  30              return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value);
  31          }
  32  
  33          try {
  34              DistributionValidations::validateFloat($value);
  35          } catch (Exception $e) {
  36              return $e->getMessage();
  37          }
  38  
  39          if (($value <= -1) || ($value >= 1)) {
  40              return ExcelError::NAN();
  41          }
  42  
  43          return 0.5 * log((1 + $value) / (1 - $value));
  44      }
  45  
  46      /**
  47       * FISHERINV.
  48       *
  49       * Returns the inverse of the Fisher transformation. Use this transformation when
  50       *        analyzing correlations between ranges or arrays of data. If y = FISHER(x), then
  51       *        FISHERINV(y) = x.
  52       *
  53       * @param mixed $probability Float probability at which you want to evaluate the distribution
  54       *                      Or can be an array of values
  55       *
  56       * @return array|float|string
  57       *         If an array of numbers is passed as an argument, then the returned result will also be an array
  58       *            with the same dimensions
  59       */
  60      public static function inverse($probability)
  61      {
  62          if (is_array($probability)) {
  63              return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $probability);
  64          }
  65  
  66          try {
  67              DistributionValidations::validateFloat($probability);
  68          } catch (Exception $e) {
  69              return $e->getMessage();
  70          }
  71  
  72          return (exp(2 * $probability) - 1) / (exp(2 * $probability) + 1);
  73      }
  74  }