ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilStatistics Class Reference

Constants for the handling of elements which are not a number. More...

+ Collaboration diagram for ilStatistics:

Public Member Functions

 setData (array $stat_data)
 
 getData ()
 
 min ()
 
 max ()
 Calculates the maximum value. More...
 
 count ()
 Calculates number of data values. More...
 
 sum_n (int $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 (int $n)
 Calculates the product of x_1^n * x_2^n * ... More...
 
 product (int $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 (float $value)
 Returns the rank of a given value. More...
 
 rank_median ()
 Returns the rank of the median. More...
 
 quantile (float $n)
 n-Quantile of the data values More...
 

Data Fields

array $stat_data = []
 

Private Member Functions

 removeNonNumericValues ()
 

Detailed Description

Constants for the handling of elements which are not a number.

This class provides mathematical functions for statistics. It works on an array of numeric values.

Author
Helmut Schottmüller hscho.nosp@m.ttm@.nosp@m.tzi.d.nosp@m.e
Version
$Id$

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

Member Function Documentation

◆ arithmetic_mean()

ilStatistics::arithmetic_mean ( )

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

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

References count(), and sum().

142  : ?float
143  {
144  $sum = $this->sum();
145  if ($sum === null) {
146  return null;
147  }
148 
149  $count = $this->count();
150  if ($count === 0) {
151  return null;
152  }
153  return (float) ($sum / $count);
154  }
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.

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

Referenced by arithmetic_mean(), geometric_mean(), harmonic_mean(), median(), quantile(), rank(), and rank_median().

72  : int
73  {
74  return count($this->stat_data);
75  }
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.

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

References count(), and product().

164  : ?float
165  {
166  $prod = $this->product(1);
167  if (($prod === null) || ($prod === 0)) {
168  return null;
169  }
170  $count = $this->count();
171  if ($count === 0) {
172  return null;
173  }
174  return pow((float) $prod, (float) (1 / $count));
175  }
product(int $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 ( )

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

References $stat_data.

43  : array
44  {
45  return $this->stat_data;
46  }

◆ harmonic_mean()

ilStatistics::harmonic_mean ( )

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

  • 1/x_n)

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

References count(), and min().

181  : ?float
182  {
183  $min = $this->min();
184  if (($min === null) or ($min === 0)) {
185  return null;
186  }
187  $count = $this->count();
188  if ($count === 0) {
189  return null;
190  }
191  $sum = 0.0;
192  foreach ($this->stat_data as $value) {
193  $sum += 1 / $value;
194  }
195  return $count / $sum;
196  }
count()
Calculates number of data values.
+ Here is the call graph for this function:

◆ max()

ilStatistics::max ( )

Calculates the maximum value.

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

60  : ?float
61  {
62  if ($this->stat_data === []) {
63  return null;
64  }
65 
66  return max($this->stat_data);
67  }
max()
Calculates the maximum value.

◆ median()

ilStatistics::median ( )

Median of the data values.

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

References count().

201  : ?float
202  {
203  if ($this->stat_data === null) {
204  return null;
205  }
206 
207  $median = 0.0;
208  $count = $this->count();
209  if ((count($this->stat_data) % 2) === 0) {
210  return ($this->stat_data[($count / 2) - 1] + $this->stat_data[($count / 2)]) / 2;
211  }
212 
213  return $this->stat_data[(($count + 1) / 2) - 1];
214  }
count()
Calculates number of data values.
+ Here is the call graph for this function:

◆ min()

ilStatistics::min ( )

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

Referenced by harmonic_mean(), and product_n().

48  : ?float
49  {
50  if ($this->stat_data === []) {
51  return null;
52  }
53 
54  return min($this->stat_data);
55  }
+ Here is the caller graph for this function:

◆ product()

ilStatistics::product ( int  $n)

Calculates the product of x_1 * x_2 * ...

  • x_i

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

References product_n().

Referenced by geometric_mean().

133  : ?float
134  {
135  return $this->product_n(1);
136  }
product_n(int $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 ( int  $n)

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

  • x_i^n

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

References min().

Referenced by product().

113  : ?float
114  {
115  if ($this->stat_data === []) {
116  return null;
117  }
118 
119  if ($this->min() === 0) {
120  return 0.0;
121  }
122 
123  $prod_n = 1.0;
124  foreach ($this->stat_data as $value) {
125  $prod_n *= pow((float) $value, (float) $n);
126  }
127  return $prod_n;
128  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quantile()

ilStatistics::quantile ( float  $n)

n-Quantile of the data values

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

References count(), and ILIAS\Repository\int().

253  : ?float
254  {
255  $count = $this->count();
256  if ($count === 0) {
257  return null;
258  }
259 
260  $nprod = ($n / 100) * $count;
261  if (intval($nprod) != $nprod) {
262  return $this->stat_data[ceil($nprod) - 1];
263  }
264 
265  if ($nprod === 0.0) {
266  return $this->stat_data[0];
267  }
268 
269  if ($nprod === (float) $count) {
270  return $this->stat_data[(int) $nprod - 1];
271  }
272 
273  return ($this->stat_data[(int) $nprod - 1] + $this->stat_data[(int) $nprod]) / 2;
274  }
count()
Calculates number of data values.
+ Here is the call graph for this function:

◆ rank()

ilStatistics::rank ( float  $value)

Returns the rank of a given value.

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

References count().

219  : ?int
220  {
221  $rank = array_search($value, $this->stat_data);
222  if ($rank === false) {
223  return null;
224  }
225 
226  return $this->count() - $rank;
227  }
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.

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

References count().

236  : ?float
237  {
238  $count = $this->count();
239  if ($count === 0) {
240  return null;
241  }
242 
243  if (($count % 2) === 0) {
244  return $rank_median = ($count + 1) / 2;
245  }
246 
247  return $rank_median = ($count + 1) / 2;
248  }
count()
Calculates number of data values.
+ Here is the call graph for this function:

◆ removeNonNumericValues()

ilStatistics::removeNonNumericValues ( )
private

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

References ILIAS\LTI\ToolProvider\$key.

Referenced by setData().

276  : void
277  {
278 
279  foreach ($this->stat_data as $key => $value) {
280  if (!is_numeric($value)) {
281  unset($this->stat_data[$key]);
282  break;
283  }
284  }
285  sort($this->stat_data);
286  }
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the caller graph for this function:

◆ setData()

ilStatistics::setData ( array  $stat_data)

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

References removeNonNumericValues().

37  : void
38  {
39  $this->stat_data = array_values($stat_data);
40  $this->removeNonNumericValues();
41  }
+ Here is the call graph for this function:

◆ sum()

ilStatistics::sum ( )

Calculates the sum of x_1 + x_2 + ...

  • x_i

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

References sum_n().

Referenced by arithmetic_mean().

96  : ?float
97  {
98  return $this->sum_n(1);
99  }
sum_n(int $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

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

References sum_n().

105  : float
106  {
107  return $this->sum_n(2);
108  }
sum_n(int $n)
Calculates the sum of x_1^n + x_2^n + ...
+ Here is the call graph for this function:

◆ sum_n()

ilStatistics::sum_n ( int  $n)

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

  • x_i^n

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

Referenced by sum(), and sum2().

80  : ?float
81  {
82  if ($this->stat_data === []) {
83  return null;
84  }
85 
86  $sum_n = 0;
87  foreach ($this->stat_data as $value) {
88  $sum_n += pow((float) $value, (float) $n);
89  }
90  return $sum_n;
91  }
+ Here is the caller graph for this function:

Field Documentation

◆ $stat_data

array ilStatistics::$stat_data = []

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

Referenced by getData().


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