15 define(
"NAN_HANDLING_REMOVE", 0);
16 define(
"NAN_HANDLING_ZERO", 1);
46 $this->stat_data = array();
109 if (
count($this->stat_data)) {
110 $min =
min($this->stat_data);
126 if (
count($this->stat_data)) {
127 $max =
max($this->stat_data);
142 return count($this->stat_data);
155 if (
count($this->stat_data)) {
157 foreach ($this->stat_data as $value) {
158 $sum_n += pow((
double) $value, (
double)
$n);
172 return $this->
sum_n(1);
184 return $this->
sum_n(2);
197 if (
count($this->stat_data)) {
198 if ($this->
min() === 0) {
202 foreach ($this->stat_data as $value) {
203 $prod_n *= pow((
double) $value, (
double)
$n);
231 if ($sum ===
false) {
234 $count = $this->
count();
238 return (
double) ($sum / $count);
255 if (($prod ===
false)
or ($prod === 0)) {
258 $count = $this->
count();
262 return pow((
double) $prod, (
double) (1 / $count));
275 if (($min ===
false)
or ($min === 0)) {
278 $count = $this->
count();
283 foreach ($this->stat_data as $value) {
286 return $count / $sum;
298 if (
count($this->stat_data)) {
300 $count = $this->
count();
301 if ((
count($this->stat_data) % 2) == 0) {
302 $median = ($this->stat_data[($count / 2) - 1] + $this->stat_data[($count / 2)]) / 2;
304 $median = $this->stat_data[(($count + 1) / 2) - 1];
318 if (!is_numeric($value)) {
321 $rank = array_search($value, $this->stat_data);
322 if ($rank !==
false) {
323 $rank = $this->
count() - $rank;
340 $count = $this->
count();
345 if (($count % 2) == 0) {
346 $rank_median = ($count + 1) / 2;
348 $rank_median = ($count + 1) / 2;
362 $count = $this->
count();
366 $nprod = (
$n / 100) * $count;
367 if (intval($nprod) == $nprod) {
370 return $this->stat_data[$k];
371 } elseif ($k == $count) {
372 return $this->stat_data[$k - 1];
374 return ($this->stat_data[$k - 1] + $this->stat_data[$k]) / 2;
378 return $this->stat_data[$k - 1];
393 foreach ($this->stat_data as
$key => $value) {
394 if (!is_numeric($value)) {
395 switch ($this->nan_handling) {
397 unset($this->stat_data[
$key]);
400 $this->stat_data[
$key] = 0;
407 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 + ...
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.