Class: Statistics::Distribution::ChiSquared
- Inherits:
-
Object
- Object
- Statistics::Distribution::ChiSquared
- Defined in:
- lib/statistics/distribution/chi_squared.rb
Instance Attribute Summary collapse
-
#degrees_of_freedom ⇒ Object
(also: #mean)
Returns the value of attribute degrees_of_freedom.
Instance Method Summary collapse
- #cumulative_function(value) ⇒ Object
- #density_function(value) ⇒ Object
-
#initialize(k) ⇒ ChiSquared
constructor
A new instance of ChiSquared.
- #mode ⇒ Object
- #variance ⇒ Object
Constructor Details
#initialize(k) ⇒ ChiSquared
Returns a new instance of ChiSquared.
8 9 10 |
# File 'lib/statistics/distribution/chi_squared.rb', line 8 def initialize(k) self.degrees_of_freedom = k end |
Instance Attribute Details
#degrees_of_freedom ⇒ Object Also known as: mean
Returns the value of attribute degrees_of_freedom.
4 5 6 |
# File 'lib/statistics/distribution/chi_squared.rb', line 4 def degrees_of_freedom @degrees_of_freedom end |
Instance Method Details
#cumulative_function(value) ⇒ Object
12 13 14 15 |
# File 'lib/statistics/distribution/chi_squared.rb', line 12 def cumulative_function(value) k = degrees_of_freedom/2.0 Math.lower_incomplete_gamma_function(k, value/2.0)/Math.gamma(k) end |
#density_function(value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/statistics/distribution/chi_squared.rb', line 17 def density_function(value) return 0 if value < 0 common = degrees_of_freedom/2.0 left_down = (2 ** common) * Math.gamma(common) right = (value ** (common - 1)) * Math.exp(-(value/2.0)) (1.0/left_down) * right end |
#mode ⇒ Object
28 29 30 |
# File 'lib/statistics/distribution/chi_squared.rb', line 28 def mode [degrees_of_freedom - 2, 0].max end |
#variance ⇒ Object
32 33 34 |
# File 'lib/statistics/distribution/chi_squared.rb', line 32 def variance degrees_of_freedom * 2 end |