Sha256: 9aa3707813d74b800665bfd2508b048b298710b773bf2a32ce89f5fe8b46a245

Contents?: true

Size: 745 Bytes

Versions: 3

Compression:

Stored size: 745 Bytes

Contents

module Statistics
  module Distribution
    class Beta
      attr_accessor :alpha, :beta

      def initialize(alp, bet)
        self.alpha = alp.to_f
        self.beta = bet.to_f
      end

      def cumulative_function(value)
        Math.incomplete_beta_function(value, alpha, beta)
      end

      def density_function(value)
        return 0 if value < 0 || value > 1 # Density function defined in the [0,1] interval

        num = (value**(alpha - 1)) * ((1 - value)**(beta - 1))
        den = Math.beta_function(alpha, beta)

        num/den
      end

      def mode
        return unless alpha > 1 && beta > 1

        (alpha - 1)/(alpha + beta - 2)
      end

      def mean
        alpha / (alpha + beta)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-statistics-1.0.2 lib/statistics/distribution/beta.rb
ruby-statistics-1.0.0 lib/statistics/distribution/beta.rb
ruby-statistics-0.5.0 lib/statistics/distribution/beta.rb