-
Notifications
You must be signed in to change notification settings - Fork 15
Geometric Distribution
This implementation has two variants:
- When 0 < p < 1.
- When 0 < p <= 1.
If you want to use the implementation where the probability can be one, specify at initialization time the flag always_success: true
or change the always_success_allowed
attribute to true
(false
by default).
It returns the probability mass value for the specified K.
If p < 1 and k <= 0 then the density function is not defined.
[4] pry(main)> Distribution::Geometric.new(0.5) # always_success: false
=> #<Statistics::Distribution::Geometric:0x000056351a0cfa08 @always_success_allowed=false, @probability_of_success=0.5>
[5] pry(main)> Distribution::Geometric.new(0.5).density_function(0)
=> nil
[6] pry(main)> Distribution::Geometric.new(0.5).density_function(4)
=> 0.0625
[7] pry(main)> Distribution::Geometric.new(0.5).density_function(2)
=> 0.25
If p <= 1 and k < 0 then the density function is not defined.
[8] pry(main)> Distribution::Geometric.new(0.5, always_success: true) # always_success: true
=> #<Statistics::Distribution::Geometric:0x000056351a146220 @always_success_allowed=true, @probability_of_success=0.5>
[9] pry(main)> Distribution::Geometric.new(0.5, always_success: true).density_function(0)
=> 0.5
[10] pry(main)> Distribution::Geometric.new(0.5, always_success: true).density_function(4)
=> 0.03125
[11] pry(main)> Distribution::Geometric.new(0.5, always_success: true).density_function(2)
=> 0.125
It returns the probability P(x <= K)
for the specified K.
If p < 1 and k <= 0 then the cumulative function is not defined.
[12] pry(main)> Distribution::Geometric.new(0.5) # always_success: false
=> #<Statistics::Distribution::Geometric:0x0000563519d6e7b0 @always_success_allowed=false, @probability_of_success=0.5>
[13] pry(main)> Distribution::Geometric.new(0.5).cumulative_function(0)
=> nil
[14] pry(main)> Distribution::Geometric.new(0.5).cumulative_function(4)
=> 0.9375
[15] pry(main)> Distribution::Geometric.new(0.5).cumulative_function(2)
=> 0.75
If p <=1 and k < 0 then the cumulative function is not defined.
[16] pry(main)> Distribution::Geometric.new(0.5, always_success: true) # always_success: true
=> #<Statistics::Distribution::Geometric:0x000056351a26cfa0 @always_success_allowed=true, @probability_of_success=0.5>
[17] pry(main)> Distribution::Geometric.new(0.5, always_success: true).cumulative_function(0)
=> 0.5
[18] pry(main)> Distribution::Geometric.new(0.5, always_success: true).cumulative_function(4)
=> 0.96875
[19] pry(main)> Distribution::Geometric.new(0.5, always_success: true).cumulative_function(2)
=> 0.875
It calculates the mean of the geometric distribution. It varies depending of the strategy choosen for the probability.
[20] pry(main)> Distribution::Geometric.new(0.5, always_success: true).mean # always_success: true
=> 1.0
[21] pry(main)> Distribution::Geometric.new(0.5, always_success: false).mean # always_success: false
=> 2.0
It calculates the median of the geometric distribution. It varies depending of the strategy choosen for the probability.
[20] pry(main)> Distribution::Geometric.new(0.5, always_success: true).median # always_success: true
=> 0.0
[21] pry(main)> Distribution::Geometric.new(0.5, always_success: false).median # always_success: false
=> 1.0
It calculates the mode of the geometric distribution. It varies depending of the strategy choosen for the probability.
[26] pry(main)> Distribution::Geometric.new(0.75, always_success: false).mode # always_success: false
=> 1.0
[27] pry(main)> Distribution::Geometric.new(0.75, always_success: true).mode # always_success: false
=> 0.0
It returns the expected variance for the geometric distribution
[28] pry(main)> Distribution::Geometric.new(0.75, always_success: true).variance # always_success: false
=> 0.4444444444444444
[29] pry(main)> Distribution::Geometric.new(0.75, always_success: false).variance # always_success: false
=> 0.4444444444444444
It calculates the skewness for the geometric distribution
[30] pry(main)> Distribution::Geometric.new(0.75, always_success: false).skewness # always_success: false
=> 2.5
[31] pry(main)> Distribution::Geometric.new(0.75, always_success: true).skewness # always_success: false
=> 2.5
It calculates the kurtosis for the geometric distribution
[32] pry(main)> Distribution::Geometric.new(0.75, always_success: true).kurtosis # always_success: false
=> 8.25
[33] pry(main)> Distribution::Geometric.new(0.75, always_success: false).kurtosis # always_success: false
=> 8.25