ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Base Class Reference
+ Collaboration diagram for Base:

Public Member Functions

 Math_Stats ($nullOption=STATS_REJECT_NULL)
 Constructor for the class.
 setData ($arr, $opt=STATS_DATA_SIMPLE)
 Sets and verifies the data, checking for nulls and using the current null handling option.
 getData ($expanded=false)
 Returns the data which might have been modified according to the current null handling options.
 setNullOption ($nullOption)
 Sets the null handling option.
 studentize ()
 Transforms the data by substracting each entry from the mean and dividing by its standard deviation.
 center ()
 Transforms the data by substracting each entry from the mean.
 calc ($mode, $returnErrorObject=true)
 Calculates the basic or full statistics for the data set.
 calcBasic ($returnErrorObject=true)
 Calculates a basic set of statistics.
 calcFull ($returnErrorObject=true)
 Calculates a full set of statistics.
 min ()
 Calculates the minimum of a data set.
 max ()
 Calculates the maximum of a data set.
 sum ()
 Calculates SUM { xi } Handles cummulative data sets correctly.
 sum2 ()
 Calculates SUM { (xi)^2 } Handles cummulative data sets correctly.
 sumN ($n)
 Calculates SUM { (xi)^n } Handles cummulative data sets correctly.
 product ()
 Calculates PROD { (xi) }, (the product of all observations) Handles cummulative data sets correctly.
 productN ($n)
 Calculates PROD { (xi)^n }, which is the product of all observations Handles cummulative data sets correctly.
 count ()
 Calculates the number of data points in the set Handles cummulative data sets correctly.
 mean ()
 Calculates the mean (average) of the data points in the set Handles cummulative data sets correctly.
 range ()
 Calculates the range of the data set = max - min.
 variance ()
 Calculates the variance (unbiased) of the data points in the set Handles cummulative data sets correctly.
 stDev ()
 Calculates the standard deviation (unbiased) of the data points in the set Handles cummulative data sets correctly.
 varianceWithMean ($mean)
 Calculates the variance (unbiased) of the data points in the set given a fixed mean (average) value.
 stDevWithMean ($mean)
 Calculates the standard deviation (unbiased) of the data points in the set given a fixed mean (average) value.
 absDev ()
 Calculates the absolute deviation of the data points in the set Handles cummulative data sets correctly.
 absDevWithMean ($mean)
 Calculates the absolute deviation of the data points in the set given a fixed mean (average) value.
 skewness ()
 Calculates the skewness of the data distribution in the set The skewness measures the degree of asymmetry of a distribution, and is related to the third central moment of a distribution.
 kurtosis ()
 Calculates the kurtosis of the data distribution in the set The kurtosis measures the degrees of peakedness of a distribution.
 median ()
 Calculates the median of a data set.
 mode ()
 Calculates the mode of a data set.
 midrange ()
 Calculates the midrange of a data set.
 geometricMean ()
 Calculates the geometrical mean of the data points in the set Handles cummulative data sets correctly.
 harmonicMean ()
 Calculates the harmonic mean of the data points in the set Handles cummulative data sets correctly.
 sampleCentralMoment ($n)
 Calculates the nth central moment (m{n}) of a data set.
 sampleRawMoment ($n)
 Calculates the nth raw moment (m{n}) of a data set.
 coeffOfVariation ()
 Calculates the coefficient of variation of a data set.
 stdErrorOfMean ()
 Calculates the standard error of the mean.
 frequency ()
 Calculates the value frequency table of a data set.
 quartiles ()
 The quartiles are defined as the values that divide a sorted data set into four equal-sized subsets, and correspond to the 25th, 50th, and 75th percentiles.
 interquartileMean ()
 The interquartile mean is defined as the mean of the values left after discarding the lower 25% and top 25% ranked values, i.e.
 interquartileRange ()
 The interquartile range is the distance between the 75th and 25th percentiles.
 quartileDeviation ()
 The quartile deviation is half of the interquartile range value.
 quartileVariationCoefficient ()
 The quartile variation coefficient is defines as follows:
 quartileSkewnessCoefficient ()
 The quartile skewness coefficient (also known as Bowley Skewness), is defined as follows:
 percentile ($p)
 The pth percentile is the value such that p% of the a sorted data set is smaller than it, and (100 - p)% of the data is larger.
 __sumdiff ($power, $mean=null)
 Utility function to calculate: SUM { (xi - mean)^n }.
 __calcVariance ($mean=null)
 Utility function to calculate the variance with or without a fixed mean.
 __calcAbsoluteDeviation ($mean=null)
 Utility function to calculate the absolute deviation with or without a fixed mean.
 __sumabsdev ($mean=null)
 Utility function to calculate: SUM { | xi - mean | }.
 __format ($v, $useErrorObject=true)
 Utility function to format a PEAR_Error to be used by calc(), calcBasic() and calcFull()
 _validate ()
 Utility function to validate the data and modify it according to the current null handling option.

Data Fields

 $_data = null
 $_dataExpanded = null
 $_dataOption = null
 $_nullOption
 $_calculatedValues = array()

Detailed Description

Definition at line 119 of file Stats.php.

Member Function Documentation

Base::__calcAbsoluteDeviation (   $mean = null)

Utility function to calculate the absolute deviation with or without a fixed mean.

private

Parameters
$meanthe fixed mean to use, null as default
Returns
mixed a numeric value on success, a PEAR_Error otherwise
See Also
absDev()
absDevWithMean()

Definition at line 1488 of file Stats.php.

References __sumabsdev(), count(), PEAR\isError(), and PEAR\raiseError().

Referenced by absDev(), and absDevWithMean().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
$count = $this->count();
if (PEAR::isError($count)) {
return $count;
}
$sumabsdev = $this->__sumabsdev($mean);
if (PEAR::isError($sumabsdev)) {
return $sumabsdev;
}
return $sumabsdev / $count;
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::__calcVariance (   $mean = null)

Utility function to calculate the variance with or without a fixed mean.

private

Parameters
$meanthe fixed mean to use, null as default
Returns
mixed a numeric value on success, a PEAR_Error otherwise
See Also
variance()
varianceWithMean()

Definition at line 1460 of file Stats.php.

References __sumdiff(), count(), PEAR\isError(), and PEAR\raiseError().

Referenced by variance(), and varianceWithMean().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
$sumdiff2 = $this->__sumdiff(2, $mean);
if (PEAR::isError($sumdiff2)) {
return $sumdiff2;
}
$count = $this->count();
if (PEAR::isError($count)) {
return $count;
}
if ($count == 1) {
return PEAR::raiseError('cannot calculate variance of a singe data point');
}
return ($sumdiff2 / ($count - 1));
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::__format (   $v,
  $useErrorObject = true 
)

