In Files

Parent

Files

Bullshit::TDistribution

This class is used to compute the T-Distribution.

Attributes

df[R]

Degrees of freedom.

Public Class Methods

new(df) click to toggle source

Returns a TDistribution instance for the degrees of freedom df.

# File lib/bullshit.rb, line 822
    def initialize(df)
      @df = df
    end

Public Instance Methods

inverse_probability(p) click to toggle source

Returns the inverse cumulative probability (t-value) of the TDistribution for the probability p.

# File lib/bullshit.rb, line 846
    def inverse_probability(p)
      case
      when p <= 0
        -1 / 0.0
      when p >= 1
        1 / 0.0
      else 
        begin
          bisect = NewtonBisection.new { |x| probability(x) - p }
          range = bisect.bracket(-10..10)
          bisect.solve(range, 1_000_000)
        rescue
          0 / 0.0
        end
      end
    end
probability(x) click to toggle source

Returns the cumulative probability (p-value) of the TDistribution for the t-value x.

# File lib/bullshit.rb, line 831
    def probability(x)
      if x == 0
        0.5
      else
        t = beta_regularized(@df / (@df + x ** 2.0), 0.5 * @df, 0.5)
        if x < 0.0
          0.5 * t
        else
          1 - 0.5 * t
        end
      end
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.