Class: Prubybility::NegativeBinomial
- Inherits:
-
Object
- Object
- Prubybility::NegativeBinomial
- Includes:
- Combinations
- Defined in:
- lib/prubybility/negative_binomial.rb
Overview
A representation of the Negative Binomial probability distribution.
See README for example usages.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#expected_value ⇒ Object
(also: #mean)
readonly
Returns the value of attribute expected_value.
-
#k ⇒ Object
readonly
Returns the value of attribute k.
-
#theta ⇒ Object
readonly
Returns the value of attribute theta.
-
#variance ⇒ Object
readonly
Returns the value of attribute variance.
Instance Method Summary collapse
-
#initialize(fixed_successes, theta) ⇒ NegativeBinomial
constructor
A new instance of NegativeBinomial.
- #p(var) ⇒ Object
Methods included from Combinations
Constructor Details
#initialize(fixed_successes, theta) ⇒ NegativeBinomial
14 15 16 17 18 19 |
# File 'lib/prubybility/negative_binomial.rb', line 14 def initialize(fixed_successes, theta) @k = fixed_successes @theta = theta.to_d @expected_value = @k / @theta @variance = @k / @theta * (1 / @theta - 1) end |
Instance Attribute Details
#expected_value ⇒ Object Also known as: mean
Returns the value of attribute expected_value.
10 11 12 |
# File 'lib/prubybility/negative_binomial.rb', line 10 def expected_value @expected_value end |
#k ⇒ Object
Returns the value of attribute k.
10 11 12 |
# File 'lib/prubybility/negative_binomial.rb', line 10 def k @k end |
#theta ⇒ Object
Returns the value of attribute theta.
10 11 12 |
# File 'lib/prubybility/negative_binomial.rb', line 10 def theta @theta end |
#variance ⇒ Object
Returns the value of attribute variance.
10 11 12 |
# File 'lib/prubybility/negative_binomial.rb', line 10 def variance @variance end |
Instance Method Details
#p(var) ⇒ Object
21 22 23 |
# File 'lib/prubybility/negative_binomial.rb', line 21 def p(var) choose(var) * (theta**k) * ((1 - theta)**(var - k)) end |