-
Notifications
You must be signed in to change notification settings - Fork 15
Beta Distribution
Esteban Zapata Rojas edited this page Aug 10, 2017
·
4 revisions
It calculates the beta function for any particular x
and y
values.
irb(main):005:0> alpha = rand(-5..5)
=> 3
irb(main):006:0> beta = rand(-5..5)
=> 4
irb(main):007:0> Statistics::Distribution::Beta.beta_function(alpha, beta)
=> 0.016666666666666666
irb(main):009:0> Statistics::Distribution::Beta.beta_function(rand(1..3), rand(1..3))
=> 1
It calculates the density for the specified value. If the value is greater than 1 or less than 0, it will default to zero.
[2] pry(main)> require 'statistics/distribution'
=> true
[3] pry(main)> beta_distribution = Distribution::Beta.new(2, 2)
=> #<Statistics::Distribution::Beta:0x007fc30a5126b8 @alpha=2.0, @beta=2.0>
[4] pry(main)> results = [0, 0.2, 0.4, 0.6, 0.8, 1].map do |number|
[4] pry(main)* beta_distribution.density_function(number)
[4] pry(main)* end
=> [0.0, 0.9600000000000002, 1.44, 1.44, 0.9599999999999999, 0.0]
It returns the mode for the beta distribution. The mode is not defined for values of alpha <=1 && beta <=1
.
[35] pry(main)> beta_distribution
=> #<Statistics::Distribution::Beta:0x007fdfcb933610 @alpha=2.0, @beta=2.0>
[36] pry(main)> beta_distribution.mode
=> 0.5
[37] pry(main)> Distribution::Beta.new(0.5, 0.5).mode
=> nil
It returns the mean for the beta distribution.
[40] pry(main)> beta_distribution
=> #<Statistics::Distribution::Beta:0x007fdfcb933610 @alpha=2.0, @beta=2.0>
[41] pry(main)> beta_distribution.mean
=> 0.5
``