Module: Distribution::Poisson::Ruby_

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

Class Method Summary collapse

Class Method Details

.cdf(k, l) ⇒ Object



8
9
10
# File 'lib/distribution/poisson/ruby.rb', line 8

def cdf(k,l)
  Math.exp(-l)*(0..k).inject(0) {|ac,i| ac+ (l**i).quo(Math.factorial(i))}
end

.p_value(prob, l) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/distribution/poisson/ruby.rb', line 11

def p_value(prob,l)
  ac=0
  (0..100).each do |i|
    ac+=pdf(i,l)
    return i if prob<=ac
  end
end

.pdf(k, l) ⇒ Object



5
6
7
# File 'lib/distribution/poisson/ruby.rb', line 5

def pdf(k,l )
  (l**k*Math.exp(-l)).quo(Math.factorial(k))
end