/**
  * Pearson's Chi-Squared Goodness of Fit Test
  * 
  * Tests whether a set of observations is significantly different than a
  * set of expected values. To test goodness of fit against a distribution,
  * use the appropriate distribution class to generate a corresponding set
  * of expected values before calling this.
  * 
  * @param array $observations The set of observations to be tested
  * @param array $expected The set of expected values to be tested
  * @param int $df The degrees of freedom in the test
  * @return float The probability of getting the chi-squared statistic or more, the p-value
  */
 public function chiSquareTest(array $observations, array $expected, $df)
 {
     $sum = 0;
     $pairsTested = min(count($observations), count($observations));
     for ($i = 0; $i < $pairsTested; $i++) {
         if ($expected[$i] == 0) {
             continue;
         }
         $sum += pow($observations[$i] - $expected[$i], 2) / $expected[$i];
     }
     return $this->chi->getSf($sum, $df);
 }
Example #2
0
 /**
  * Returns the moments of the distribution
  * 
  * @param string $moments Which moments to compute. m for mean, v for variance, s for skew, k for kurtosis.  Default 'mv'
  * @return type array A dictionary containing the first four moments of the distribution
  */
 public function stats($moments = 'mv')
 {
     return $this->calculator->getStats($moments, $this->k);
 }
Example #3
0
 /**
  * Returns a random float between $d1 and $d1 plus $d2
  * 
  * @param float $d1 Degrees of freedom 1. Default 1.0
  * @param float $d2 Degrees of freedom 2. Default 1.0
  * @return float The random variate.
  */
 public function getRvs($d1 = 1, $d2 = 1)
 {
     $x = $this->chi->getRvs($d1);
     $y = $this->chi->getRvs($d2);
     return $x / $d1 / ($y / $d2);
 }