15 define(
"NAN_HANDLING_REMOVE", 0);
16 define(
"NAN_HANDLING_ZERO", 1);
46 $this->stat_data = array();
108 if (
count($this->stat_data))
110 $min =
min($this->stat_data);
127 if (
count($this->stat_data))
129 $max =
max($this->stat_data);
145 return count($this->stat_data);
157 if (
count($this->stat_data))
160 foreach ($this->stat_data as $value)
162 $sum_n += pow((
double)$value, (
double)
$n);
175 return $this->
sum_n(1);
186 return $this->
sum_n(2);
198 if (
count($this->stat_data))
200 if ($this->
min() === 0)
205 foreach ($this->stat_data as $value)
207 $prod_n *= pow((
double)$value, (
double)
$n);
237 $count = $this->
count();
242 return (
double)($sum/$count);
258 if (($prod ===
false) or ($prod === 0))
262 $count = $this->
count();
267 return pow((
double)$prod, (
double)(1/$count));
279 if (($min ===
false) or ($min === 0))
283 $count = $this->
count();
289 foreach ($this->stat_data as $value)
304 if (
count($this->stat_data))
307 $count = $this->
count();
308 if ((
count($this->stat_data) % 2) == 0)
310 $median = ($this->stat_data[($count / 2) - 1] + $this->stat_data[($count / 2)]) / 2;
314 $median = $this->stat_data[(($count + 1) / 2) - 1];
328 if (!is_numeric($value))
332 $rank = array_search($value, $this->stat_data);
335 $rank = $this->
count() - $rank;
352 $count = $this->
count();
358 if (($count % 2) == 0)
360 $rank_median = ($count + 1) / 2;
364 $rank_median = ($count + 1) / 2;
377 $count = $this->
count();
382 $nprod = (
$n/100)*$count;
383 if (intval($nprod) == $nprod)
388 return $this->stat_data[$k];
390 else if ($k == $count)
392 return $this->stat_data[$k-1];
396 return ($this->stat_data[$k-1] + $this->stat_data[$k])/2;
402 return $this->stat_data[$k-1];
417 foreach ($this->stat_data as $key => $value)
419 if (!is_numeric($value)) {
420 switch ($this->nan_handling) {
422 unset($this->stat_data[$key]);
425 $this->stat_data[$key] = 0;
432 sort($this->stat_data);
const NAN_HANDLING_REMOVE
This class provides mathematical functions for statistics.
sum()
Calculates the sum of x_1 + x_2 + ... + x_i.
setNANHandling($nan_handling=NAN_HANDLING_REMOVE)
Set the handling of elements which are not a number.
product_n($n)
Calculates the product of x_1^n * x_2^n * ... * x_i^n.
product($n)
Calculates the product of x_1 * x_2 * ... * x_i.
ilStatistics($nan_handling=NAN_HANDLING_REMOVE)
Constructor of ilStatistics class.
quantile($n)
n-Quantile of the data values
arithmetic_mean()
Arithmetic mean of the data values xbar = (1/n)*∑x_i.
getData()
Returns the numeric value array containing the data.
sum_n($n)
Calculates the sum of x_1^n + x_2^n + ... + x_i^n.
setData($stat_data)
Sets the data and checks for invalid values.
harmonic_mean()
Harmonic mean of the data values harmonic_mean = n/(1/x_1 + 1/x_2 + ... + 1/x_n)
geometric_mean()
Geometric mean of the data values geometric_mean = (x_1 * x_2 * ... * x_n)^(1/n)
median()
Median of the data values.
rank($value)
Returns the rank of a given value.
getNANHandling()
Get the handling of elements which are not a number.
rank_median()
Returns the rank of the median.
min()
Calculates the minimum value.
max()
Calculates the maximum value.
count()
Calculates number of data values.
sum2()
Calculates the sum of x_1^2 + x_2^2 + ... + x_i^2.
validate()
Validates the numeric data and handles values which are not a number according to the $nan_handling v...