class Statistics::Distribution::ChiSquared
Attributes
degrees_of_freedom[RW]
mean[RW]
Public Class Methods
new(k)
click to toggle source
# File lib/statistics/distribution/chi_squared.rb, line 8 def initialize(k) self.degrees_of_freedom = k end
Public Instance Methods
cumulative_function(value)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/statistics/distribution/chi_squared.rb, line 28 def mode [degrees_of_freedom - 2, 0].max end
variance()
click to toggle source
# File lib/statistics/distribution/chi_squared.rb, line 32 def variance degrees_of_freedom * 2 end