Math_Stats
[ class tree: Math_Stats ] [ index: Math_Stats ] [ all elements ]

Class: Math_Stats

Source Location: Program_Root/class/stats.class.php

Class Overview


A class to calculate descriptive statistics from a data set.


Author(s):

Version:

  • 0.8

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 118]
A class to calculate descriptive statistics from a data set.

Data sets can be simple arrays of data, or a cummulative hash. The second form is useful when passing large data set, for example the data set:

$data1 = array (1,2,1,1,1,1,3,3,4.1,3,2,2,4.1,1,1,2,3,3,2,2,1,1,2,2);

can be epxressed more compactly as:

$data2 = array("1"=>9, "2"=>8, "3"=>5, "4.1"=>2);

Example of use:

include_once "Math/Stats.php";
$s = new Math_Stats();
$s->setData($data1);
// or
// $s->setData($data2, STATS_DATA_CUMMULATIVE);
$stats = $s->calcBasic();
echo "Mean: ".$stats["mean"]." StDev: ".$stats["stdev"]." 
\n"; // using data with nulls // first ignoring them: $data3 = array(1.2, "foo", 2.4, 3.1, 4.2, 3.2, null, 5.1, 6.2); $s->setNullOption(STATS_IGNORE_NULL); $s->setData($data3); $stats3 = $s->calcFull(); // and then assuming nulls == 0 $s->setNullOption(STATS_USE_NULL_AS_ZERO); $s->setData($data3); $stats3 = $s->calcFull();

Originally this class was part of NumPHP (Numeric PHP package)




Tags:

access:  public
version:  0.8
author:  Jesus M. Castagnetto <jmcastagnetto@php.net>


[ Top ]


Class Variables

$_data = null

[line 128]

The simple or cummulative data set.

Null by default.




Tags:

access:  private

Type:   array


[ Top ]

$_dataOption = null

[line 137]

Flag for data type, one of STATS_DATA_SIMPLE or STATS_DATA_CUMMULATIVE.

Null by default.




Tags:

access:  private

Type:   int


[ Top ]

$_nullOption =

[line 146]

Flag for null handling options.

One of STATS_REJECT_NULL, STATS_IGNORE_NULL or STATS_USE_NULL_AS_ZERO




Tags:

access:  private

Type:   int


[ Top ]



Class Methods


constructor Math_Stats [line 157]

Math_Stats Math_Stats( [optional $nullOption = STATS_REJECT_NULL])

Constructor for the class



Tags:

access:  public


Parameters:

optional   $nullOption   int how to handle null values

[ Top ]

method absDev [line 502]

mixed absDev( )

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



Tags:

return:  the absolute deviation on success, a PEAR_Error object otherwise
see:  Math_Stats::absDevWithMean()
see:  Math_Stats::count()
see:  Math_Stats::__sumabsdev()
see:  Math_Stats::calc()
access:  public


[ Top ]

method absDevWithMean [line 520]

