Class: Bernoulli::Distribution::Hypergeometric
- Inherits:
-
Object
- Object
- Bernoulli::Distribution::Hypergeometric
show all
- Includes:
- Bernoulli::Distribution
- Defined in:
- lib/bernoulli/distribution/hypergeometric.rb
Overview
Instance Method Summary
collapse
#[], #probability_range, #standard_deviation
Constructor Details
Returns a new instance of Hypergeometric.
17
18
19
20
21
22
|
# File 'lib/bernoulli/distribution/hypergeometric.rb', line 17
def initialize(bn, m, n)
if bn < 1 or m < 0 or m > bn or n < 1 or n > bn
raise 'Expecting bn > 1, 0 < m < bn, 0 < n < bn'
end
@bn, @m, @n = bn.to_i, m.to_i, n.to_i
end
|
Instance Method Details
#excess ⇒ Object
48
49
50
|
# File 'lib/bernoulli/distribution/hypergeometric.rb', line 48
def excess
((@bn - 1) * @bn * @bn * (@bn * (@bn + 1) - 6 * @m * (@bn - @m) - 6 * @n * (@bn - @n)) + 6 * @n * @m * (@bn - @m) * (@bn - @n) * (5 * @bn - 6)).to_f / (@n * @m * (@bn - @m) * (@bn - @n) * (@bn - 2) * (@bn - 3))
end
|
#expected_value ⇒ Object
Also known as:
ev
34
35
36
|
# File 'lib/bernoulli/distribution/hypergeometric.rb', line 34
def expected_value
@n * (@m.to_f / @bn)
end
|
#probability(k) ⇒ Float
Returns the probability of ‘k` successes.
30
31
32
|
# File 'lib/bernoulli/distribution/hypergeometric.rb', line 30
def probability(k)
(Math.binomial(@m, k) * Math.binomial(@bn - @m, @n - k)).to_f / Math.binomial(@bn, @n)
end
|
#skewness ⇒ Object
44
45
46
|
# File 'lib/bernoulli/distribution/hypergeometric.rb', line 44
def skewness
((@bn - 2 * @m) * Math.sqrt(@bn - 1) * (@bn - 2 * @n)) / (Math.sqrt(@n * @m * (@bn - @m) * (@bn - @n)) * (@bn - 2))
end
|
#to_s ⇒ Object
24
25
26
|
# File 'lib/bernoulli/distribution/hypergeometric.rb', line 24
def to_s
"#<Distribution::Hypergeometric @bn=#@bn, @m=#@m, @n=#@n>"
end
|
#variance ⇒ Object
Also known as:
v
39
40
41
|
# File 'lib/bernoulli/distribution/hypergeometric.rb', line 39
def variance
(@n * @m * (@bn - @m) *(@bn - @n)).to_f / (@bn * @bn * (@bn - 1))
end
|