PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Calculation / Statistical / Distributions / F.php

F.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Calculation/Statistical/Distributions/F.php

75 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
6 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception;
7 use TablePress\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<mixed>|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($value, $u, $v, $cumulative)
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 if ($value == 0.0) {
59 if ($u === 2) {
60 return 1.0;
61 }
62
63 return ($u === 1) ? INF : 0.0;
64 }
65
66 // Log domain, so large degrees of freedom cannot overflow the Gamma ratio.
67 return exp(
68 Gamma::logGamma(($v + $u) / 2) - Gamma::logGamma($u / 2) - Gamma::logGamma($v / 2)
69 + ($u / 2) * log($u / $v)
70 + (($u - 2) / 2) * log($value)
71 - (($u + $v) / 2) * log(1 + ($u / $v) * $value)
72 );
73 }
74 }
75