19 declare(strict_types=1);
37 public function setData(array $stat_data): void
39 $this->stat_data = array_values($stat_data);
48 public function min(): ?float
50 if ($this->stat_data === []) {
54 return min($this->stat_data);
60 public function max(): ?float
62 if ($this->stat_data === []) {
66 return max($this->stat_data);
74 return count($this->stat_data);
80 public function sum_n(
int $n): ?float
82 if ($this->stat_data === []) {
87 foreach ($this->stat_data as $value) {
88 $sum_n += pow((
float) $value, (
float) $n);
96 public function sum(): ?float
98 return $this->
sum_n(1);
107 return $this->
sum_n(2);
115 if ($this->stat_data === []) {
119 if ($this->
min() === 0) {
124 foreach ($this->stat_data as $value) {
125 $prod_n *= pow((
float) $value, (
float) $n);
149 $count = $this->
count();
153 return (
float) ($sum / $count);
167 if (($prod === null) || ($prod === 0)) {
170 $count = $this->
count();
174 return pow((
float) $prod, (
float) (1 / $count));
184 if (($min === null) or ($min === 0)) {
187 $count = $this->
count();
192 foreach ($this->stat_data as $value) {
195 return $count / $sum;
203 if ($this->stat_data === null) {
208 $count = $this->
count();
209 if ((
count($this->stat_data) % 2) === 0) {
210 return ($this->stat_data[($count / 2) - 1] + $this->stat_data[($count / 2)]) / 2;
213 return $this->stat_data[(($count + 1) / 2) - 1];
221 $rank = array_search($value, $this->stat_data);
222 if ($rank ===
false) {
226 return $this->
count() - $rank;
238 $count = $this->
count();
243 if (($count % 2) === 0) {
244 return $rank_median = ($count + 1) / 2;
247 return $rank_median = ($count + 1) / 2;
255 $count = $this->
count();
260 $nprod = ($n / 100) * $count;
261 if (intval($nprod) != $nprod) {
262 return $this->stat_data[ceil($nprod) - 1];
265 if ($nprod === 0.0) {
266 return $this->stat_data[0];
269 if ($nprod === (
float) $count) {
270 return $this->stat_data[(
int) $nprod - 1];
273 return ($this->stat_data[(
int) $nprod - 1] + $this->stat_data[(
int) $nprod]) / 2;
279 foreach ($this->stat_data as
$key => $value) {
280 if (!is_numeric($value)) {
281 unset($this->stat_data[
$key]);
285 sort($this->stat_data);
product(int $n)
Calculates the product of x_1 * x_2 * ...
sum()
Calculates the sum of x_1 + x_2 + ...
arithmetic_mean()
Arithmetic mean of the data values xbar = (1/n)*∑x_i.
rank(float $value)
Returns the rank of a given value.
max()
Calculates the maximum value.
median()
Median of the data values.
harmonic_mean()
Harmonic mean of the data values harmonic_mean = n/(1/x_1 + 1/x_2 + ...
geometric_mean()
Geometric mean of the data values geometric_mean = (x_1 * x_2 * ...
sum2()
Calculates the sum of x_1^2 + x_2^2 + ...
count()
Calculates number of data values.
rank_median()
Returns the rank of the median.
Constants for the handling of elements which are not a number.
sum_n(int $n)
Calculates the sum of x_1^n + x_2^n + ...
product_n(int $n)
Calculates the product of x_1^n * x_2^n * ...
quantile(float $n)
n-Quantile of the data values
setData(array $stat_data)