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 / StandardNormal.php

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

159 lines 5.7 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\Functions;
7 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
8 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Statistical\Averages;
9 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Statistical\StandardDeviations;
10
11 class StandardNormal
12 {
13 use ArrayEnabled;
14
15 /**
16 * NORMSDIST.
17 *
18 * Returns the standard normal cumulative distribution function. The distribution has
19 * a mean of 0 (zero) and a standard deviation of one. Use this function in place of a
20 * table of standard normal curve areas.
21 *
22 * NOTE: We don't need to check for arrays to array-enable this function, because that is already
23 * handled by the logic in Normal::distribution()
24 * All we need to do is pass the value through as scalar or as array.
25 *
26 * @param mixed $value Float value for which we want the probability
27 * Or can be an array of values
28 *
29 * @return array<mixed>|float|string The result, or a string containing an error
30 * 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 cumulative($value)
34 {
35 return Normal::distribution($value, 0, 1, true);
36 }
37
38 /**
39 * NORM.S.DIST.
40 *
41 * Returns the standard normal cumulative distribution function. The distribution has
42 * a mean of 0 (zero) and a standard deviation of one. Use this function in place of a
43 * table of standard normal curve areas.
44 *
45 * NOTE: We don't need to check for arrays to array-enable this function, because that is already
46 * handled by the logic in Normal::distribution()
47 * All we need to do is pass the value and cumulative through as scalar or as array.
48 *
49 * @param mixed $value Float value for which we want the probability
50 * Or can be an array of values
51 * @param mixed $cumulative Boolean value indicating if we want the cdf (true) or the pdf (false)
52 * Or can be an array of values
53 *
54 * @return array<mixed>|float|string The result, or a string containing an error
55 * If an array of numbers is passed as an argument, then the returned result will also be an array
56 * with the same dimensions
57 */
58 public static function distribution($value, $cumulative)
59 {
60 return Normal::distribution($value, 0, 1, $cumulative);
61 }
62
63 /**
64 * NORMSINV.
65 *
66 * Returns the inverse of the standard normal cumulative distribution
67 *
68 * @param mixed $value float probability for which we want the value
69 * Or can be an array of values
70 *
71 * NOTE: We don't need to check for arrays to array-enable this function, because that is already
72 * handled by the logic in Normal::inverse()
73 * All we need to do is pass the value through as scalar or as array
74 *
75 * @return array<mixed>|float|string The result, or a string containing an error
76 * If an array of numbers is passed as an argument, then the returned result will also be an array
77 * with the same dimensions
78 */
79 public static function inverse($value)
80 {
81 return Normal::inverse($value, 0, 1);
82 }
83
84 /**
85 * GAUSS.
86 *
87 * Calculates the probability that a member of a standard normal population will fall between
88 * the mean and z standard deviations from the mean.
89 *
90 * @param mixed $value Or can be an array of values
91 *
92 * @return array<mixed>|float|string The result, or a string containing an error
93 * If an array of numbers is passed as an argument, then the returned result will also be an array
94 * with the same dimensions
95 */
96 public static function gauss($value)
97 {
98 if (is_array($value)) {
99 return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value);
100 }
101
102 if (!is_numeric($value)) {
103 return ExcelError::VALUE();
104 }
105 /** @var float $dist */
106 $dist = self::distribution($value, true);
107
108 return $dist - 0.5;
109 }
110
111 /**
112 * ZTEST.
113 *
114 * Returns the one-tailed P-value of a z-test.
115 *
116 * For a given hypothesized population mean, x, Z.TEST returns the probability that the sample mean would be
117 * greater than the average of observations in the data set (array) — that is, the observed sample mean.
118 *
119 * @param mixed $dataSet The dataset should be an array of float values for the observations
120 * @param mixed $m0 Alpha Parameter
121 * Or can be an array of values
122 * @param mixed $sigma A null or float value for the Beta (Standard Deviation) Parameter;
123 * if null, we use the standard deviation of the dataset
124 * Or can be an array of values
125 *
126 * @return array<mixed>|float|string (string if result is an error)
127 * If an array of numbers is passed as an argument, then the returned result will also be an array
128 * with the same dimensions
129 */
130 public static function zTest($dataSet, $m0, $sigma = null)
131 {
132 if (is_array($m0) || is_array($sigma)) {
133 return self::evaluateArrayArgumentsSubsetFrom([self::class, __FUNCTION__], 1, $dataSet, $m0, $sigma);
134 }
135
136 $dataSet = Functions::flattenArrayIndexed($dataSet);
137
138 if (!is_numeric($m0) || ($sigma !== null && !is_numeric($sigma))) {
139 return ExcelError::VALUE();
140 }
141
142 if ($sigma === null) {
143 /** @var float $sigma */
144 $sigma = StandardDeviations::STDEV($dataSet);
145 }
146 $n = count($dataSet);
147
148 $sub1 = Averages::average($dataSet);
149
150 if (!is_numeric($sub1)) {
151 return $sub1;
152 }
153
154 $temp = self::cumulative(($sub1 - $m0) / ($sigma / sqrt($n)));
155
156 return 1 - (is_numeric($temp) ? $temp : 0);
157 }
158 }
159