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;
   4  
   5  use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
   6  use PhpOffice\PhpSpreadsheet\Calculation\Exception;
   7  use PhpOffice\PhpSpreadsheet\Calculation\Functions;
   8  use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
   9  
  10  class Confidence
  11  {
  12      use ArrayEnabled;
  13  
  14      /**
  15       * CONFIDENCE.
  16       *
  17       * Returns the confidence interval for a population mean
  18       *
  19       * @param mixed $alpha As a float
  20       *                      Or can be an array of values
  21       * @param mixed $stdDev Standard Deviation as a float
  22       *                      Or can be an array of values
  23       * @param mixed $size As an integer
  24       *                      Or can be an array of values
  25       *
  26       * @return array|float|string
  27       *         If an array of numbers is passed as an argument, then the returned result will also be an array
  28       *            with the same dimensions
  29       */
  30      public static function CONFIDENCE($alpha, $stdDev, $size)
  31      {
  32          if (is_array($alpha) || is_array($stdDev) || is_array($size)) {
  33              return self::evaluateArrayArguments([self::class, __FUNCTION__], $alpha, $stdDev, $size);
  34          }
  35  
  36          try {
  37              $alpha = StatisticalValidations::validateFloat($alpha);
  38              $stdDev = StatisticalValidations::validateFloat($stdDev);
  39              $size = StatisticalValidations::validateInt($size);
  40          } catch (Exception $e) {
  41              return $e->getMessage();
  42          }
  43  
  44          if (($alpha <= 0) || ($alpha >= 1) || ($stdDev <= 0) || ($size < 1)) {
  45              return ExcelError::NAN();
  46          }
  47          /** @var float */
  48          $temp = Distributions\StandardNormal::inverse(1 - $alpha / 2);
  49  
  50          return Functions::scalar($temp * $stdDev / sqrt($size));
  51      }
  52  }