| @@ 428-441 (lines=14) @@ | ||
| 425 | * @see sum2() |
|
| 426 | * @see sumN() |
|
| 427 | */ |
|
| 428 | public function sum() |
|
| 429 | { |
|
| 430 | if (!array_key_exists('sum', $this->_calculatedValues)) { |
|
| 431 | try { |
|
| 432 | $sum = $this->sumN(1); |
|
| 433 | $this->_calculatedValues['sum'] = $sum; |
|
| 434 | } catch (\PEAR_Exception $e) { |
|
| 435 | return $sum; |
|
| 436 | } |
|
| 437 | } |
|
| 438 | return $this->_calculatedValues['sum']; |
|
| 439 | } |
|
| 440 | ||
| 441 | /** |
|
| 442 | * Calculates SUM { (xi)^2 } |
|
| 443 | * Handles cummulative data sets correctly |
|
| 444 | * |
|
| @@ 451-463 (lines=13) @@ | ||
| 448 | * @see sum() |
|
| 449 | * @see sumN() |
|
| 450 | */ |
|
| 451 | public function sum2() |
|
| 452 | { |
|
| 453 | if (!array_key_exists('sum2', $this->_calculatedValues)) { |
|
| 454 | try { |
|
| 455 | $sum2 = $this->sumN(2); |
|
| 456 | $this->_calculatedValues['sum2'] = $sum2; |
|
| 457 | } catch (\PEAR_Exception $e) { |
|
| 458 | return $sum2; |
|
| 459 | } |
|
| 460 | } |
|
| 461 | return $this->_calculatedValues['sum2']; |
|
| 462 | } |
|
| 463 | ||
| 464 | /** |
|
| 465 | * Calculates SUM { (xi)^n } |
|
| 466 | * Handles cummulative data sets correctly |
|
| @@ 503-516 (lines=14) @@ | ||
| 500 | * a PEAR_Error object otherwise |
|
| 501 | * @see productN() |
|
| 502 | */ |
|
| 503 | public function product() |
|
| 504 | { |
|
| 505 | if (!array_key_exists('product', $this->_calculatedValues)) { |
|
| 506 | try { |
|
| 507 | $product = $this->productN(1); |
|
| 508 | $this->_calculatedValues['product'] = $product; |
|
| 509 | } catch (\PEAR_Exception $e) { |
|
| 510 | return $product; |
|
| 511 | } |
|
| 512 | } |
|
| 513 | return $this->_calculatedValues['product']; |
|
| 514 | } |
|
| 515 | ||
| 516 | /** |
|
| 517 | * Calculates PROD { (xi)^n }, which is the product of all observations |
|
| 518 | * Handles cummulative data sets correctly |
|
| 519 | * |
|
| @@ 660-673 (lines=14) @@ | ||
| 657 | * @see __sumdiff() |
|
| 658 | * @see count() |
|
| 659 | */ |
|
| 660 | public function variance() |
|
| 661 | { |
|
| 662 | if (!array_key_exists('variance', $this->_calculatedValues)) { |
|
| 663 | try { |
|
| 664 | $variance = $this->__calcVariance(); |
|
| 665 | } catch (\PEAR_Exception $e) { |
|
| 666 | return $variance; |
|
| 667 | } |
|
| 668 | ||
| 669 | $this->_calculatedValues['variance'] = $variance; |
|
| 670 | } |
|
| 671 | return $this->_calculatedValues['variance']; |
|
| 672 | } |
|
| 673 | ||
| 674 | /** |
|
| 675 | * Calculates the standard deviation (unbiased) of the data points in the set |
|
| 676 | * Handles cummulative data sets correctly |
|
| @@ 683-696 (lines=14) @@ | ||
| 680 | * @see calc() |
|
| 681 | * @see variance() |
|
| 682 | */ |
|
| 683 | public function stDev() |
|
| 684 | { |
|
| 685 | if (!array_key_exists('stDev', $this->_calculatedValues)) { |
|
| 686 | try { |
|
| 687 | $variance = $this->variance(); |
|
| 688 | } catch (\PEAR_Exception $e) { |
|
| 689 | return $variance; |
|
| 690 | } |
|
| 691 | ||
| 692 | $this->_calculatedValues['stDev'] = sqrt($variance); |
|
| 693 | } |
|
| 694 | return $this->_calculatedValues['stDev']; |
|
| 695 | } |
|
| 696 | ||
| 697 | /** |
|
| 698 | * Calculates the variance (unbiased) of the data points in the set |
|
| 699 | * given a fixed mean (average) value. Not used in calcBasic(), calcFull() |
|
| @@ 749-762 (lines=14) @@ | ||
| 746 | * @see count() |
|
| 747 | * @see absDevWithMean() |
|
| 748 | */ |
|
| 749 | public function absDev() |
|
| 750 | { |
|
| 751 | if (!array_key_exists('absDev', $this->_calculatedValues)) { |
|
| 752 | try { |
|
| 753 | $absDev = $this->__calcAbsoluteDeviation(); |
|
| 754 | } catch (\PEAR_Exception $e) { |
|
| 755 | return $absDev; |
|
| 756 | } |
|
| 757 | ||
| 758 | $this->_calculatedValues['absDev'] = $absDev; |
|
| 759 | } |
|
| 760 | return $this->_calculatedValues['absDev']; |
|
| 761 | } |
|
| 762 | ||
| 763 | /** |
|
| 764 | * Calculates the absolute deviation of the data points in the set |
|
| 765 | * given a fixed mean (average) value. Not used in calcBasic(), calcFull() |
|
| @@ 1360-1372 (lines=13) @@ | ||
| 1357 | * @see quartiles() |
|
| 1358 | * @see interquartileRange() |
|
| 1359 | */ |
|
| 1360 | public function quartileDeviation() |
|
| 1361 | { |
|
| 1362 | if (!array_key_exists('quartileDeviation', $this->_calculatedValues)) { |
|
| 1363 | try { |
|
| 1364 | $iqr = $this->interquartileRange(); |
|
| 1365 | } catch (\PEAR_Exception $e) { |
|
| 1366 | return $iqr; |
|
| 1367 | } |
|
| 1368 | $this->_calculatedValues['quartileDeviation'] = $iqr / 2; |
|
| 1369 | } |
|
| 1370 | return $this->_calculatedValues['quartileDeviation']; |
|
| 1371 | } |
|
| 1372 | ||
| 1373 | /** |
|
| 1374 | * The quartile variation coefficient is defined as follows: |
|
| 1375 | * |
|