15 define(
"NAN_HANDLING_REMOVE", 0);
16 define(
"NAN_HANDLING_ZERO", 1);
46 $this->stat_data =
array();
85 $this->stat_data = array_values($stat_data);
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);
rank($value)
Returns the rank of a given value.
sum()
Calculates the sum of x_1 + x_2 + ...
arithmetic_mean()
Arithmetic mean of the data values xbar = (1/n)*∑x_i.
quantile($n)
n-Quantile of the data values
__construct($nan_handling=NAN_HANDLING_REMOVE)
Constructor of ilStatistics class.
const NAN_HANDLING_REMOVE
This class provides mathematical functions for statistics.
getData()
Returns the numeric value array containing the data.
max()
Calculates the maximum value.
validate()
Validates the numeric data and handles values which are not a number according to the $nan_handling v...
min()
Calculates the minimum value.
median()
Median of the data values.
harmonic_mean()
Harmonic mean of the data values harmonic_mean = n/(1/x_1 + 1/x_2 + ...
Create styles array
The data for the language used.
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 + ...
product($n)
Calculates the product of x_1 * x_2 * ...
count()
Calculates number of data values.
getNANHandling()
Get the handling of elements which are not a number.
product_n($n)
Calculates the product of x_1^n * x_2^n * ...
rank_median()
Returns the rank of the median.
setNANHandling($nan_handling=NAN_HANDLING_REMOVE)
Set the handling of elements which are not a number.
sum_n($n)
Calculates the sum of x_1^n + x_2^n + ...
setData($stat_data)
Sets the data and checks for invalid values.