| @@ 608-626 (lines=19) @@ | ||
| 605 | * @see sum() |
|
| 606 | * @see count() |
|
| 607 | */ |
|
| 608 | public function mean() |
|
| 609 | { |
|
| 610 | if (!array_key_exists('mean', $this->_calculatedValues)) { |
|
| 611 | try { |
|
| 612 | $sum = $this->sum(); |
|
| 613 | try { |
|
| 614 | $count = $this->count(); |
|
| 615 | } catch (\PEAR_Exception $e) { |
|
| 616 | return $count; |
|
| 617 | } |
|
| 618 | $this->_calculatedValues['mean'] = $sum / $count; |
|
| 619 | } catch (\PEAR_Exception $e) { |
|
| 620 | return $sum; |
|
| 621 | } |
|
| 622 | } |
|
| 623 | return $this->_calculatedValues['mean']; |
|
| 624 | } |
|
| 625 | ||
| 626 | /** |
|
| 627 | * Calculates the range of the data set = max - min |
|
| 628 | * |
|
| 629 | * @access public |
|
| @@ 632-652 (lines=21) @@ | ||
| 629 | * @access public |
|
| 630 | * @return mixed the value of the range on success, a PEAR_Error object otherwise. |
|
| 631 | */ |
|
| 632 | public function range() |
|
| 633 | { |
|
| 634 | if (!array_key_exists('range', $this->_calculatedValues)) { |
|
| 635 | try { |
|
| 636 | $min = $this->min(); |
|
| 637 | try { |
|
| 638 | $max = $this->max(); |
|
| 639 | } catch (\PEAR_Exception $e) { |
|
| 640 | return $max; |
|
| 641 | } |
|
| 642 | $this->_calculatedValues['range'] = $max - $min; |
|
| 643 | } catch (\PEAR_Exception $e) { |
|
| 644 | return $min; |
|
| 645 | } |
|
| 646 | } |
|
| 647 | return $this->_calculatedValues['range']; |
|
| 648 | } |
|
| 649 | ||
| 650 | /** |
|
| 651 | * Calculates the variance (unbiased) of the data points in the set |
|
| 652 | * Handles cummulative data sets correctly |
|
| 653 | * |
|
| 654 | * @access public |
|
| 655 | * @return mixed the variance value on success, a PEAR_Error object otherwise |
|
| @@ 960-978 (lines=19) @@ | ||
| 957 | * @see max() |
|
| 958 | * @see calc() |
|
| 959 | */ |
|
| 960 | public function midrange() |
|
| 961 | { |
|
| 962 | if (!array_key_exists('midrange', $this->_calculatedValues)) { |
|
| 963 | try { |
|
| 964 | $min = $this->min(); |
|
| 965 | try { |
|
| 966 | $max = $this->max(); |
|
| 967 | } catch (\PEAR_Exception $e) { |
|
| 968 | return $max; |
|
| 969 | } |
|
| 970 | } catch (\PEAR_Exception $e) { |
|
| 971 | return $min; |
|
| 972 | } |
|
| 973 | ||
| 974 | $this->_calculatedValues['midrange'] = (($max + $min) / 2); |
|
| 975 | } |
|
| 976 | return $this->_calculatedValues['midrange']; |
|
| 977 | } |
|
| 978 | ||
| 979 | /** |
|
| 980 | * Calculates the geometrical mean of the data points in the set |
|
| 981 | * Handles cummulative data sets correctly |
|
| @@ 1192-1209 (lines=18) @@ | ||
| 1189 | * @see count() |
|
| 1190 | * @see calc() |
|
| 1191 | */ |
|
| 1192 | public function stdErrorOfMean() |
|
| 1193 | { |
|
| 1194 | if (!array_key_exists('stdErrorOfMean', $this->_calculatedValues)) { |
|
| 1195 | try { |
|
| 1196 | $count = $this->count(); |
|
| 1197 | } catch (\PEAR_Exception $e) { |
|
| 1198 | return $count; |
|
| 1199 | } |
|
| 1200 | try { |
|
| 1201 | $stDev = $this->stDev(); |
|
| 1202 | } catch (\PEAR_Exception $e) { |
|
| 1203 | return $stDev; |
|
| 1204 | } |
|
| 1205 | $this->_calculatedValues['stdErrorOfMean'] = $stDev / sqrt($count); |
|
| 1206 | } |
|
| 1207 | return $this->_calculatedValues['stdErrorOfMean']; |
|
| 1208 | } |
|
| 1209 | ||
| 1210 | /** |
|
| 1211 | * Calculates the value frequency table of a data set. |
|
| 1212 | * Handles cummulative data sets correctly |
|