Method: RubyStatistics::Distribution::Poisson#probability_mass_function

Defined in:
lib/ruby-statistics/distribution/poisson.rb

#probability_mass_function(k) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby-statistics/distribution/poisson.rb', line 13

def probability_mass_function(k)
  return if k < 0 || expected_number_of_occurrences < 0

  k = k.to_i

  upper = (expected_number_of_occurrences ** k) * Math.exp(-expected_number_of_occurrences)
  lower = Math.factorial(k)

  upper/lower.to_r
end