Utility function to format a PEAR_Error to be used by calc(), calcBasic() and calcFull()

private

Parameters
mixed$vvalue to be formatted
boolean$returnErrorObjectwhether the raw PEAR_Error (when true, default), or only the error message will be returned (when false)
Returns
mixed if the value is a PEAR_Error object, and $useErrorObject is false, then a string with the error message will be returned, otherwise the value will not be modified and returned as passed.

Definition at line 1545 of file Stats.php.

References PEAR\isError().

Referenced by calcBasic(), and calcFull().

{/*{{{*/
if (PEAR::isError($v) && $useErrorObject == false) {
return $v->getMessage();
} else {
return $v;
}
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::__sumabsdev (   $mean = null)

Utility function to calculate: SUM { | xi - mean | }.

private

Parameters
optionaldouble $mean the mean value for the set or population
Returns
mixed the sum on success, a PEAR_Error object otherwise
See Also
absDev()
absDevWithMean()

Definition at line 1513 of file Stats.php.

References mean(), PEAR\raiseError(), and STATS_DATA_CUMMULATIVE.

Referenced by __calcAbsoluteDeviation().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
if (is_null($mean)) {
$mean = $this->mean();
}
$sdev = 0;
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
foreach ($this->_data as $val=>$freq) {
$sdev += $freq * abs($val - $mean);
}
} else {
foreach ($this->_data as $val) {
$sdev += abs($val - $mean);
}
}
return $sdev;
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::__sumdiff (   $power,
  $mean = null 
)

Utility function to calculate: SUM { (xi - mean)^n }.

private

Parameters
numeric$powerthe exponent
optionaldouble $mean the data set mean value
Returns
mixed the sum on success, a PEAR_Error object otherwise
See Also
stDev()
variaceWithMean();
skewness();
kurtosis();

Definition at line 1428 of file Stats.php.

References PEAR\isError(), mean(), PEAR\raiseError(), and STATS_DATA_CUMMULATIVE.

Referenced by __calcVariance(), kurtosis(), sampleCentralMoment(), and skewness().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
if (is_null($mean)) {
$mean = $this->mean();
if (PEAR::isError($mean)) {
return $mean;
}
}
$sdiff = 0;
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
foreach ($this->_data as $val=>$freq) {
$sdiff += $freq * pow((double)($val - $mean), (double)$power);
}
} else {
foreach ($this->_data as $val)
$sdiff += pow((double)($val - $mean), (double)$power);
}
return $sdiff;
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::_validate ( )

Utility function to validate the data and modify it according to the current null handling option.

private

Returns
mixed true on success, a PEAR_Error object otherwise
See Also
setData()

Definition at line 1562 of file Stats.php.

References $d, $key, count(), PEAR\raiseError(), STATS_DATA_CUMMULATIVE, STATS_IGNORE_NULL, STATS_REJECT_NULL, and STATS_USE_NULL_AS_ZERO.

Referenced by setData().

