Sha256: 5aab9cf4d83bf3872d9d4ea64d679084debbf468e326fd57cb9aee9845f8d7ef

Contents?: true

Size: 751 Bytes

Versions: 4

Compression:

Stored size: 751 Bytes

Contents

module Statistics
  module Distribution
    class Bernoulli
      def self.density_function(n, p)
        return if n != 0 && n != 1 # The support of the distribution is n = {0, 1}.

        case n
        when 0 then 1.0 - p
        when 1 then p
        end
      end

      def self.cumulative_function(n, p)
        return if n != 0 && n != 1 # The support of the distribution is n = {0, 1}.

        case n
        when 0 then 1.0 - p
        when 1 then 1.0
        end
      end

      def self.variance(p)
        p * (1.0 - p)
      end

      def self.skewness(p)
        (1.0 - 2.0*p).to_f / Math.sqrt(p * (1.0 - p))
      end

      def self.kurtosis(p)
        (6.0 * (p ** 2) - (6 * p) + 1) / (p * (1.0 - p))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-statistics-2.1.2 lib/statistics/distribution/bernoulli.rb
ruby-statistics-2.1.1 lib/statistics/distribution/bernoulli.rb
ruby-statistics-2.1.0 lib/statistics/distribution/bernoulli.rb
ruby-statistics-2.0.5 lib/statistics/distribution/bernoulli.rb