ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilStatistics Class Reference
+ Collaboration diagram for ilStatistics:

Public Member Functions

 __construct ($nan_handling=NAN_HANDLING_REMOVE)
 Constructor of ilStatistics class. More...
 
 setNANHandling ($nan_handling=NAN_HANDLING_REMOVE)
 Set the handling of elements which are not a number. More...
 
 getNANHandling ()
 Get the handling of elements which are not a number. More...
 
 setData ($stat_data)
 Sets the data and checks for invalid values. More...
 
 getData ()
 Returns the numeric value array containing the data. More...
 
 min ()
 Calculates the minimum value. More...
 
 max ()
 Calculates the maximum value. More...
 
 count ()
 Calculates number of data values. More...
 
 sum_n ($n)
 Calculates the sum of x_1^n + x_2^n + ... More...
 
 sum ()
 Calculates the sum of x_1 + x_2 + ... More...
 
 sum2 ()
 Calculates the sum of x_1^2 + x_2^2 + ... More...
 
 product_n ($n)
 Calculates the product of x_1^n * x_2^n * ... More...
 
 product ($n)
 Calculates the product of x_1 * x_2 * ... More...
 
 arithmetic_mean ()
 Arithmetic mean of the data values xbar = (1/n)*∑x_i. More...
 
 geometric_mean ()
 Geometric mean of the data values geometric_mean = (x_1 * x_2 * ... More...
 
 harmonic_mean ()
 Harmonic mean of the data values harmonic_mean = n/(1/x_1 + 1/x_2 + ... More...
 
 median ()
 Median of the data values. More...
 
 rank ($value)
 Returns the rank of a given value. More...
 
 rank_median ()
 Returns the rank of the median. More...
 
 quantile ($n)
 n-Quantile of the data values More...
 
 validate ()
 Validates the numeric data and handles values which are not a number according to the $nan_handling variable. More...
 

Data Fields

 $nan_handling
 
 $stat_data
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilStatistics::__construct (   $nan_handling = NAN_HANDLING_REMOVE)

Constructor of ilStatistics class.

public

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

References $nan_handling, and array.

44  {
45  $this->nan_handling = $nan_handling;
46  $this->stat_data = array();
47  }
Create styles array
The data for the language used.

Member Function Documentation

◆ arithmetic_mean()

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 228 of file class.ilStatistics.php.

References count(), and sum().

229  {
230  $sum = $this->sum();
231  if ($sum === false) {
232  return false;
233  }
234  $count = $this->count();
235  if ($count == 0) {
236  return false;
237  }
238  return (double) ($sum/$count);
239  }
sum()
Calculates the sum of x_1 + x_2 + ...
count()
Calculates number of data values.
+ Here is the call graph for this function:

◆ count()

ilStatistics::count ( )

Calculates number of data values.

Returns
mixed The number of data values public

Definition at line 140 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().

141  {
142  return count($this->stat_data);
143  }
count()
Calculates number of data values.
+ Here is the caller graph for this function:

◆ geometric_mean()

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 252 of file class.ilStatistics.php.

References count(), and product().

253  {
254  $prod = $this->product();
255  if (($prod === false) or ($prod === 0)) {
256  return false;
257  }
258  $count = $this->count();
259  if ($count == 0) {
260  return false;
261  }
262  return pow((double) $prod, (double) (1/$count));
263  }
product($n)
Calculates the product of x_1 * x_2 * ...
count()
Calculates number of data values.
+ Here is the call graph for this function:

◆ getData()

ilStatistics::getData ( )

Returns the numeric value array containing the data.

Returns
array An array containing the sorted numeric data public

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

References $stat_data.

96  {
97  return $this->stat_data;
98  }

◆ getNANHandling()

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 72 of file class.ilStatistics.php.

References $nan_handling.

73  {
74  return $this->nan_handling;
75  }

◆ harmonic_mean()

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 272 of file class.ilStatistics.php.

References count(), and min().

273  {
274  $min = $this->min();
275  if (($min === false) or ($min === 0)) {
276  return false;
277  }
278  $count = $this->count();
279  if ($count == 0) {
280  return false;
281  }
282  $sum = 0;
283  foreach ($this->stat_data as $value) {
284  $sum += 1/$value;
285  }
286  return $count/$sum;
287  }
min()
Calculates the minimum value.
count()
Calculates number of data values.
+ Here is the call graph for this function:

◆ max()

ilStatistics::max ( )

Calculates the maximum value.

Returns
mixed The maximum value or false, if no maximum exists
See also
min() User interface

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

References count().

125  {
126  if (count($this->stat_data)) {
127  $max = max($this->stat_data);
128  } else {
129  $max = false;
130  }
131  return $max;
132  }
max()
Calculates the maximum value.
count()
Calculates number of data values.
+ Here is the call graph for this function:

◆ median()

ilStatistics::median ( )

Median of the data values.

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

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

References count().

296  {
297  $median = false;
298  if (count($this->stat_data)) {
299  $median = 0;
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;
303  } else {
304  $median = $this->stat_data[(($count + 1) / 2) - 1];
305  }
306  }
307  return $median;
308  }
count()
Calculates number of data values.
+ Here is the call graph for this function:

◆ min()

ilStatistics::min ( )

Calculates the minimum value.

Returns
mixed The minimum value or false, if no minimum exists
See also
max() User interface

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

References count().

Referenced by harmonic_mean(), and product_n().

108  {
109  if (count($this->stat_data)) {
110  $min = min($this->stat_data);
111  } else {
112  $min = false;
113  }
114  return $min;
115  }
min()
Calculates the minimum value.
count()
Calculates number of data values.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ product()

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 216 of file class.ilStatistics.php.

References product_n().

Referenced by geometric_mean().

217  {
218  return $this->product_n(1);
219  }
product_n($n)
Calculates the product of x_1^n * x_2^n * ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ product_n()

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 194 of file class.ilStatistics.php.

References $n, count(), and min().

Referenced by product().

195  {
196  $prod_n = false;
197  if (count($this->stat_data)) {
198  if ($this->min() === 0) {
199  return 0.0;
200  }
201  $prod_n = 1.0;
202  foreach ($this->stat_data as $value) {
203  $prod_n *= pow((double) $value, (double) $n);
204  }
205  }
206  return $prod_n;
207  }
min()
Calculates the minimum value.
$n
Definition: RandomTest.php:85
count()
Calculates number of data values.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quantile()

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 360 of file class.ilStatistics.php.

References $n, and count().

361  {
362  $count = $this->count();
363  if ($count == 0) {
364  return false;
365  }
366  $nprod = ($n/100)*$count;
367  if (intval($nprod) == $nprod) {
368  $k = $nprod;
369  if ($k == 0) {
370  return $this->stat_data[$k];
371  } elseif ($k == $count) {
372  return $this->stat_data[$k-1];
373  } else {
374  return ($this->stat_data[$k-1] + $this->stat_data[$k])/2;
375  }
376  } else {
377  $k = ceil($nprod);
378  return $this->stat_data[$k-1];
379  }
380  }
$n
Definition: RandomTest.php:85
count()
Calculates number of data values.
+ Here is the call graph for this function:

◆ rank()

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 316 of file class.ilStatistics.php.

References count().

317  {
318  if (!is_numeric($value)) {
319  return false;
320  }
321  $rank = array_search($value, $this->stat_data);
322  if ($rank !== false) {
323  $rank = $this->count() - $rank;
324  }
325  return $rank;
326  }
count()
Calculates number of data values.
+ Here is the call graph for this function:

◆ rank_median()

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 338 of file class.ilStatistics.php.

References count().

339  {
340  $count = $this->count();
341  if ($count == 0) {
342  return false;
343  }
344 
345  if (($count % 2) == 0) {
346  $rank_median = ($count + 1) / 2;
347  } else {
348  $rank_median = ($count + 1) / 2;
349  }
350  return $rank_median;
351  }
count()
Calculates number of data values.
+ Here is the call graph for this function:

◆ setData()

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 83 of file class.ilStatistics.php.

References $stat_data, and validate().

84  {
85  $this->stat_data = array_values($stat_data);
86  $this->validate();
87  }
validate()
Validates the numeric data and handles values which are not a number according to the $nan_handling v...
+ Here is the call graph for this function:

◆ setNANHandling()

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 58 of file class.ilStatistics.php.

References $nan_handling.

59  {
60  $this->nan_handling = $nan_handling;
61  }

◆ sum()

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 170 of file class.ilStatistics.php.

References sum_n().

Referenced by arithmetic_mean().

171  {
172  return $this->sum_n(1);
173  }
sum_n($n)
Calculates the sum of x_1^n + x_2^n + ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sum2()

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 182 of file class.ilStatistics.php.

References sum_n().

183  {
184  return $this->sum_n(2);
185  }
sum_n($n)
Calculates the sum of x_1^n + x_2^n + ...
+ Here is the call graph for this function:

◆ sum_n()

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 152 of file class.ilStatistics.php.

References $n, and count().

Referenced by sum(), and sum2().

153  {
154  $sum_n = false;
155  if (count($this->stat_data)) {
156  $sum_n = 0;
157  foreach ($this->stat_data as $value) {
158  $sum_n += pow((double) $value, (double) $n);
159  }
160  }
161  return $sum_n;
162  }
$n
Definition: RandomTest.php:85
count()
Calculates number of data values.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate()

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 390 of file class.ilStatistics.php.

References $key, $result, NAN_HANDLING_REMOVE, and NAN_HANDLING_ZERO.

Referenced by setData().

391  {
392  $result = true;
393  foreach ($this->stat_data as $key => $value) {
394  if (!is_numeric($value)) {
395  switch ($this->nan_handling) {
396  case NAN_HANDLING_REMOVE:
397  unset($this->stat_data[$key]);
398  break;
399  case NAN_HANDLING_ZERO:
400  $this->stat_data[$key] = 0;
401  break;
402  default:
403  $result = false;
404  }
405  }
406  }
407  sort($this->stat_data);
408  return $result;
409  }
const NAN_HANDLING_ZERO
$result
const NAN_HANDLING_REMOVE
This class provides mathematical functions for statistics.
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

Field Documentation

◆ $nan_handling

ilStatistics::$nan_handling

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

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

◆ $stat_data

ilStatistics::$stat_data

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

Referenced by getData(), and setData().


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