{/*{{{*/
$flag = ($this->_dataOption == STATS_DATA_CUMMULATIVE);
foreach ($this->_data as $key=>$value) {
$d = ($flag) ? $key : $value;
$v = ($flag) ? $value : $key;
if (!is_numeric($d)) {
switch ($this->_nullOption) {
unset($this->_data["$key"]);
break;
if ($flag) {
unset($this->_data["$key"]);
$this->_data[0] += $v;
} else {
$this->_data[$key] = 0;
}
break;
default:
return PEAR::raiseError('data rejected, contains NULL values');
break;
}
}
}
if ($flag) {
ksort($this->_data);
$this->_dataExpanded = array();
foreach ($this->_data as $val=>$freq) {
$this->_dataExpanded = array_pad($this->_dataExpanded, count($this->_dataExpanded) + $freq, $val);
}
sort($this->_dataExpanded);
} else {
sort($this->_data);
}
return true;
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::absDev ( )

Calculates the absolute deviation of the data points in the set Handles cummulative data sets correctly.

public

Returns
mixed the absolute deviation on success, a PEAR_Error object otherwise
See Also
calc()
__sumabsdev()
count()
absDevWithMean()

Definition at line 750 of file Stats.php.

References __calcAbsoluteDeviation(), and PEAR\isError().

Referenced by calcFull().

{/*{{{*/
if (!array_key_exists('absDev', $this->_calculatedValues)) {
$absDev = $this->__calcAbsoluteDeviation();
if (PEAR::isError($absdev)) {
return $absdev;
}
$this->_calculatedValues['absDev'] = $absDev;
}
return $this->_calculatedValues['absDev'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::absDevWithMean (   $mean)

Calculates the absolute deviation of the data points in the set given a fixed mean (average) value.

Not used in calcBasic(), calcFull() or calc(). Handles cummulative data sets correctly

public

Parameters
numeric$meanthe fixed mean value
Returns
mixed the absolute deviation on success, a PEAR_Error object otherwise
See Also
__sumabsdev()
absDev()

Definition at line 773 of file Stats.php.

References __calcAbsoluteDeviation().

{/*{{{*/
return $this->__calcAbsoluteDeviation($mean);
}/*}}}*/

+ Here is the call graph for this function:

Base::calc (   $mode,
  $returnErrorObject = true 
)

Calculates the basic or full statistics for the data set.

public

Parameters
int$modeone of STATS_BASIC or STATS_FULL
boolean$returnErrorObjectwhether the raw PEAR_Error (when true, default), or only the error message will be returned (when false), if an error happens.
Returns
mixed an associative array of statistics on success, a PEAR_Error object otherwise
See Also
calcBasic()
calcFull()

Definition at line 326 of file Stats.php.

References calcBasic(), calcFull(), elseif(), PEAR\raiseError(), STATS_BASIC, and STATS_FULL.

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
if ($mode == STATS_BASIC) {
return $this->calcBasic($returnErrorObject);
} elseif ($mode == STATS_FULL) {
return $this->calcFull($returnErrorObject);
} else {
return PEAR::raiseError('incorrect mode, expected STATS_BASIC or STATS_FULL');
}
}/*}}}*/

+ Here is the call graph for this function:

Base::calcBasic (   $returnErrorObject = true)

Calculates a basic set of statistics.

public

Parameters
boolean$returnErrorObjectwhether the raw PEAR_Error (when true, default), or only the error message will be returned (when false), if an error happens.
Returns
mixed an associative array of statistics on success, a PEAR_Error object otherwise
See Also
calc()
calcFull()

Definition at line 349 of file Stats.php.

References __format(), count(), max(), mean(), min(), range(), stDev(), sum(), sum2(), and variance().

Referenced by calc().

{/*{{{*/
return array (
'min' => $this->__format($this->min(), $returnErrorObject),
'max' => $this->__format($this->max(), $returnErrorObject),
'sum' => $this->__format($this->sum(), $returnErrorObject),
'sum2' => $this->__format($this->sum2(), $returnErrorObject),
'count' => $this->__format($this->count(), $returnErrorObject),
'mean' => $this->__format($this->mean(), $returnErrorObject),
'stdev' => $this->__format($this->stDev(), $returnErrorObject),
'variance' => $this->__format($this->variance(), $returnErrorObject),
'range' => $this->__format($this->range(), $returnErrorObject)
);
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::calcFull (   $returnErrorObject = true)

Calculates a full set of statistics.

public

Parameters
boolean$returnErrorObjectwhether the raw PEAR_Error (when true, default), or only the error message will be returned (when false), if an error happens.
Returns
mixed an associative array of statistics on success, a PEAR_Error object otherwise
See Also
calc()
calcBasic()

Definition at line 373 of file Stats.php.

References __format(), absDev(), coeffOfVariation(), count(), frequency(), geometricMean(), harmonicMean(), interquartileMean(), interquartileRange(), kurtosis(), max(), mean(), median(), midrange(), min(), mode(), quartileDeviation(), quartiles(), quartileSkewnessCoefficient(), quartileVariationCoefficient(), range(), sampleCentralMoment(), sampleRawMoment(), skewness(), stdErrorOfMean(), stDev(), sum(), sum2(), and variance().

Referenced by calc().

{/*{{{*/
return array (
'min' => $this->__format($this->min(), $returnErrorObject),
'max' => $this->__format($this->max(), $returnErrorObject),
'sum' => $this->__format($this->sum(), $returnErrorObject),
'sum2' => $this->__format($this->sum2(), $returnErrorObject),
'count' => $this->__format($this->count(), $returnErrorObject),
'mean' => $this->__format($this->mean(), $returnErrorObject),
'median' => $this->__format($this->median(), $returnErrorObject),
'mode' => $this->__format($this->mode(), $returnErrorObject),
'midrange' => $this->__format($this->midrange(), $returnErrorObject),
'geometric_mean' => $this->__format($this->geometricMean(), $returnErrorObject),
'harmonic_mean' => $this->__format($this->harmonicMean(), $returnErrorObject),
'stdev' => $this->__format($this->stDev(), $returnErrorObject),
'absdev' => $this->__format($this->absDev(), $returnErrorObject),
'variance' => $this->__format($this->variance(), $returnErrorObject),
'range' => $this->__format($this->range(), $returnErrorObject),
'std_error_of_mean' => $this->__format($this->stdErrorOfMean(), $returnErrorObject),
'skewness' => $this->__format($this->skewness(), $returnErrorObject),
'kurtosis' => $this->__format($this->kurtosis(), $returnErrorObject),
'coeff_of_variation' => $this->__format($this->coeffOfVariation(), $returnErrorObject),
'sample_central_moments' => array (
1 => $this->__format($this->sampleCentralMoment(1), $returnErrorObject),
2 => $this->__format($this->sampleCentralMoment(2), $returnErrorObject),
3 => $this->__format($this->sampleCentralMoment(3), $returnErrorObject),
4 => $this->__format($this->sampleCentralMoment(4), $returnErrorObject),
5 => $this->__format($this->sampleCentralMoment(5), $returnErrorObject)
),
'sample_raw_moments' => array (
1 => $this->__format($this->sampleRawMoment(1), $returnErrorObject),
2 => $this->__format($this->sampleRawMoment(2), $returnErrorObject),
3 => $this->__format($this->sampleRawMoment(3), $returnErrorObject),
4 => $this->__format($this->sampleRawMoment(4), $returnErrorObject),
5 => $this->__format($this->sampleRawMoment(5), $returnErrorObject)
),
'frequency' => $this->__format($this->frequency(), $returnErrorObject),
'quartiles' => $this->__format($this->quartiles(), $returnErrorObject),
'interquartile_range' => $this->__format($this->interquartileRange(), $returnErrorObject),
'interquartile_mean' => $this->__format($this->interquartileMean(), $returnErrorObject),
'quartile_deviation' => $this->__format($this->quartileDeviation(), $returnErrorObject),
'quartile_variation_coefficient' => $this->__format($this->quartileVariationCoefficient(), $returnErrorObject),
'quartile_skewness_coefficient' => $this->__format($this->quartileSkewnessCoefficient(), $returnErrorObject)
);
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::center ( )

Transforms the data by substracting each entry from the mean.

This will reset all pre-calculated values to their original (unset) defaults.

public

Returns
mixed true on success, a PEAR_Error object otherwise
See Also
mean()
setData()

Definition at line 295 of file Stats.php.

References PEAR\isError(), mean(), setData(), and STATS_DATA_CUMMULATIVE.

{/*{{{*/
$mean = $this->mean();
if (PEAR::isError($mean)) {
return $mean;
}
$arr = array();
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
foreach ($this->_data as $val=>$freq) {
$newval = $val - $mean;
$arr["$newval"] = $freq;
}
} else {
foreach ($this->_data as $val) {
$newval = $val - $mean;
$arr[] = $newval;
}
}
return $this->setData($arr, $this->_dataOption);
}/*}}}*/

+ Here is the call graph for this function:

Base::coeffOfVariation ( )

Calculates the coefficient of variation of a data set.

The coefficient of variation measures the spread of a set of data as a proportion of its mean. It is often expressed as a percentage. Handles cummulative data sets correctly

public

Returns
mixed the coefficient of variation on success, a PEAR_Error object otherwise
See Also
stDev()
mean()
calc()

Definition at line 1109 of file Stats.php.

References PEAR\isError(), mean(), PEAR\raiseError(), and stDev().

Referenced by calcFull().

{/*{{{*/
if (!array_key_exists('coeffOfVariation', $this->_calculatedValues)) {
$mean = $this->mean();
if (PEAR::isError($mean)) {
return $mean;
}
if ($mean == 0.0) {
return PEAR::raiseError('cannot calculate the coefficient '.
'of variation, mean of sample is zero');
}
$stDev = $this->stDev();
if (PEAR::isError($stDev)) {
return $stDev;
}
$this->_calculatedValues['coeffOfVariation'] = $stDev / $mean;
}
return $this->_calculatedValues['coeffOfVariation'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::count ( )

Calculates the number of data points in the set Handles cummulative data sets correctly.

public

Returns
mixed the count on success, a PEAR_Error object otherwise
See Also
calc()

Definition at line 599 of file Stats.php.

References PEAR\raiseError(), and STATS_DATA_CUMMULATIVE.

Referenced by __calcAbsoluteDeviation(), __calcVariance(), _validate(), calcBasic(), calcFull(), geometricMean(), harmonicMean(), kurtosis(), mean(), median(), percentile(), sampleCentralMoment(), sampleRawMoment(), skewness(), and stdErrorOfMean().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
if (!array_key_exists('count', $this->_calculatedValues)) {
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
$count = count($this->_dataExpanded);
} else {
$count = count($this->_data);
}
$this->_calculatedValues['count'] = $count;
}
return $this->_calculatedValues['count'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::frequency ( )

Calculates the value frequency table of a data set.

Handles cummulative data sets correctly

public

Returns
mixed an associative array of value=>frequency items on success, a PEAR_Error object otherwise
See Also
min()
max()
calc()

Definition at line 1171 of file Stats.php.

References $_data, PEAR\raiseError(), and STATS_DATA_CUMMULATIVE.

Referenced by calcFull(), and mode().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
if (!array_key_exists('frequency', $this->_calculatedValues)) {
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
$freq = $this->_data;
} else {
$freq = array();
foreach ($this->_data as $val) {
$freq["$val"]++;
}
ksort($freq);
}
$this->_calculatedValues['frequency'] = $freq;
}
return $this->_calculatedValues['frequency'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::geometricMean ( )

Calculates the geometrical mean of the data points in the set Handles cummulative data sets correctly.

public

Returns
mixed the geometrical mean value on success, a PEAR_Error object otherwise
See Also
calc()
product()
count()

Definition at line 965 of file Stats.php.

References count(), PEAR\isError(), product(), and PEAR\raiseError().

Referenced by calcFull().

{/*{{{*/
if (!array_key_exists('geometricMean', $this->_calculatedValues)) {
$count = $this->count();
if (PEAR::isError($count)) {
return $count;
}
$prod = $this->product();
if (PEAR::isError($prod)) {
return $prod;
}
if ($prod == 0.0) {
return 0.0;
}
if ($prod < 0) {
return PEAR::raiseError('The product of the data set is negative, geometric mean undefined.');
}
$this->_calculatedValues['geometricMean'] = pow($prod , 1 / $count);
}
return $this->_calculatedValues['geometricMean'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::getData (   $expanded = false)

Returns the data which might have been modified according to the current null handling options.

public

Parameters
boolean$expandedwhether to return a expanded list, default is false
Returns
mixed array of data on success, a PEAR_Error object otherwise
See Also
_validate()

Definition at line 217 of file Stats.php.

References $_data, $_dataExpanded, PEAR\raiseError(), and STATS_DATA_CUMMULATIVE.

Referenced by interquartileMean().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
if ($this->_dataOption == STATS_DATA_CUMMULATIVE && $expanded) {
} else {
return $this->_data;
}
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::harmonicMean ( )

Calculates the harmonic mean of the data points in the set Handles cummulative data sets correctly.

public

Returns
mixed the harmonic mean value on success, a PEAR_Error object otherwise
See Also
calc()
count()

Definition at line 995 of file Stats.php.

References count(), PEAR\isError(), PEAR\raiseError(), and STATS_DATA_CUMMULATIVE.

Referenced by calcFull().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
if (!array_key_exists('harmonicMean', $this->_calculatedValues)) {
$count = $this->count();
if (PEAR::isError($count)) {
return $count;
}
$invsum = 0.0;
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
foreach($this->_data as $val=>$freq) {
if ($val == 0) {
return PEAR::raiseError('cannot calculate a '.
'harmonic mean with data values of zero.');
}
$invsum += $freq / $val;
}
} else {
foreach($this->_data as $val) {
if ($val == 0) {
return PEAR::raiseError('cannot calculate a '.
'harmonic mean with data values of zero.');
}
$invsum += 1 / $val;
}
}
$this->_calculatedValues['harmonicMean'] = $count / $invsum;
}
return $this->_calculatedValues['harmonicMean'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::interquartileMean ( )

The interquartile mean is defined as the mean of the values left after discarding the lower 25% and top 25% ranked values, i.e.

:

interquart mean = mean(<P(25),P(75)>)

where: P = percentile

Todo:
need to double check the equation public
Returns
mixed a numeric value on success, a PEAR_Error otherwise
See Also
quartiles()

Definition at line 1235 of file Stats.php.

References $n, getData(), PEAR\isError(), quartiles(), and PEAR\raiseError().

Referenced by calcFull().

{/*{{{*/
if (!array_key_exists('interquartileMean', $this->_calculatedValues)) {
$quart = $this->quartiles();
if (PEAR::isError($quart)) {
return $quart;
}
$q3 = $quart['75'];
$q1 = $quart['25'];
$sum = 0;
$n = 0;
foreach ($this->getData(true) as $val) {
if ($val >= $q1 && $val <= $q3) {
$sum += $val;
++$n;
}
}
if ($n == 0) {
return PEAR::raiseError('error calculating interquartile mean, '.
'empty interquartile range of values.');
}
$this->_calculatedValues['interquartileMean'] = $sum / $n;
}
return $this->_calculatedValues['interquartileMean'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::interquartileRange ( )

The interquartile range is the distance between the 75th and 25th percentiles.

Basically the range of the middle 50% of the data set, and thus is not affected by outliers or extreme values.

interquart range = P(75) - P(25)

where: P = percentile

public

Returns
mixed a numeric value on success, a PEAR_Error otherwise
See Also
quartiles()

Definition at line 1273 of file Stats.php.

References PEAR\isError(), and quartiles().

Referenced by calcFull(), and quartileDeviation().

{/*{{{*/
if (!array_key_exists('interquartileRange', $this->_calculatedValues)) {
$quart = $this->quartiles();
if (PEAR::isError($quart)) {
return $quart;
}
$q3 = $quart['75'];
$q1 = $quart['25'];
$this->_calculatedValues['interquartileRange'] = $q3 - $q1;
}
return $this->_calculatedValues['interquartileRange'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::kurtosis ( )

Calculates the kurtosis of the data distribution in the set The kurtosis measures the degrees of peakedness of a distribution.

It is also called the "excess" or "excess coefficient", and is a normalized form of the fourth central moment of a distribution. A normal distributions has kurtosis = 0 A narrow and peaked (leptokurtic) distribution has a kurtosis > 0 A flat and wide (platykurtic) distribution has a kurtosis < 0 Handles cummulative data sets correctly

public

Returns
mixed the kurtosis value on success, a PEAR_Error object otherwise
See Also
__sumdiff()
count()
stDev()
calc()

Definition at line 832 of file Stats.php.

References __sumdiff(), count(), PEAR\isError(), and stDev().

Referenced by calcFull().

{/*{{{*/
if (!array_key_exists('kurtosis', $this->_calculatedValues)) {
$count = $this->count();
if (PEAR::isError($count)) {
return $count;
}
$stDev = $this->stDev();
if (PEAR::isError($stDev)) {
return $stDev;
}
$sumdiff4 = $this->__sumdiff(4);
if (PEAR::isError($sumdiff4)) {
return $sumdiff4;
}
$this->_calculatedValues['kurtosis'] = ($sumdiff4 / ($count * pow($stDev, 4))) - 3;
}
return $this->_calculatedValues['kurtosis'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::Math_Stats (   $nullOption = STATS_REJECT_NULL)

Constructor for the class.

public

Parameters
optionalint $nullOption how to handle null values
Returns
object Math_Stats

Definition at line 176 of file Stats.php.

{/*{{{*/
$this->_nullOption = $nullOption;
}/*}}}*/
Base::max ( )

Calculates the maximum of a data set.

Handles cummulative data sets correctly

public

Returns
mixed the maximum value on success, a PEAR_Error object otherwise
See Also
calc()
min()

Definition at line 451 of file Stats.php.

References PEAR\raiseError(), and STATS_DATA_CUMMULATIVE.

Referenced by calcBasic(), calcFull(), midrange(), and range().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
if (!array_key_exists('max', $this->_calculatedValues)) {
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
$max = max(array_keys($this->_data));
} else {
$max = max($this->_data);
}
$this->_calculatedValues['max'] = $max;
}
return $this->_calculatedValues['max'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::mean ( )

Calculates the mean (average) of the data points in the set Handles cummulative data sets correctly.

public

Returns
mixed the mean value on success, a PEAR_Error object otherwise
See Also
calc()
sum()
count()

Definition at line 624 of file Stats.php.

References count(), PEAR\isError(), and sum().

Referenced by __sumabsdev(), __sumdiff(), calcBasic(), calcFull(), center(), coeffOfVariation(), and studentize().

{/*{{{*/
if (!array_key_exists('mean', $this->_calculatedValues)) {
$sum = $this->sum();
if (PEAR::isError($sum)) {
return $sum;
}
$count = $this->count();
if (PEAR::isError($count)) {
return $count;
}
$this->_calculatedValues['mean'] = $sum / $count;
}
return $this->_calculatedValues['mean'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::median ( )

Calculates the median of a data set.

The median is the value such that half of the points are below it in a sorted data set. If the number of values is odd, it is the middle item. If the number of values is even, is the average of the two middle items. Handles cummulative data sets correctly

public

Returns
mixed the median value on success, a PEAR_Error object otherwise
See Also
count()
calc()

Definition at line 864 of file Stats.php.

References $_data, $_dataExpanded, $n, count(), PEAR\isError(), PEAR\raiseError(), and STATS_DATA_CUMMULATIVE.

Referenced by calcFull().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
if (!array_key_exists('median', $this->_calculatedValues)) {
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
} else {
$arr =& $this->_data;
}
$n = $this->count();
if (PEAR::isError($n)) {
return $n;
}
$h = intval($n / 2);
if ($n % 2 == 0) {
$median = ($arr[$h] + $arr[$h - 1]) / 2;
} else {
$median = $arr[$h + 1];
}
$this->_calculatedValues['median'] = $median;
}
return $this->_calculatedValues['median'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::midrange ( )

Calculates the midrange of a data set.

The midrange is the average of the minimum and maximum of the data set. Handles cummulative data sets correctly

public

Returns
mixed the midrange value on success, a PEAR_Error object otherwise
See Also
min()
max()
calc()

Definition at line 940 of file Stats.php.

References PEAR\isError(), max(), and min().

Referenced by calcFull().

{/*{{{*/
if (!array_key_exists('midrange', $this->_calculatedValues)) {
$min = $this->min();
if (PEAR::isError($min)) {
return $min;
}
$max = $this->max();
if (PEAR::isError($max)) {
return $max;
}
$this->_calculatedValues['midrange'] = (($max + $min) / 2);
}
return $this->_calculatedValues['midrange'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::min ( )

Calculates the minimum of a data set.

Handles cummulative data sets correctly

public

Returns
mixed the minimum value on success, a PEAR_Error object otherwise
See Also
calc()
max()

Definition at line 427 of file Stats.php.

References PEAR\raiseError(), and STATS_DATA_CUMMULATIVE.

Referenced by calcBasic(), calcFull(), midrange(), and range().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
if (!array_key_exists('min', $this->_calculatedValues)) {
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
$min = min(array_keys($this->_data));
} else {
$min = min($this->_data);
}
$this->_calculatedValues['min'] = $min;
}
return $this->_calculatedValues['min'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::mode ( )

Calculates the mode of a data set.

The mode is the value with the highest frequency in the data set. There can be more than one mode. Handles cummulative data sets correctly

public

Returns
mixed an array of mode value on success, a PEAR_Error object otherwise
See Also
frequency()
calc()

Definition at line 900 of file Stats.php.

References $_data, frequency(), PEAR\raiseError(), and STATS_DATA_CUMMULATIVE.

Referenced by calcFull().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
if (!array_key_exists('mode', $this->_calculatedValues)) {
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
$arr = $this->_data;
} else {
$arr = $this->frequency();
}
arsort($arr);
$mcount = 1;
foreach ($arr as $val=>$freq) {
if ($mcount == 1) {
$mode = array($val);
$mfreq = $freq;
++$mcount;
continue;
}
if ($mfreq == $freq)
$mode[] = $val;
if ($mfreq > $freq)
break;
}
$this->_calculatedValues['mode'] = $mode;
}
return $this->_calculatedValues['mode'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::percentile (   $p)

The pth percentile is the value such that p% of the a sorted data set is smaller than it, and (100 - p)% of the data is larger.

A quick algorithm to pick the appropriate value from a sorted data set is as follows:

  • Count the number of values: n
  • Calculate the position of the value in the data list: i = p * (n + 1)
  • if i is an integer, return the data at that position
  • if i < 1, return the minimum of the data set
  • if i > n, return the maximum of the data set
  • otherwise, average the entries at adjacent positions to i

The median is the 50th percentile value.

Todo:
need to double check generality of the algorithm

public

Parameters
numeric$pthe percentile to estimate, e.g. 25 for 25th percentile
Returns
mixed a numeric value on success, a PEAR_Error otherwise
See Also
quartiles()
median()

Definition at line 1389 of file Stats.php.

References $_data, $_dataExpanded, $data, count(), elseif(), PEAR\isError(), and STATS_DATA_CUMMULATIVE.

Referenced by quartiles().

{/*{{{*/
$count = $this->count();
if (PEAR::isError($count)) {
return $count;
}
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
} else {
}
$obsidx = $p * ($count + 1) / 100;
if (intval($obsidx) == $obsidx) {
return $data[($obsidx - 1)];
} elseif ($obsidx < 1) {
return $data[0];
} elseif ($obsidx > $count) {
return $data[($count - 1)];
} else {
$left = floor($obsidx - 1);
$right = ceil($obsidx - 1);
return ($data[$left] + $data[$right]) / 2;
}
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::product ( )

Calculates PROD { (xi) }, (the product of all observations) Handles cummulative data sets correctly.

public

Returns
mixed the product on success, a PEAR_Error object otherwise
See Also
productN()

Definition at line 546 of file Stats.php.

References PEAR\isError(), and productN().

Referenced by geometricMean().

{/*{{{*/
if (!array_key_exists('product', $this->_calculatedValues)) {
$product = $this->productN(1);
if (PEAR::isError($product)) {
return $product;
} else {
$this->_calculatedValues['product'] = $product;
}
}
return $this->_calculatedValues['product'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::productN (   $n)

Calculates PROD { (xi)^n }, which is the product of all observations Handles cummulative data sets correctly.

public

Parameters
numeric$nthe exponent
Returns
mixed the product on success, a PEAR_Error object otherwise
See Also
product()

Definition at line 567 of file Stats.php.

References $n, PEAR\raiseError(), and STATS_DATA_CUMMULATIVE.

Referenced by product().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
$prodN = 1.0;
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
foreach($this->_data as $val=>$freq) {
if ($val == 0) {
return 0.0;
}
$prodN *= $freq * pow((double)$val, (double)$n);
}
} else {
foreach($this->_data as $val) {
if ($val == 0) {
return 0.0;
}
$prodN *= pow((double)$val, (double)$n);
}
}
return $prodN;
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::quartileDeviation ( )

The quartile deviation is half of the interquartile range value.

quart dev = (P(75) - P(25)) / 2

where: P = percentile

public

Returns
mixed a numeric value on success, a PEAR_Error otherwise
See Also
quartiles()
interquartileRange()

Definition at line 1298 of file Stats.php.

References interquartileRange(), and PEAR\isError().

Referenced by calcFull().

{/*{{{*/
if (!array_key_exists('quartileDeviation', $this->_calculatedValues)) {
$iqr = $this->interquartileRange();
if (PEAR::isError($iqr)) {
return $iqr;
}
$this->_calculatedValues['quartileDeviation'] = $iqr / 2;
}
return $this->_calculatedValues['quartileDeviation'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::quartiles ( )

The quartiles are defined as the values that divide a sorted data set into four equal-sized subsets, and correspond to the 25th, 50th, and 75th percentiles.

public

Returns
mixed an associative array of quartiles on success, a PEAR_Error otherwise
See Also
percentile()

Definition at line 1199 of file Stats.php.

References PEAR\isError(), and percentile().

Referenced by calcFull(), interquartileMean(), interquartileRange(), quartileSkewnessCoefficient(), and quartileVariationCoefficient().

{/*{{{*/
if (!array_key_exists('quartiles', $this->_calculatedValues)) {
$q1 = $this->percentile(25);
if (PEAR::isError($q1)) {
return $q1;
}
$q2 = $this->percentile(50);
if (PEAR::isError($q2)) {
return $q2;
}
$q3 = $this->percentile(75);
if (PEAR::isError($q3)) {
return $q3;
}
$this->_calculatedValues['quartiles'] = array (
'25' => $q1,
'50' => $q2,
'75' => $q3
);
}
return $this->_calculatedValues['quartiles'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::quartileSkewnessCoefficient ( )

The quartile skewness coefficient (also known as Bowley Skewness), is defined as follows:

quart skewness coeff = (P(25) - 2*P(50) + P(75)) / (P(75) - P(25))

where: P = percentile

Todo:
need to double check the equation public
Returns
mixed a numeric value on success, a PEAR_Error otherwise
See Also
quartiles()

Definition at line 1349 of file Stats.php.

References $d, PEAR\isError(), and quartiles().

Referenced by calcFull().

{/*{{{*/
if (!array_key_exists('quartileSkewnessCoefficient', $this->_calculatedValues)) {
$quart = $this->quartiles();
if (PEAR::isError($quart)) {
return $quart;
}
$q3 = $quart['75'];
$q2 = $quart['50'];
$q1 = $quart['25'];
$d = $q3 - 2*$q2 + $q1;
$s = $q3 - $q1;
$this->_calculatedValues['quartileSkewnessCoefficient'] = $d / $s;
}
return $this->_calculatedValues['quartileSkewnessCoefficient'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::quartileVariationCoefficient ( )

The quartile variation coefficient is defines as follows:

quart var coeff = 100 * (P(75) - P(25)) / (P(75) + P(25))

where: P = percentile

Todo:
need to double check the equation public
Returns
mixed a numeric value on success, a PEAR_Error otherwise
See Also
quartiles()

Definition at line 1321 of file Stats.php.

References $d, PEAR\isError(), and quartiles().

Referenced by calcFull().

{/*{{{*/
if (!array_key_exists('quartileVariationCoefficient', $this->_calculatedValues)) {
$quart = $this->quartiles();
if (PEAR::isError($quart)) {
return $quart;
}
$q3 = $quart['75'];
$q1 = $quart['25'];
$d = $q3 - $q1;
$s = $q3 + $q1;
$this->_calculatedValues['quartileVariationCoefficient'] = 100 * $d / $s;
}
return $this->_calculatedValues['quartileVariationCoefficient'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::range ( )

Calculates the range of the data set = max - min.

public

Returns
mixed the value of the range on success, a PEAR_Error object otherwise.

Definition at line 645 of file Stats.php.

References PEAR\isError(), max(), and min().

Referenced by calcBasic(), and calcFull().

{/*{{{*/
if (!array_key_exists('range', $this->_calculatedValues)) {
$min = $this->min();
if (PEAR::isError($min)) {
return $min;
}
$max = $this->max();
if (PEAR::isError($max)) {
return $max;
}
$this->_calculatedValues['range'] = $max - $min;
}
return $this->_calculatedValues['range'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::sampleCentralMoment (   $n)

Calculates the nth central moment (m{n}) of a data set.

The definition of a sample central moment is:

m{n} = 1/N * SUM { (xi - avg)^n }

where: N = sample size, avg = sample mean.

public

Parameters
integer$nmoment to calculate
Returns
mixed the numeric value of the moment on success, PEAR_Error otherwise

Definition at line 1040 of file Stats.php.

References $n, __sumdiff(), count(), PEAR\isError(), and PEAR\raiseError().

Referenced by calcFull().

{/*{{{*/
if (!is_int($n) || $n < 1) {
return PEAR::isError('moment must be a positive integer >= 1.');
}
if ($n == 1) {
return 0;
}
$count = $this->count();
if (PEAR::isError($count)) {
return $count;
}
if ($count == 0) {
return PEAR::raiseError("Cannot calculate {$n}th sample moment, ".
'there are zero data entries');
}
$sum = $this->__sumdiff($n);
if (PEAR::isError($sum)) {
return $sum;
}
return ($sum / $count);
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::sampleRawMoment (   $n)

Calculates the nth raw moment (m{n}) of a data set.

The definition of a sample central moment is:

m{n} = 1/N * SUM { xi^n }

where: N = sample size, avg = sample mean.

public

Parameters
integer$nmoment to calculate
Returns
mixed the numeric value of the moment on success, PEAR_Error otherwise

Definition at line 1076 of file Stats.php.

References $n, count(), PEAR\isError(), PEAR\raiseError(), and sumN().

Referenced by calcFull().

{/*{{{*/
if (!is_int($n) || $n < 1) {
return PEAR::isError('moment must be a positive integer >= 1.');
}
$count = $this->count();
if (PEAR::isError($count)) {
return $count;
}
if ($count == 0) {
return PEAR::raiseError("Cannot calculate {$n}th raw moment, ".
'there are zero data entries.');
}
$sum = $this->sumN($n);
if (PEAR::isError($sum)) {
return $sum;
}
return ($sum / $count);
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::setData (   $arr,
  $opt = STATS_DATA_SIMPLE 
)

Sets and verifies the data, checking for nulls and using the current null handling option.

public

Parameters
array$arrthe data set
optionalint $opt data format: STATS_DATA_CUMMULATIVE or STATS_DATA_SIMPLE (default)
Returns
mixed true on success, a PEAR_Error object otherwise

Definition at line 189 of file Stats.php.

References _validate(), PEAR\raiseError(), STATS_DATA_CUMMULATIVE, and STATS_DATA_SIMPLE.

Referenced by center(), and studentize().

{/*{{{*/
if (!is_array($arr)) {
return PEAR::raiseError('invalid data, an array of numeric data was expected');
}
$this->_data = null;
$this->_dataExpanded = null;
$this->_dataOption = null;
$this->_calculatedValues = array();
if ($opt == STATS_DATA_SIMPLE) {
$this->_dataOption = $opt;
$this->_data = array_values($arr);
} else if ($opt == STATS_DATA_CUMMULATIVE) {
$this->_dataOption = $opt;
$this->_data = $arr;
$this->_dataExpanded = array();
}
return $this->_validate();
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::setNullOption (   $nullOption)

Sets the null handling option.

Must be called before assigning a new data set containing null values

public

Returns
mixed true on success, a PEAR_Error object otherwise
See Also
_validate()

Definition at line 236 of file Stats.php.

References PEAR\raiseError(), STATS_IGNORE_NULL, STATS_REJECT_NULL, and STATS_USE_NULL_AS_ZERO.

{/*{{{*/
if ($nullOption == STATS_REJECT_NULL
|| $nullOption == STATS_IGNORE_NULL
|| $nullOption == STATS_USE_NULL_AS_ZERO) {
$this->_nullOption = $nullOption;
return true;
} else {
return PEAR::raiseError('invalid null handling option expecting: '.
'STATS_REJECT_NULL, STATS_IGNORE_NULL or STATS_USE_NULL_AS_ZERO');
}
}/*}}}*/

+ Here is the call graph for this function:

Base::skewness ( )

Calculates the skewness of the data distribution in the set The skewness measures the degree of asymmetry of a distribution, and is related to the third central moment of a distribution.

A normal distribution has a skewness = 0 A distribution with a tail off towards the high end of the scale (positive skew) has a skewness > 0 A distribution with a tail off towards the low end of the scale (negative skew) has a skewness < 0 Handles cummulative data sets correctly

public

Returns
mixed the skewness value on success, a PEAR_Error object otherwise
See Also
__sumdiff()
count()
stDev()
calc()

Definition at line 795 of file Stats.php.

References __sumdiff(), count(), PEAR\isError(), and stDev().

Referenced by calcFull().

{/*{{{*/
if (!array_key_exists('skewness', $this->_calculatedValues)) {
$count = $this->count();
if (PEAR::isError($count)) {
return $count;
}
$stDev = $this->stDev();
if (PEAR::isError($stDev)) {
return $stDev;
}
$sumdiff3 = $this->__sumdiff(3);
if (PEAR::isError($sumdiff3)) {
return $sumdiff3;
}
$this->_calculatedValues['skewness'] = ($sumdiff3 / ($count * pow($stDev, 3)));
}
return $this->_calculatedValues['skewness'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::stdErrorOfMean ( )

Calculates the standard error of the mean.

It is the standard deviation of the sampling distribution of the mean. The formula is:

S.E. Mean = SD / (N)^(1/2)

This formula does not assume a normal distribution, and shows that the size of the standard error of the mean is inversely proportional to the square root of the sample size.

public

Returns
mixed the standard error of the mean on success, a PEAR_Error object otherwise
See Also
stDev()
count()
calc()

Definition at line 1146 of file Stats.php.

References count(), PEAR\isError(), and stDev().

Referenced by calcFull().

{/*{{{*/
if (!array_key_exists('stdErrorOfMean', $this->_calculatedValues)) {
$count = $this->count();
if (PEAR::isError($count)) {
return $count;
}
$stDev = $this->stDev();
if (PEAR::isError($stDev)) {
return $stDev;
}
$this->_calculatedValues['stdErrorOfMean'] = $stDev / sqrt($count);
}
return $this->_calculatedValues['stdErrorOfMean'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::stDev ( )

Calculates the standard deviation (unbiased) of the data points in the set Handles cummulative data sets correctly.

public

Returns
mixed the standard deviation on success, a PEAR_Error object otherwise
See Also
calc()
variance()

Definition at line 691 of file Stats.php.

References PEAR\isError(), and variance().

Referenced by calcBasic(), calcFull(), coeffOfVariation(), kurtosis(), skewness(), stdErrorOfMean(), and studentize().

{/*{{{*/
if (!array_key_exists('stDev', $this->_calculatedValues)) {
$variance = $this->variance();
if (PEAR::isError($variance)) {
return $variance;
}
$this->_calculatedValues['stDev'] = sqrt($variance);
}
return $this->_calculatedValues['stDev'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::stDevWithMean (   $mean)

Calculates the standard deviation (unbiased) of the data points in the set given a fixed mean (average) value.

Not used in calcBasic(), calcFull() or calc(). Handles cummulative data sets correctly

public

Parameters
numeric$meanthe fixed mean value
Returns
mixed the standard deviation on success, a PEAR_Error object otherwise
See Also
varianceWithMean()
stDev()

Definition at line 731 of file Stats.php.

References PEAR\isError(), and varianceWithMean().

{/*{{{*/
$varianceWM = $this->varianceWithMean($mean);
if (PEAR::isError($varianceWM)) {
return $varianceWM;
}
return sqrt($varianceWM);
}/*}}}*/

+ Here is the call graph for this function:

Base::studentize ( )

Transforms the data by substracting each entry from the mean and dividing by its standard deviation.

This will reset all pre-calculated values to their original (unset) defaults.

public

Returns
mixed true on success, a PEAR_Error object otherwise
See Also
mean()
stDev()
setData()

Definition at line 259 of file Stats.php.

References PEAR\isError(), mean(), PEAR\raiseError(), setData(), STATS_DATA_CUMMULATIVE, and stDev().

{/*{{{*/
$mean = $this->mean();
if (PEAR::isError($mean)) {
return $mean;
}
$std = $this->stDev();
if (PEAR::isError($std)) {
return $std;
}
if ($std == 0) {
return PEAR::raiseError('cannot studentize data, standard deviation is zero.');
}
$arr = array();
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
foreach ($this->_data as $val=>$freq) {
$newval = ($val - $mean) / $std;
$arr["$newval"] = $freq;
}
} else {
foreach ($this->_data as $val) {
$newval = ($val - $mean) / $std;
$arr[] = $newval;
}
}
return $this->setData($arr, $this->_dataOption);
}/*}}}*/

+ Here is the call graph for this function:

Base::sum ( )

Calculates SUM { xi } Handles cummulative data sets correctly.

public

Returns
mixed the sum on success, a PEAR_Error object otherwise
See Also
calc()
sum2()
sumN()

Definition at line 476 of file Stats.php.

References PEAR\isError(), and sumN().

Referenced by calcBasic(), calcFull(), and mean().

{/*{{{*/
if (!array_key_exists('sum', $this->_calculatedValues)) {
$sum = $this->sumN(1);
if (PEAR::isError($sum)) {
return $sum;
} else {
$this->_calculatedValues['sum'] = $sum;
}
}
return $this->_calculatedValues['sum'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::sum2 ( )

Calculates SUM { (xi)^2 } Handles cummulative data sets correctly.

public

Returns
mixed the sum on success, a PEAR_Error object otherwise
See Also
calc()
sum()
sumN()

Definition at line 498 of file Stats.php.

References PEAR\isError(), and sumN().

Referenced by calcBasic(), and calcFull().

{/*{{{*/
if (!array_key_exists('sum2', $this->_calculatedValues)) {
$sum2 = $this->sumN(2);
if (PEAR::isError($sum2)) {
return $sum2;
} else {
$this->_calculatedValues['sum2'] = $sum2;
}
}
return $this->_calculatedValues['sum2'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::sumN (   $n)

Calculates SUM { (xi)^n } Handles cummulative data sets correctly.

public

Parameters
numeric$nthe exponent
Returns
mixed the sum on success, a PEAR_Error object otherwise
See Also
calc()
sum()
sum2()

Definition at line 521 of file Stats.php.

References $n, PEAR\raiseError(), and STATS_DATA_CUMMULATIVE.

Referenced by sampleRawMoment(), sum(), and sum2().

{/*{{{*/
if ($this->_data == null) {
return PEAR::raiseError('data has not been set');
}
$sumN = 0;
if ($this->_dataOption == STATS_DATA_CUMMULATIVE) {
foreach($this->_data as $val=>$freq) {
$sumN += $freq * pow((double)$val, (double)$n);
}
} else {
foreach($this->_data as $val) {
$sumN += pow((double)$val, (double)$n);
}
}
return $sumN;
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::variance ( )

Calculates the variance (unbiased) of the data points in the set Handles cummulative data sets correctly.

public

Returns
mixed the variance value on success, a PEAR_Error object otherwise
See Also
calc()
__sumdiff()
count()

Definition at line 671 of file Stats.php.

References __calcVariance(), and PEAR\isError().

Referenced by calcBasic(), calcFull(), and stDev().

{/*{{{*/
if (!array_key_exists('variance', $this->_calculatedValues)) {
$variance = $this->__calcVariance();
if (PEAR::isError($variance)) {
return $variance;
}
$this->_calculatedValues['variance'] = $variance;
}
return $this->_calculatedValues['variance'];
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Base::varianceWithMean (   $mean)

Calculates the variance (unbiased) of the data points in the set given a fixed mean (average) value.

Not used in calcBasic(), calcFull() or calc(). Handles cummulative data sets correctly

public

Parameters
numeric$meanthe fixed mean value
Returns
mixed the variance on success, a PEAR_Error object otherwise
See Also
__sumdiff()
count()
variance()

Definition at line 715 of file Stats.php.

References __calcVariance().

Referenced by stDevWithMean().

{/*{{{*/
return $this->__calcVariance($mean);
}/*}}}*/

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

Base::$_calculatedValues = array()

Definition at line 165 of file Stats.php.

Base::$_data = null

Definition at line 129 of file Stats.php.

Referenced by frequency(), getData(), median(), mode(), and percentile().

Base::$_dataExpanded = null

Definition at line 138 of file Stats.php.

Referenced by getData(), median(), and percentile().

Base::$_dataOption = null

Definition at line 147 of file Stats.php.

Base::$_nullOption

Definition at line 156 of file Stats.php.


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