Class: RubyStatistics::Distribution::Beta
- Inherits:
-
Object
- Object
- RubyStatistics::Distribution::Beta
- Defined in:
- lib/ruby-statistics/distribution/beta.rb
Instance Attribute Summary collapse
-
#alpha ⇒ Object
Returns the value of attribute alpha.
-
#beta ⇒ Object
Returns the value of attribute beta.
Instance Method Summary collapse
- #cumulative_function(value) ⇒ Object
- #density_function(value) ⇒ Object
-
#initialize(alp, bet) ⇒ Beta
constructor
A new instance of Beta.
- #mean ⇒ Object
- #mode ⇒ Object
Constructor Details
#initialize(alp, bet) ⇒ Beta
Returns a new instance of Beta.
6 7 8 9 |
# File 'lib/ruby-statistics/distribution/beta.rb', line 6 def initialize(alp, bet) self.alpha = alp.to_r self.beta = bet.to_r end |
Instance Attribute Details
#alpha ⇒ Object
Returns the value of attribute alpha.
4 5 6 |
# File 'lib/ruby-statistics/distribution/beta.rb', line 4 def alpha @alpha end |
#beta ⇒ Object
Returns the value of attribute beta.
4 5 6 |
# File 'lib/ruby-statistics/distribution/beta.rb', line 4 def beta @beta end |
Instance Method Details
#cumulative_function(value) ⇒ Object
11 12 13 |
# File 'lib/ruby-statistics/distribution/beta.rb', line 11 def cumulative_function(value) Math.incomplete_beta_function(value, alpha, beta) end |
#density_function(value) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/ruby-statistics/distribution/beta.rb', line 15 def density_function(value) return 0 if value < 0 || value > 1 # Density function defined in the [0,1] interval num = (value**(alpha - 1)) * ((1 - value)**(beta - 1)) den = Math.beta_function(alpha, beta) num/den end |
#mean ⇒ Object
30 31 32 33 |
# File 'lib/ruby-statistics/distribution/beta.rb', line 30 def mean return if alpha + beta == 0 alpha / (alpha + beta) end |
#mode ⇒ Object
24 25 26 27 28 |
# File 'lib/ruby-statistics/distribution/beta.rb', line 24 def mode return unless alpha > 1 && beta > 1 (alpha - 1)/(alpha + beta - 2) end |