Class: Bernoulli::Distribution::Geometric
Overview
Instance Method Summary
collapse
#[], #probability_range, #standard_deviation
Constructor Details
Returns a new instance of Geometric.
13
14
15
16
17
18
|
# File 'lib/bernoulli/distribution/geometric.rb', line 13
def initialize(p)
if p > 1.0 or p < 0.0
raise 'Expecting 0.0 <= p <= 1.0'
end
@p = p.to_f
end
|
Instance Method Details
#excess ⇒ Object
49
50
51
|
# File 'lib/bernoulli/distribution/geometric.rb', line 49
def excess
6 + @p**2 / (1 - @p)
end
|
#expected_value ⇒ Object
Also known as:
ev
35
36
37
|
# File 'lib/bernoulli/distribution/geometric.rb', line 35
def expected_value
1 / @p
end
|
#probability(k) ⇒ Float
Returns the probability that the first occurrence of success require ‘k` independent trials.
27
28
29
30
31
32
33
|
# File 'lib/bernoulli/distribution/geometric.rb', line 27
def probability(k)
if k == 0
0
else
(1 - @p)**(k - 1) * @p
end
end
|
#skewness ⇒ Object
45
46
47
|
# File 'lib/bernoulli/distribution/geometric.rb', line 45
def skewness
(2 - @p) / Math.sqrt(1 - @p)
end
|
#to_s ⇒ Object
20
21
22
|
# File 'lib/bernoulli/distribution/geometric.rb', line 20
def to_s
"#<Distribution::Geometric @p=#@p>"
end
|
#variance ⇒ Object
Also known as:
v
40
41
42
|
# File 'lib/bernoulli/distribution/geometric.rb', line 40
def variance
(1 - @p) / @p**2
end
|