ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilStatistics Class Reference
+ Collaboration diagram for ilStatistics:

Public Member Functions

 ilStatistics ($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 + ... + x_i^n. More...
 
 sum ()
 Calculates the sum of x_1 + x_2 + ... + x_i. More...
 
 sum2 ()
 Calculates the sum of x_1^2 + x_2^2 + ... + x_i^2. More...
 
 product_n ($n)
 Calculates the product of x_1^n * x_2^n * ... * x_i^n. More...
 
 product ($n)
 Calculates the product of x_1 * x_2 * ... * x_i. 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 * ... * x_n)^(1/n) More...
 
 harmonic_mean ()
 Harmonic mean of the data values harmonic_mean = n/(1/x_1 + 1/x_2 + ... + 1/x_n) 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.

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 @access public

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

231 {
232 $sum = $this->sum();
233 if ($sum === false)
234 {
235 return false;
236 }
237 $count = $this->count();
238 if ($count == 0)
239 {
240 return false;
241 }
242 return (double)($sum/$count);
243 }
sum()
Calculates the sum of x_1 + x_2 + ... + x_i.
count()
Calculates number of data values.

References count(), and sum().

+ Here is the call graph for this function:

◆ count()

ilStatistics::count ( )

Calculates number of data values.

Returns
mixed The number of data values @access public

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

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

References count().

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

+ Here is the call graph for this function:
+ 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 @access public

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

256 {
257 $prod = $this->product();
258 if (($prod === false) or ($prod === 0))
259 {
260 return false;
261 }
262 $count = $this->count();
263 if ($count == 0)
264 {
265 return false;
266 }
267 return pow((double)$prod, (double)(1/$count));
268 }
product($n)
Calculates the product of x_1 * x_2 * ... * x_i.

References count(), and product().

+ 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 @access public

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

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

References $stat_data.

◆ 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 @access public

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

73 {
75 }

References $nan_handling.

◆ 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 @access public

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

277 {
278 $min = $this->min();
279 if (($min === false) or ($min === 0))
280 {
281 return false;
282 }
283 $count = $this->count();
284 if ($count == 0)
285 {
286 return false;
287 }
288 $sum = 0;
289 foreach ($this->stat_data as $value)
290 {
291 $sum += 1/$value;
292 }
293 return $count/$sum;
294 }
min()
Calculates the minimum value.

References count(), and min().

+ Here is the call graph for this function:

◆ ilStatistics()

ilStatistics::ilStatistics (   $nan_handling = NAN_HANDLING_REMOVE)

Constructor of ilStatistics class.

@access public

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

44 {
45 $this->nan_handling = $nan_handling;
46 $this->stat_data = array();
47 }

References $nan_handling.

◆ max()

ilStatistics::max ( )

Calculates the maximum value.

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

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

126 {
127 if (count($this->stat_data))
128 {
129 $max = max($this->stat_data);
130 }
131 else
132 {
133 $max = false;
134 }
135 return $max;
136 }
max()
Calculates the maximum value.

References count(), and max().

Referenced by max().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ median()

ilStatistics::median ( )

Median of the data values.

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

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

302 {
303 $median = false;
304 if (count($this->stat_data))
305 {
306 $median = 0;
307 $count = $this->count();
308 if ((count($this->stat_data) % 2) == 0)
309 {
310 $median = ($this->stat_data[($count / 2) - 1] + $this->stat_data[($count / 2)]) / 2;
311 }
312 else
313 {
314 $median = $this->stat_data[(($count + 1) / 2) - 1];
315 }
316 }
317 return $median;
318 }

References count().

+ 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() @access User interface

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

107 {
108 if (count($this->stat_data))
109 {
110 $min = min($this->stat_data);
111 }
112 else
113 {
114 $min = false;
115 }
116 return $min;
117 }

References count(), and min().

Referenced by harmonic_mean(), min(), and product_n().

+ 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 @access public

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

220 {
221 return $this->product_n(1);
222 }
product_n($n)
Calculates the product of x_1^n * x_2^n * ... * x_i^n.

References product_n().

Referenced by geometric_mean().

+ 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 @access public

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

196 {
197 $prod_n = false;
198 if (count($this->stat_data))
199 {
200 if ($this->min() === 0)
201 {
202 return 0.0;
203 }
204 $prod_n = 1.0;
205 foreach ($this->stat_data as $value)
206 {
207 $prod_n *= pow((double)$value, (double)$n);
208 }
209 }
210 return $prod_n;
211 }
$n
Definition: RandomTest.php:80

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

Referenced by product().

+ 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 @access public

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

376 {
377 $count = $this->count();
378 if ($count == 0)
379 {
380 return false;
381 }
382 $nprod = ($n/100)*$count;
383 if (intval($nprod) == $nprod)
384 {
385 $k = $nprod;
386 if ($k == 0)
387 {
388 return $this->stat_data[$k];
389 }
390 else if ($k == $count)
391 {
392 return $this->stat_data[$k-1];
393 }
394 else
395 {
396 return ($this->stat_data[$k-1] + $this->stat_data[$k])/2;
397 }
398 }
399 else
400 {
401 $k = ceil($nprod);
402 return $this->stat_data[$k-1];
403 }
404 }

References $n, and count().

+ 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 @access public

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

327 {
328 if (!is_numeric($value))
329 {
330 return false;
331 }
332 $rank = array_search($value, $this->stat_data);
333 if ($rank !== FALSE)
334 {
335 $rank = $this->count() - $rank;
336 }
337 return $rank;
338 }

References count().

+ 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 @access public

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

351 {
352 $count = $this->count();
353 if ($count == 0)
354 {
355 return false;
356 }
357
358 if (($count % 2) == 0)
359 {
360 $rank_median = ($count + 1) / 2;
361 }
362 else
363 {
364 $rank_median = ($count + 1) / 2;
365 }
366 return $rank_median;
367 }

References count().

+ 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 @access public

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

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

References $stat_data, and validate().

+ 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 @access public

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

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

References $nan_handling.

◆ 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 @access public

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

174 {
175 return $this->sum_n(1);
176 }
sum_n($n)
Calculates the sum of x_1^n + x_2^n + ... + x_i^n.

References sum_n().

Referenced by arithmetic_mean().

+ 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 @access public

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

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

References sum_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 @access public

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

155 {
156 $sum_n = false;
157 if (count($this->stat_data))
158 {
159 $sum_n = 0;
160 foreach ($this->stat_data as $value)
161 {
162 $sum_n += pow((double)$value, (double)$n);
163 }
164 }
165 return $sum_n;
166 }

References $n, and count().

Referenced by sum(), and sum2().

+ 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 @access private

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

415 {
416 $result = true;
417 foreach ($this->stat_data as $key => $value)
418 {
419 if (!is_numeric($value)) {
420 switch ($this->nan_handling) {
422 unset($this->stat_data[$key]);
423 break;
425 $this->stat_data[$key] = 0;
426 break;
427 default:
428 $result = false;
429 }
430 }
431 }
432 sort($this->stat_data);
433 return $result;
434 }
$result
const NAN_HANDLING_REMOVE
This class provides mathematical functions for statistics.
const NAN_HANDLING_ZERO

References $result, NAN_HANDLING_REMOVE, and NAN_HANDLING_ZERO.

Referenced by setData().

+ 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 getNANHandling(), ilStatistics(), 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: