class MoreMath::ChiSquareDistribution
This class is used to compute the Chi-Square Distribution.
def initialize(df)
def initialize(df) @df = df @df_half = @df / 2.0 end
def inverse_probability(p)
Returns the inverse cumulative probability value of the
def inverse_probability(p) case when p <= 0, p >= 1 0.0 else begin bisect = NewtonBisection.new { |x| probability(x) - p } range = bisect.bracket 0.5..10 bisect.solve(range, 1_000_000) rescue 0 / 0.0 end end end
def probability(x)
Returns the cumulative probability (p-value) of the ChiSquareDistribution
def probability(x) if x < 0 0.0 else gammaP_regularized(x / 2, @df_half) end end