class Statistics::Distribution::Poisson

Attributes

expected_number_of_occurrences[RW]
mean[RW]
variance[RW]

Public Class Methods

new(l) click to toggle source
# File lib/statistics/distribution/poisson.rb, line 9
def initialize(l)
  self.expected_number_of_occurrences = l
end

Public Instance Methods

cumulative_function(k) click to toggle source
# File lib/statistics/distribution/poisson.rb, line 24
def cumulative_function(k)
  return if k < 0 || expected_number_of_occurrences < 0

  k = k.to_i

  upper = Math.lower_incomplete_gamma_function((k + 1).floor, expected_number_of_occurrences)
  lower = Math.factorial(k.floor)

  # We need the right tail, i.e.: The upper incomplete gamma function. This can be
  # achieved by doing a substraction between 1 and the lower incomplete gamma function.
  1 - (upper/lower.to_r)
end
probability_mass_function(k) click to toggle source
# File lib/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