Confidence.php
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Confidence
{
/**
* CONFIDENCE.
*
* Returns the confidence interval for a population mean
*
* @param mixed $alpha As a float
* @param mixed $stdDev Standard Deviation as a float
* @param mixed $size As an integer
*
* @return float|string
*/
public static function CONFIDENCE($alpha, $stdDev, $size)
{
$alpha = Functions::flattenSingleValue($alpha);
$stdDev = Functions::flattenSingleValue($stdDev);
$size = Functions::flattenSingleValue($size);
try {
$alpha = StatisticalValidations::validateFloat($alpha);
$stdDev = StatisticalValidations::validateFloat($stdDev);
$size = StatisticalValidations::validateInt($size);
} catch (Exception $e) {
return $e->getMessage();
}
if (($alpha <= 0) || ($alpha >= 1) || ($stdDev <= 0) || ($size < 1)) {
return Functions::NAN();
}
return Distributions\StandardNormal::inverse(1 - $alpha / 2) * $stdDev / sqrt($size);
}
}