Example #1
0
 /**
  * Two Sample T Test
  * 
  * The two-sample T test tests whether two samples are significantly
  * different from each other.
  * 
  * @param array $datax The first sample to test
  * @param array $datay The second sample to test
  * @return float The probability of having the first sample's population mean be greater than or equal to the second sample's population mean
  */
 static function twoSampleTTest(array $datax, array $datay)
 {
     $df = pow(pow(Stats::sampleStddev($datax), 2) / count($datax) + pow(Stats::sampleStddev($datay), 2) / count($datay), 2) / (pow(pow(Stats::sampleStddev($datax), 2) / count($datax), 2) / (count($datax) - 1) + pow(pow(Stats::sampleStddev($datay), 2) / count($datay), 2) / (count($datay) - 1));
     $sampleT = (Stats::average($datax) - Stats::average($datay)) / sqrt(pow(Stats::sampleStddev($datax), 2) / count($datax) + pow(Stats::sampleStddev($datay), 2) / count($datay));
     return \PHPStats\ProbabilityDistribution\StudentsT::getCdf($sampleT, $df);
 }