Class: RubyStatistics::Distribution::F
- Inherits:
-
Object
- Object
- RubyStatistics::Distribution::F
- Defined in:
- lib/ruby-statistics/distribution/f.rb
Instance Attribute Summary collapse
-
#d1 ⇒ Object
Degrees of freedom #1 and #2.
-
#d2 ⇒ Object
Degrees of freedom #1 and #2.
Instance Method Summary collapse
-
#cumulative_function(value) ⇒ Object
Formula extracted from www.itl.nist.gov/div898/handbook/eda/section3/eda3665.htm#CDF.
- #density_function(value) ⇒ Object
-
#initialize(k, j) ⇒ F
constructor
A new instance of F.
- #mean ⇒ Object
- #mode ⇒ Object
Constructor Details
#initialize(k, j) ⇒ F
Returns a new instance of F.
6 7 8 9 |
# File 'lib/ruby-statistics/distribution/f.rb', line 6 def initialize(k, j) self.d1 = k self.d2 = j end |
Instance Attribute Details
#d1 ⇒ Object
Degrees of freedom #1 and #2
4 5 6 |
# File 'lib/ruby-statistics/distribution/f.rb', line 4 def d1 @d1 end |
#d2 ⇒ Object
Degrees of freedom #1 and #2
4 5 6 |
# File 'lib/ruby-statistics/distribution/f.rb', line 4 def d2 @d2 end |
Instance Method Details
#cumulative_function(value) ⇒ Object
Formula extracted from www.itl.nist.gov/div898/handbook/eda/section3/eda3665.htm#CDF
12 13 14 15 16 |
# File 'lib/ruby-statistics/distribution/f.rb', line 12 def cumulative_function(value) k = d2/(d2 + d1 * value.to_r) 1 - Math.incomplete_beta_function(k, d2/2.0, d1/2.0) end |
#density_function(value) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby-statistics/distribution/f.rb', line 18 def density_function(value) return if d1 < 0 || d2 < 0 # F-pdf is well defined for the [0, +infinity) interval. val = value.to_r upper = ((d1 * val) ** d1) * (d2**d2) lower = (d1 * val + d2) ** (d1 + d2) up = Math.sqrt(upper/lower.to_r) down = val * Math.beta_function(d1/2.0, d2/2.0) up/down.to_r end |
#mean ⇒ Object
30 31 32 33 34 |
# File 'lib/ruby-statistics/distribution/f.rb', line 30 def mean return if d2 <= 2 d2/(d2 - 2).to_r end |
#mode ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/ruby-statistics/distribution/f.rb', line 36 def mode return if d1 <= 2 left = (d1 - 2)/d1.to_r right = d2/(d2 + 2).to_r (left * right).to_f end |