Sha256: d3acfcd75bb6fe606f7dd217d8e63cd920d71c0b24bc3155bdff0d4fd781afad

Contents?: true

Size: 785 Bytes

Versions: 3

Compression:

Stored size: 785 Bytes

Contents

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

      def initialize(alp, bet)
        self.alpha = alp.to_r
        self.beta = bet.to_r
      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
        return if alpha + beta == 0
        alpha / (alpha + beta)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-statistics-4.1.0 lib/ruby-statistics/distribution/beta.rb
ruby-statistics-4.0.1 lib/ruby-statistics/distribution/beta.rb
ruby-statistics-4.0.0 lib/ruby-statistics/distribution/beta.rb