Class: RubyStatistics::Distribution::Bernoulli

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-statistics/distribution/bernoulli.rb

Class Method Summary collapse

Class Method Details

.cumulative_function(n, p) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/ruby-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) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/ruby-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) ⇒ Object



30
31
32
# File 'lib/ruby-statistics/distribution/bernoulli.rb', line 30

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

.skewness(p) ⇒ Object



26
27
28
# File 'lib/ruby-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) ⇒ Object



22
23
24
# File 'lib/ruby-statistics/distribution/bernoulli.rb', line 22

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