Esempio n. 1
0
 /**
  * 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);
 }
Esempio n. 2
0
 /**
  * Returns the survival function, the probability of getting the test value or something above it
  * 
  * @param float $x The test value
  * @return float The probability
  */
 public function sf($x)
 {
     return $this->calculator->getSf($x, $this->k);
 }