class Statistics::Distribution::Bernoulli

Public Class Methods

cumulative_function(n, p) click to toggle source
# File lib/statistics/distribution/bernoulli.rb, line 13
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
density_function(n, p) click to toggle source
# File lib/statistics/distribution/bernoulli.rb, line 4
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
kurtosis(p) click to toggle source
# File lib/statistics/distribution/bernoulli.rb, line 30
def self.kurtosis(p)
  (6.0 * (p ** 2) - (6 * p) + 1) / (p * (1.0 - p))
end
skewness(p) click to toggle source
# File lib/statistics/distribution/bernoulli.rb, line 26
def self.skewness(p)
  (1.0 - 2.0*p).to_r / Math.sqrt(p * (1.0 - p))
end
variance(p) click to toggle source
# File lib/statistics/distribution/bernoulli.rb, line 22
def self.variance(p)
  p * (1.0 - p)
end