Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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 If an array of numbers is passed as an argument, then the returned result will also be an array
27
     *            with the same dimensions
28
     */
29
    public static function CONFIDENCE(mixed $alpha, mixed $stdDev, mixed $size)
30
    {
31
        if (is_array($alpha) || is_array($stdDev) || is_array($size)) {
32
            return self::evaluateArrayArguments([self::class, __FUNCTION__], $alpha, $stdDev, $size);
33
        }
34
 
35
        try {
36
            $alpha = StatisticalValidations::validateFloat($alpha);
37
            $stdDev = StatisticalValidations::validateFloat($stdDev);
38
            $size = StatisticalValidations::validateInt($size);
39
        } catch (Exception $e) {
40
            return $e->getMessage();
41
        }
42
 
43
        if (($alpha <= 0) || ($alpha >= 1) || ($stdDev <= 0) || ($size < 1)) {
44
            return ExcelError::NAN();
45
        }
46
        /** @var float $temp */
47
        $temp = Distributions\StandardNormal::inverse(1 - $alpha / 2);
48
 
49
        return Functions::scalar($temp * $stdDev / sqrt($size));
50
    }
51
}