wpdatatables
/
lib
/
phpoffice
/
phpspreadsheet
/
src
/
PhpSpreadsheet
/
Calculation
/
Statistical
/
Confidence.php
Confidence.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Statistical/Confidence.php
| 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 | } |
| 53 |