# ilStatistics Class Reference

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

\$nan_handling
\$stat_data

## Detailed Description

Definition at line 39 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 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);
}
``` 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 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);
}
``` 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 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));
}
``` 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 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.

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

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)

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

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;
}
``` Here is the call graph for this function:

 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.

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

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;
}
``` 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 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;
}
``` 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
max() Public

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;
}
``` 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 \$n The exponent
Returns:
mixed The product of x_1 * x_2 * ... * x_i or false, if no values exist public

Definition at line 241 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 \$n The 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 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;
}
``` 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 \$n A 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 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];
}
}
``` 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 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.

Returns:
mixed The rank of the median, otherwise false public

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;
}
``` Here is the call graph for this function:

 ilStatistics::setData ( \$ stat_data )

Sets the data and checks for invalid values.

Parameters:
 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();
}
``` 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_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

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

Definition at line 195 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 206 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 \$n The 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 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;
}
``` 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 435 of file class.ilStatistics.php.

References \$key, and \$result.

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;
}
``` Here is the caller graph for this function:

## Field Documentation

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

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