mixed absDevWithMean( numeric $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




Tags:

return:  the absolute deviation on success, a PEAR_Error object otherwise
see:  Math_Stats::absDev()
see:  Math_Stats::__sumabsdev()
access:  public


Parameters:

numeric   $mean   the fixed mean value

[ Top ]

method calc [line 228]

mixed calc( int $mode)

Calculates the basic or full statistics for the data set



Tags:

return:  an associative array of statistics on success, a PEAR_Error object otherwise
see:  Math_Stats::calcFull()
see:  Math_Stats::calcBasic()
access:  public


Parameters:

int   $mode   one of STATS_BASIC or STATS_FULL

[ Top ]

method calcBasic [line 274]

mixed calcBasic( )

Calculates a basic set of statistics



Tags:

return:  an associative array of statistics on success, a PEAR_Error object otherwise
see:  Math_Stats::calcFull()
see:  Math_Stats::calc()
access:  public


[ Top ]

method calcFull [line 286]

mixed calcFull( )

Calculates a full set of statistics



Tags:

return:  an associative array of statistics on success, a PEAR_Error object otherwise
see:  Math_Stats::calcBasic()
see:  Math_Stats::calc()
access:  public


[ Top ]

method coeffOfVariation [line 687]

mixed 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




Tags:

return:  the coefficient of variation on success, a PEAR_Error object otherwise
see:  Math_Stats::calc()
see:  Math_Stats::mean()
see:  Math_Stats::stDev()
access:  public


[ Top ]

method count [line 391]

mixed count( )

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



Tags:

return:  the count on success, a PEAR_Error object otherwise
see:  Math_Stats::calc()
access:  public


[ Top ]

method frequency [line 662]

mixed frequency( )

Calculates the value frequency table of a data set.

Handles cummulative data sets correctly




Tags:

return:  an associative array of value=>frequency items on success, a PEAR_Error object otherwise
see:  Math_Stats::calc()
see:  Math_Stats::max()
see:  Math_Stats::min()
access:  public


[ Top ]

method getData [line 193]

mixed getData( )

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



Tags:

return:  array of data on success, a PEAR_Error object otherwise
see:  Math_Stats::_validate()
access:  public


[ Top ]

method kurtosis [line 560]

mixed kurtosis( )

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

It is also callesd the "excess" or "excess coefficient", and is a normalized form of the fourth central moment of a distribution. Handles cummulative data sets correctly




Tags:

return:  the kurtosis value on success, a PEAR_Error object otherwise
see:  Math_Stats::calc()
see:  Math_Stats::stDev()
see:  Math_Stats::count()
see:  Math_Stats::__sumdiff()
access:  public


[ Top ]

method max [line 317]

mixed max( )

Calculates the maximum of a data set.

Handles cummulative data sets correctly




Tags:

return:  the maximum value on success, a PEAR_Error object otherwise
see:  Math_Stats::min()
see:  Math_Stats::calc()
access:  public


[ Top ]

method mean [line 413]

mixed mean( )

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



Tags:

return:  the mean value on success, a PEAR_Error object otherwise
see:  Math_Stats::count()
see:  Math_Stats::sum()
see:  Math_Stats::calc()
access:  public


[ Top ]

method median [line 580]

mixed 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




Tags:

return:  the median value on success, a PEAR_Error object otherwise
see:  Math_Stats::calc()
see:  Math_Stats::count()
access:  public


[ Top ]

method midrange [line 646]

mixed 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




Tags:

return:  the midrange value on success, a PEAR_Error object otherwise
see:  Math_Stats::calc()
see:  Math_Stats::max()
see:  Math_Stats::min()
access:  public


[ Top ]

method min [line 299]

mixed min( )

Calculates the minimum of a data set.

Handles cummulative data sets correctly




Tags:

return:  the minimum value on success, a PEAR_Error object otherwise
see:  Math_Stats::max()
see:  Math_Stats::calc()
access:  public


[ Top ]

method mode [line 611]

mixed 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




Tags:

return:  an array of mode value on success, a PEAR_Error object otherwise
see:  Math_Stats::calc()
see:  Math_Stats::frequency()
access:  public


[ Top ]

method setData [line 170]

mixed setData( array $arr, [optional $opt = STATS_DATA_SIMPLE])

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



Tags:

return:  true on success, a PEAR_Error object otherwise
access:  public


Parameters:

array   $arr   the data set
optional   $opt   int data format: STATS_DATA_CUMMULATIVE or STATS_DATA_SIMPLE (default)

[ Top ]

method setNullOption [line 207]

mixed setNullOption( mixed $nullOption)

Sets the null handling option.

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




Tags:

return:  true on success, a PEAR_Error object otherwise
see:  Math_Stats::_validate()
access:  public


[ Top ]

method skewness [line 539]

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

Handles cummulative data sets correctly




Tags:

return:  the skewness value on success, a PEAR_Error object otherwise
see:  Math_Stats::calc()
see:  Math_Stats::stDev()
see:  Math_Stats::count()
see:  Math_Stats::__sumdiff()
access:  public


[ Top ]

method stDev [line 448]

mixed stDev( )

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



Tags:

return:  the standard deviation on success, a PEAR_Error object otherwise
see:  Math_Stats::variance()
see:  Math_Stats::calc()
access:  public


[ Top ]

method stDevWithMean [line 485]

mixed stDevWithMean( numeric $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




Tags:

return:  the standard deviation on success, a PEAR_Error object otherwise
see:  Math_Stats::stDev()
see:  Math_Stats::varianceWithMean()
access:  public


Parameters:

numeric   $mean   the fixed mean value

[ Top ]

method sum [line 336]

mixed sum( )

Calculates SUM { xi } Handles cummulative data sets correctly



Tags:

return:  the sum on success, a PEAR_Error object otherwise
see:  Math_Stats::sumN()
see:  Math_Stats::sum2()
see:  Math_Stats::calc()
access:  public


[ Top ]

method sum2 [line 350]

mixed sum2( )

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



Tags:

return:  the sum on success, a PEAR_Error object otherwise
see:  Math_Stats::sumN()
see:  Math_Stats::sum()
see:  Math_Stats::calc()
access:  public


[ Top ]

method sumN [line 365]

mixed sumN( numeric $n)

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



Tags:

return:  the sum on success, a PEAR_Error object otherwise
see:  Math_Stats::sum2()
see:  Math_Stats::sum()
see:  Math_Stats::calc()
access:  public


Parameters:

numeric   $n   the exponent

[ Top ]

method variance [line 429]

mixed variance( )

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



Tags:

return:  the variance value on success, a PEAR_Error object otherwise
see:  Math_Stats::count()
see:  Math_Stats::__sumdiff()
see:  Math_Stats::calc()
access:  public


[ Top ]

method varianceWithMean [line 467]

mixed varianceWithMean( numeric $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




Tags:

return:  the variance on success, a PEAR_Error object otherwise
see:  Math_Stats::variance()
see:  Math_Stats::count()
see:  Math_Stats::__sumdiff()
access:  public


Parameters:

numeric   $mean   the fixed mean value

[ Top ]

method _validate [line 757]

mixed _validate( )

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



Tags:

return:  true on success, a PEAR_Error object otherwise
see:  Math_Stats::setData()
access:  private


[ Top ]

method __sumabsdev [line 732]

mixed __sumabsdev( [optional $mean = null])

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



Tags:

return:  

the sum on success, a PEAR_Error object otherwise

see:  Math_Stats::absDevWithMean()
see:  Math_Stats::absDev()
access:  private


Parameters:

optional   $mean   float the mean value for the set or population

[ Top ]

method __sumdiff [line 706]

mixed __sumdiff( numeric $power, [optional $mean = null])

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



Tags:

return:  

the sum on success, a PEAR_Error object otherwise

see:  kurtosis();
see:  skewness();
see:  variaceWithMean();
see:  Math_Stats::stDev()
access:  private


Parameters:

numeric   $power   the exponent
optional   $mean   float the data set mean value

[ Top ]


Documentation generated on Tue, 15 Jul 2003 10:19:51 +0200 by phpDocumentor 1.2.1