ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilStatistics Class Reference
+ Collaboration diagram for ilStatistics:

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

Detailed Description

Definition at line 38 of file class.ilStatistics.php.

Member Function Documentation

ilStatistics::arithmetic_mean ( )

Arithmetic mean of the data values xbar = (1/n)*∑x_i.

Returns
mixed The arithmetic mean or false, if there is an error or no values public

Definition at line 251 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);
}

+ Here is the call graph for this function:

ilStatistics::count ( )

Calculates number of data values.

Returns
mixed The number of data values public

Definition at line 164 of file class.ilStatistics.php.

Referenced by arithmetic_mean(), geometric_mean(), harmonic_mean(), max(), median(), min(), product_n(), quantile(), rank(), rank_median(), and sum_n().

{
return count($this->stat_data);
}

+ Here is the caller graph for this function:

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.

Returns
mixed The geometric mean or false, if there is an error or no values public

Definition at line 276 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));
}

+ Here is the call graph for this function:

ilStatistics::getData ( )

Returns the numeric value array containing the data.

Returns
array An array containing the sorted numeric data public

Definition at line 115 of file class.ilStatistics.php.

References $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.

Returns
integer A constant defining the handling of elements which are not a number public

Definition at line 92 of file class.ilStatistics.php.

References $nan_handling.

{
}
ilStatistics::harmonic_mean ( )

Harmonic mean of the data values harmonic_mean = n/(1/x_1 + 1/x_2 + ...

  • 1/x_n)
Returns
mixed The harmonic mean or false, if there is an error or no values public

Definition at line 297 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;
}

+ Here is the call graph for this function:

ilStatistics::ilStatistics (   $nan_handling = NAN_HANDLING_REMOVE)

Constructor of ilStatistics class.

public

Definition at line 63 of file class.ilStatistics.php.

References $nan_handling.

{
$this->nan_handling = $nan_handling;
$this->stat_data = array();
}
ilStatistics::max ( )

Calculates the maximum value.

Returns
mixed The maximum value or false, if no maximum exists
See Also
min() Public

Definition at line 146 of file class.ilStatistics.php.

References count().

{
if (count($this->stat_data))
{
$max = max($this->stat_data);
}
else
{
$max = false;
}
return $max;
}

+ Here is the call graph for this function:

ilStatistics::median ( )

Median of the data values.

Returns
mixed The median or false, if there are no data values public

Definition at line 322 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;
}

+ Here is the call graph for this function:

ilStatistics::min ( )

Calculates the minimum value.

Returns
mixed The minimum value or false, if no minimum exists
See Also
max() Public

Definition at line 127 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;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilStatistics::product (   $n)

Calculates the product of x_1 * x_2 * ...

  • x_i
Parameters
numeric$nThe exponent
Returns
mixed The product of x_1 * x_2 * ... * x_i or false, if no values exist public

Definition at line 240 of file class.ilStatistics.php.

References product_n().

Referenced by geometric_mean().

{
return $this->product_n(1);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilStatistics::product_n (   $n)

Calculates the product of x_1^n * x_2^n * ...

  • x_i^n
Parameters
numeric$nThe exponent
Returns
mixed The product of x_1^n * x_2^n * ... * x_i^n or false, if no values exist public

Definition at line 216 of file class.ilStatistics.php.

References $n, 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;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilStatistics::quantile (   $n)

n-Quantile of the data values

Parameters
double$nA value between 0 an 100 calculating the n-Quantile
Returns
mixed The n-quantile or false, if there are no data values public

Definition at line 396 of file class.ilStatistics.php.

References $n, and 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];
}
}

+ Here is the call graph for this function:

ilStatistics::rank (   $value)

Returns the rank of a given value.

Returns
mixed The rank, if the value exists in the data, otherwise false public

Definition at line 346 of file class.ilStatistics.php.

References count().

{
if (!is_numeric($value))
{
return false;
}
$rank = array_search($value, $this->stat_data);
if ($rank !== FALSE)
{
$rank = $this->count() - $rank;
}
return $rank;
}

+ Here is the call graph for this function:

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.

Returns
mixed The rank of the median, otherwise false public

Definition at line 370 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;
}

+ Here is the call graph for this function:

ilStatistics::setData (   $stat_data)

Sets the data and checks for invalid values.

Parameters
array$stat_dataAn array containing the numeric data public

Definition at line 103 of file class.ilStatistics.php.

References $stat_data, and validate().

{
$this->stat_data = array_values($stat_data);
$this->validate();
}

+ Here is the call graph for this function:

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.

Parameters
integer$nan_handlingA constant defining the handling of elements which are not a number public

Definition at line 78 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
Returns
mixed The sum of x_1 + x_2 + ... + x_i or false, if no values exist public

Definition at line 194 of file class.ilStatistics.php.

References sum_n().

Referenced by arithmetic_mean().

{
return $this->sum_n(1);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilStatistics::sum2 ( )

Calculates the sum of x_1^2 + x_2^2 + ...

  • x_i^2
Returns
mixed The sum of x_1^2 + x_2^2 + ... + x_i^2 or false, if no values exist public

Definition at line 205 of file class.ilStatistics.php.

References sum_n().

{
return $this->sum_n(2);
}

+ Here is the call graph for this function:

ilStatistics::sum_n (   $n)

Calculates the sum of x_1^n + x_2^n + ...

  • x_i^n
Parameters
numeric$nThe exponent
Returns
mixed The sum of x_1^n + x_2^n + ... + x_i^n or false, if no values exist public

Definition at line 175 of file class.ilStatistics.php.

References $n, and 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;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

Returns
boolean Returns true on success, otherwise false private

Definition at line 434 of file class.ilStatistics.php.

References $result, NAN_HANDLING_REMOVE, and NAN_HANDLING_ZERO.

Referenced by setData().

{
$result = true;
foreach ($this->stat_data as $key => $value)
{
if (!is_numeric($value)) {
switch ($this->nan_handling) {
unset($this->stat_data[$key]);
break;
$this->stat_data[$key] = 0;
break;
default:
$result = false;
}
}
}
sort($this->stat_data);
return $result;
}

+ Here is the caller graph for this function:

Field Documentation

ilStatistics::$nan_handling

Definition at line 48 of file class.ilStatistics.php.

Referenced by getNANHandling(), ilStatistics(), and setNANHandling().

ilStatistics::$stat_data

Definition at line 56 of file class.ilStatistics.php.

Referenced by getData(), and setData().


The documentation for this class was generated from the following file: