ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
HyperGeometric.php
Go to the documentation of this file.
1 <?php
2 
4 
8 
10 {
24  public static function distribution($sampleSuccesses, $sampleNumber, $populationSuccesses, $populationNumber)
25  {
26  $sampleSuccesses = Functions::flattenSingleValue($sampleSuccesses);
27  $sampleNumber = Functions::flattenSingleValue($sampleNumber);
28  $populationSuccesses = Functions::flattenSingleValue($populationSuccesses);
29  $populationNumber = Functions::flattenSingleValue($populationNumber);
30 
31  try {
32  $sampleSuccesses = DistributionValidations::validateInt($sampleSuccesses);
33  $sampleNumber = DistributionValidations::validateInt($sampleNumber);
34  $populationSuccesses = DistributionValidations::validateInt($populationSuccesses);
35  $populationNumber = DistributionValidations::validateInt($populationNumber);
36  } catch (Exception $e) {
37  return $e->getMessage();
38  }
39 
40  if (($sampleSuccesses < 0) || ($sampleSuccesses > $sampleNumber) || ($sampleSuccesses > $populationSuccesses)) {
41  return Functions::NAN();
42  }
43  if (($sampleNumber <= 0) || ($sampleNumber > $populationNumber)) {
44  return Functions::NAN();
45  }
46  if (($populationSuccesses <= 0) || ($populationSuccesses > $populationNumber)) {
47  return Functions::NAN();
48  }
49 
50  $successesPopulationAndSample = (float) Combinations::withoutRepetition($populationSuccesses, $sampleSuccesses);
51  $numbersPopulationAndSample = (float) Combinations::withoutRepetition($populationNumber, $sampleNumber);
52  $adjustedPopulationAndSample = (float) Combinations::withoutRepetition(
53  $populationNumber - $populationSuccesses,
54  $sampleNumber - $sampleSuccesses
55  );
56 
57  return $successesPopulationAndSample * $adjustedPopulationAndSample / $numbersPopulationAndSample;
58  }
59 }
static distribution($sampleSuccesses, $sampleNumber, $populationSuccesses, $populationNumber)
HYPGEOMDIST.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649