1441 |
ariadna |
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 F
|
|
|
10 |
{
|
|
|
11 |
use ArrayEnabled;
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* F.DIST.
|
|
|
15 |
*
|
|
|
16 |
* Returns the F probability distribution.
|
|
|
17 |
* You can use this function to determine whether two data sets have different degrees of diversity.
|
|
|
18 |
* For example, you can examine the test scores of men and women entering high school, and determine
|
|
|
19 |
* if the variability in the females is different from that found in the males.
|
|
|
20 |
*
|
|
|
21 |
* @param mixed $value Float value for which we want the probability
|
|
|
22 |
* Or can be an array of values
|
|
|
23 |
* @param mixed $u The numerator degrees of freedom as an integer
|
|
|
24 |
* Or can be an array of values
|
|
|
25 |
* @param mixed $v The denominator degrees of freedom as an integer
|
|
|
26 |
* Or can be an array of values
|
|
|
27 |
* @param mixed $cumulative Boolean value indicating if we want the cdf (true) or the pdf (false)
|
|
|
28 |
* Or can be an array of values
|
|
|
29 |
*
|
|
|
30 |
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
31 |
* with the same dimensions
|
|
|
32 |
*/
|
|
|
33 |
public static function distribution(mixed $value, mixed $u, mixed $v, mixed $cumulative): array|string|float
|
|
|
34 |
{
|
|
|
35 |
if (is_array($value) || is_array($u) || is_array($v) || is_array($cumulative)) {
|
|
|
36 |
return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $u, $v, $cumulative);
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
try {
|
|
|
40 |
$value = DistributionValidations::validateFloat($value);
|
|
|
41 |
$u = DistributionValidations::validateInt($u);
|
|
|
42 |
$v = DistributionValidations::validateInt($v);
|
|
|
43 |
$cumulative = DistributionValidations::validateBool($cumulative);
|
|
|
44 |
} catch (Exception $e) {
|
|
|
45 |
return $e->getMessage();
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
if ($value < 0 || $u < 1 || $v < 1) {
|
|
|
49 |
return ExcelError::NAN();
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
if ($cumulative) {
|
|
|
53 |
$adjustedValue = ($u * $value) / ($u * $value + $v);
|
|
|
54 |
|
|
|
55 |
return Beta::incompleteBeta($adjustedValue, $u / 2, $v / 2);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
return (Gamma::gammaValue(($v + $u) / 2)
|
|
|
59 |
/ (Gamma::gammaValue($u / 2) * Gamma::gammaValue($v / 2)))
|
|
|
60 |
* (($u / $v) ** ($u / 2))
|
|
|
61 |
* (($value ** (($u - 2) / 2)) / ((1 + ($u / $v) * $value) ** (($u + $v) / 2)));
|
|
|
62 |
}
|
|
|
63 |
}
|