/** * Binomial distribution - probability mass function * https://en.wikipedia.org/wiki/Binomial_distribution * * P(X = r) = nCr pʳ (1 - p)ⁿ⁻ʳ * * @param int $n number of events * @param int $r number of successful events * @param float $p probability of success * * @return float */ public static function PMF(int $n, int $r, float $p) : float { Support::checkLimits(self::LIMITS, ['n' => $n, 'r' => $r, 'p' => $p]); $nCr = Combinatorics::combinations($n, $r); $pʳ = pow($p, $r); $⟮1 − p⟯ⁿ⁻ʳ = pow(1 - $p, $n - $r); return $nCr * $pʳ * $⟮1 − p⟯ⁿ⁻ʳ; }
/** * Probability mass function * * b(x; r, p) = ₓ₋₁Cᵣ₋₁ pʳ * (1 - p)ˣ⁻ʳ * * @param int $x number of trials required to produce r successes * @param int $r number of successful events * @param float $p probability of success on an individual trial * * @return float */ public static function PMF(int $x, int $r, float $p) : float { Support::checkLimits(self::LIMITS, ['x' => $x, 'r' => $r, 'p' => $p]); $ₓ₋₁Cᵣ₋₁ = Combinatorics::combinations($x - 1, $r - 1); $pʳ = pow($p, $r); $⟮1 − p⟯ˣ⁻ʳ = pow(1 - $p, $x - $r); return $ₓ₋₁Cᵣ₋₁ * $pʳ * $⟮1 − p⟯ˣ⁻ʳ; }