Public Member Functions | |
ilStatistics ($nan_handling=NAN_HANDLING_REMOVE) | |
Constructor of ilStatistics class. | |
setNANHandling ($nan_handling=NAN_HANDLING_REMOVE) | |
Set the handling of elements which are not a number. | |
getNANHandling () | |
Get the handling of elements which are not a number. | |
setData ($stat_data) | |
Sets the data and checks for invalid values. | |
getData () | |
Returns the numeric value array containing the data. | |
min () | |
Calculates the minimum value. | |
max () | |
Calculates the maximum value. | |
count () | |
Calculates number of data values. | |
sum_n ($n) | |
Calculates the sum of x_1^n + x_2^n + ... | |
sum () | |
Calculates the sum of x_1 + x_2 + ... | |
sum2 () | |
Calculates the sum of x_1^2 + x_2^2 + ... | |
product_n ($n) | |
Calculates the product of x_1^n * x_2^n * ... | |
product ($n) | |
Calculates the product of x_1 * x_2 * ... | |
arithmetic_mean () | |
Arithmetic mean of the data values xbar = (1/n)*∑x_i. | |
geometric_mean () | |
Geometric mean of the data values geometric_mean = (x_1 * x_2 * ... | |
harmonic_mean () | |
Harmonic mean of the data values harmonic_mean = n/(1/x_1 + 1/x_2 + ... | |
median () | |
Median of the data values. | |
rank ($value) | |
Returns the rank of a given value. | |
rank_median () | |
Returns the rank of the median. | |
quantile ($n) | |
n-Quantile of the data values | |
validate () | |
Validates the numeric data and handles values which are not a number according to the $nan_handling variable. | |
Data Fields | |
$nan_handling | |
$stat_data |
Definition at line 39 of file class.ilStatistics.php.
ilStatistics::arithmetic_mean | ( | ) |
Arithmetic mean of the data values xbar = (1/n)*∑x_i.
Definition at line 252 of file class.ilStatistics.php.
References count(), and sum().
{ $sum = $this->sum(); if ($sum === false) { return false; } $count = $this->count(); if ($count == 0) { return false; } return (double)($sum/$count); }
ilStatistics::count | ( | ) |
Calculates number of data values.
Definition at line 165 of file class.ilStatistics.php.
Referenced by arithmetic_mean(), geometric_mean(), harmonic_mean(), max(), median(), min(), product_n(), quantile(), rank_median(), and sum_n().
{ return count($this->stat_data); }
ilStatistics::geometric_mean | ( | ) |
Geometric mean of the data values geometric_mean = (x_1 * x_2 * ...
* x_n)^(1/n)
The geometric mean of a set of positive data is defined as the product of all the members of the set, raised to a power equal to the reciprocal of the number of members.
Definition at line 277 of file class.ilStatistics.php.
References count(), and product().
{ $prod = $this->product(); if (($prod === false) or ($prod === 0)) { return false; } $count = $this->count(); if ($count == 0) { return false; } return pow((double)$prod, (double)(1/$count)); }
ilStatistics::getData | ( | ) |
Returns the numeric value array containing the data.
Definition at line 116 of file class.ilStatistics.php.
{
return $this->stat_data;
}
ilStatistics::getNANHandling | ( | ) |
Get the handling of elements which are not a number.
Returns NAN_HANDLING_REMOVE if all elements which are not a number will be removed. Returns NAN_HANDLING_ZERO if all elements which are not a number will be set to zero.
Definition at line 93 of file class.ilStatistics.php.
{
return $this->nan_handling;
}
ilStatistics::harmonic_mean | ( | ) |
Harmonic mean of the data values harmonic_mean = n/(1/x_1 + 1/x_2 + ...
+ 1/x_n)
Definition at line 298 of file class.ilStatistics.php.
References count(), and min().
{ $min = $this->min(); if (($min === false) or ($min === 0)) { return false; } $count = $this->count(); if ($count == 0) { return false; } $sum = 0; foreach ($this->stat_data as $value) { $sum += 1/$value; } return $count/$sum; }
ilStatistics::ilStatistics | ( | $ | nan_handling = NAN_HANDLING_REMOVE |
) |
Constructor of ilStatistics class.
public
Definition at line 64 of file class.ilStatistics.php.
References $nan_handling.
{ $this->nan_handling = $nan_handling; $this->stat_data = array(); }
ilStatistics::max | ( | ) |
Calculates the maximum value.
Definition at line 147 of file class.ilStatistics.php.
References count().
{ if (count($this->stat_data)) { $max = max($this->stat_data); } else { $max = false; } return $max; }
ilStatistics::median | ( | ) |
Median of the data values.
Definition at line 323 of file class.ilStatistics.php.
References count().
{ $median = false; if (count($this->stat_data)) { $median = 0; $count = $this->count(); if ((count($this->stat_data) % 2) == 0) { $median = ($this->stat_data[($count / 2) - 1] + $this->stat_data[($count / 2)]) / 2; } else { $median = $this->stat_data[(($count + 1) / 2) - 1]; } } return $median; }
ilStatistics::min | ( | ) |
Calculates the minimum value.
Definition at line 128 of file class.ilStatistics.php.
References count().
Referenced by harmonic_mean(), and product_n().
{ if (count($this->stat_data)) { $min = min($this->stat_data); } else { $min = false; } return $min; }
ilStatistics::product | ( | $ | n | ) |
Calculates the product of x_1 * x_2 * ...
* x_i
numeric | $n The exponent |
Definition at line 241 of file class.ilStatistics.php.
References product_n().
Referenced by geometric_mean().
{ return $this->product_n(1); }
ilStatistics::product_n | ( | $ | n | ) |
Calculates the product of x_1^n * x_2^n * ...
* x_i^n
numeric | $n The exponent |
Definition at line 217 of file class.ilStatistics.php.
References count(), and min().
Referenced by product().
{ $prod_n = false; if (count($this->stat_data)) { if ($this->min() === 0) { return 0.0; } $prod_n = 1.0; foreach ($this->stat_data as $value) { $prod_n *= pow((double)$value, (double)$n); } } return $prod_n; }
ilStatistics::quantile | ( | $ | n | ) |
n-Quantile of the data values
double | $n A value between 0 an 100 calculating the n-Quantile |
Definition at line 397 of file class.ilStatistics.php.
References count().
{ $count = $this->count(); if ($count == 0) { return false; } $nprod = ($n/100)*$count; if (intval($nprod) == $nprod) { $k = $nprod; if ($k == 0) { return $this->stat_data[$k]; } else if ($k == $count) { return $this->stat_data[$k-1]; } else { return ($this->stat_data[$k-1] + $this->stat_data[$k])/2; } } else { $k = ceil($nprod); return $this->stat_data[$k-1]; } }
ilStatistics::rank | ( | $ | value | ) |
Returns the rank of a given value.
Definition at line 347 of file class.ilStatistics.php.
{ if (!is_numeric($value)) { return false; } $rank = array_search($value, $this->stat_data); if ($rank !== FALSE) { $rank += 1; } return $rank; }
ilStatistics::rank_median | ( | ) |
Returns the rank of the median.
This method is different from the rank method because the median could be the arithmetic mean of the two middle values when the data size is even. In this case the median could a value which is not part of the data set.
Definition at line 371 of file class.ilStatistics.php.
References count().
{ $count = $this->count(); if ($count == 0) { return false; } if (($count % 2) == 0) { $rank_median = ($count + 1) / 2; } else { $rank_median = ($count + 1) / 2; } return $rank_median; }
ilStatistics::setData | ( | $ | stat_data | ) |
Sets the data and checks for invalid values.
array | $stat_data An array containing the numeric data public |
Definition at line 104 of file class.ilStatistics.php.
References $stat_data, and validate().
{ $this->stat_data = array_values($stat_data); $this->validate(); }
ilStatistics::setNANHandling | ( | $ | nan_handling = NAN_HANDLING_REMOVE |
) |
Set the handling of elements which are not a number.
If set to NAN_HANDLING_REMOVE, all elements which are not a number will be removed, if set to NAN_HANDLING_ZERO, all elements which are not a number will be set to zero.
integer | $nan_handling A constant defining the handling of elements which are not a number public |
Definition at line 79 of file class.ilStatistics.php.
References $nan_handling.
{ $this->nan_handling = $nan_handling; }
ilStatistics::sum | ( | ) |
Calculates the sum of x_1 + x_2 + ...
+ x_i
Definition at line 195 of file class.ilStatistics.php.
References sum_n().
Referenced by arithmetic_mean().
{ return $this->sum_n(1); }
ilStatistics::sum2 | ( | ) |
Calculates the sum of x_1^2 + x_2^2 + ...
+ x_i^2
Definition at line 206 of file class.ilStatistics.php.
References sum_n().
{ return $this->sum_n(2); }
ilStatistics::sum_n | ( | $ | n | ) |
Calculates the sum of x_1^n + x_2^n + ...
+ x_i^n
numeric | $n The exponent |
Definition at line 176 of file class.ilStatistics.php.
References count().
Referenced by sum(), and sum2().
{ $sum_n = false; if (count($this->stat_data)) { $sum_n = 0; foreach ($this->stat_data as $value) { $sum_n += pow((double)$value, (double)$n); } } return $sum_n; }
ilStatistics::validate | ( | ) |
Validates the numeric data and handles values which are not a number according to the $nan_handling variable.
After validation the data is sorted.
Definition at line 435 of file class.ilStatistics.php.
Referenced by setData().
{ $result = true; foreach ($this->stat_data as $key => $value) { if (!is_numeric($value)) { switch ($this->nan_handling) { case NAN_HANDLING_REMOVE: unset($this->stat_data[$key]); break; case NAN_HANDLING_ZERO: $this->stat_data[$key] = 0; break; default: $result = false; } } } sort($this->stat_data); return $result; }
ilStatistics::$nan_handling |
Definition at line 49 of file class.ilStatistics.php.
Referenced by ilStatistics(), and setNANHandling().
ilStatistics::$stat_data |
Definition at line 57 of file class.ilStatistics.php.
Referenced by setData().