Informática Asociada ia doc & examples Index Examples List

Documentation jit ia\Math\Stats Documentation Usage sample Function examples Index Examples List

class ia\Math\Stats


Index Documentation Usage sample Function examples Index Examples List

ia\Math\Stats


Usage sample ia\Math\Stats Documentation Usage sample Function examples Index Examples List

Stats
Calculate Running basic statistics, using bcMath: min, avg, max, sum, var, stdDev, skewness, kurtosis, coefficient of variation (cv)
Setup
$stat = new Stats(); $stat = new Stats($scale = 8, $exceptions = 8); $scale number of decimals $exceptions How to manage missing, null, N/A & not numeric. default: MISSING_ZERO | NA_ZERO (missing & N/A set to 0.00) Stats::MISSING_ZERO Stats::MISSING_SKIP Stats::NA_ZERO Stats::NA_SKIP
Value by value
$stat = new Stats(); for($i=1; $i<11; $i++) $stat->push($i); $result = $stat->stats(); Array ( [min] => 1 [avg] => 5.50000000 [max] => 10 [count] => 10 [sum] => 55 [variance] => 9.16666666 [stdDev] => 3.02765035 [cv] => 55.04818800 [skewness] => 0.00000000 [kurtosis] => -1.22424243 )
Feed an array
$stats = new Stats(); $stats->pushArray([5,20,40,80,100]); $result = $stats->stats(); print_r($result); Array ( [min] => 5 [avg] => 48.99999999 [max] => 100 [count] => 5 [sum] => 245 [variance] => 1604.99999995 [stdDev] => 40.06245124 [cv] => 81.76010400 [skewness] => 0.22664883 [kurtosis] => -1.52599209 )
Get each stat value
  • $stats->avg(); // 48.99999999
  • $stats->count(); // 5
  • $stats->cv(); // 81.76010400
  • $stats->kurtosis(); // -1.52599209
  • $stats->max(); // 100
  • $stats->min(); // 5
  • $stats->skewness(); // 0.22664883
  • $stats->stdDev(); // 40.06245124
  • $stats->sum(); // 245

Examples by function ia\Math\Stats Documentation Usage sample Function examples Index Examples List

ia\Math\Stats

Disclaimer: Auto generated file. Please help us setting parameters to useful values and extending the examples.

/**
     * Constructor
     *
     * @param integer $scale number of decimals
     * @param integer $exceptions  How to manage missing, null, N/A & not numeric. Stats::MISSING_ Stats::NA_ default Asume 0.00
     * @return void
     */
/*
 $stats = new Stats(integer $scale = 8, integer $exceptions = 8);
*/

$stats = new Stats();

  • $stats->pushArray(array $valuesArray) : Stats
    /**
         * Caclulate stats for values in array
         *
         * @param array $valuesArray [val1, val2, ...]
         * @return Stats object this
         */
    
    1. $stats->pushArray(['a' => '1', 'b' => '2', 'c' => 3]); -> 
      Array
      (
          [min] => 1
          [avg] => 2.00000000
          [max] => 3
          [count] => 3
          [sum] => 6
          [variance] => 1.00000000
          [stdDev] => 1.00000000
          [cv] => 50.00000000
          [skewness] => 0.00000000
          [kurtosis] => -1.50000000
      )
      
  • $stats->push(string|int $x) : void
    /**
         * Add a value to caclulate
         *
         * @param string|int $x
         * @return void
         */
    
    1. $stats->push(3);"
  • $stats->count() : string|int
    /**
         * Return count or n elements processed
         *
         * @return string|int number of items calculated
         */
    
    1. $stats->count(); -> 4
  • $stats->min() : string
    /**
         * Minimum value encountered
         *
         * @return string bcmath number
         */
    
    1. $stats->min(); -> 1
  • $stats->avg() : string
    /**
         * Average, mean, of calculated values
         *
         * @return string bcmath number
         */
    
    1. $stats->avg(); -> 2.25000000
  • $stats->max() : string
    /**
         * Maximum value encountered
         *
         * @return string bcmath number
         */
    
    1. $stats->max(); -> 3
  • $stats->sum() : string
    /**
         * Sum or total of cacluated values
         *
         * @return string bcmath number
         */
    
    1. $stats->sum(); -> 9
  • $stats->variance() : string
    /**
         * Varaince
         *
         * @return string bcmath number
         */
    
    1. $stats->variance(); -> 0.91666666
  • $stats->stdDev() : string
    /**
         * Standard deviation
         *
         * @return string bcmath number
         */
    
    1. $stats->stdDev(); -> 0.95742710
  • $stats->skewness() :
    /**
         * Skewness
         *
         * Characterizes the degree of asymmetry of a distribution around its mean.
         * [-0.5, 0.5] aprox symetric, [0.5,1],[-0.5,-1] moderatly, else highly
         * Positive skewness indicates a distribution with an asymmetric tail extending toward more positive values.
         * Negative skewness indicates a distribution with an asymmetric tail extending toward more negative values.
         *
         * Skewness, has several estimators see:
         * https://www.researchgate.net/post/Is_there_any_difference_in_formula_when_calculating_Skewness_manually_and_using_SPSS_software
         *
         */
    
    1. $stats->skewness(); -> 
      -0.49338220
  • $stats->kurtosis() : string
    /**
         * Kurtosis
         *
         * Characterizes the relative peakedness or flatness of a distribution compared with the normal distribution.
         * Positive kurtosis indicates a relatively peaked distribution.
         * Negative kurtosis indicates a relatively flat distribution.
         *
         * A normal distribution has kurtosis exactly 3 (excess kurtosis exactly 0). Any distribution with kurtosis ≈3 (excess ≈0) is called mesokurtic.
         * A distribution with kurtosis <3 (excess kurtosis <0) is called platykurtic. Compared to a normal distribution, its tails are shorter and thinner, and often its central peak is lower and broader.
         * A distribution with kurtosis >3 (excess kurtosis >0) is called leptokurtic. Compared to a normal distribution, its tails are longer and fatter, and often its central peak is higher and sharper.
         *
         * @return string bcmath number
         */
    
    1. $stats->kurtosis(); -> -1.37190083
  • $stats->cv() : string
    /**
         * Coefficient of Variation (cv) stdDev/Avg * 100
         *
         * @return string bcmath number
         */
    
    1. $stats->cv(); -> 42.55231500
  • $stats->stats() : array
    /**
         * Returns basci statistics on calculated values
         *
         * @return array ['min'=>1,'avg'=>1,'max'=>1,'count'=>1,'sum'=1,'variance'=>1,'stdDev'=>1,'skewness'=>1,'kurtosis'=>1]
         */
    
    1. $stats->stats(); -> 
      Array
      (
          [min] => 1
          [avg] => 2.25000000
          [max] => 3
          [count] => 4
          [sum] => 9
          [variance] => 0.91666666
          [stdDev] => 0.95742710
          [cv] => 42.55231500
          [skewness] => -0.49338220
          [kurtosis] => -1.37190083
      )
      

End: ia\Math\Stats Documentation Usage sample Function examples Index Examples List