Skip to content

Negative Binomial Distribution

Esteban Zapata Rojas edited this page Jun 27, 2018 · 1 revision

Negative Binomial Distribution

Instance Methods

Probability mass function

It returns the probability mass value for the specified K. If the specified K < 0 or K > number of specified failures before success at initialization time, then the probability mass function is not defined.

[25] pry(main)> Distribution::NegativeBinomial.new(3,0.5)
=> #<Statistics::Distribution::NegativeBinomial:0x00000000018b7648 @number_of_failures=3, @probability_per_trial=0.5>
[26] pry(main)> Distribution::Binomial.new(3,0.5).probability_mass_function(-1)
=> nil
[27] pry(main)> Distribution::Binomial.new(3,0.5).probability_mass_function(4)
=> nil
[28] pry(main)> Distribution::Binomial.new(3,0.5).probability_mass_function(2)
=> 0.1875

Cumulative function

It returns the probability P(x <= K) for the specified K. If the specified K < 0 or K > number of specified failures before success at initialization time, then the cumulative function is not defined.

[29] pry(main)> Distribution::NegativeBinomial.new(3,0.5).cumulative_function(4)
=> nil
[30] pry(main)> Distribution::NegativeBinomial.new(3,0.5).cumulative_function(-1)
=> nil
[31] pry(main)> Distribution::NegativeBinomial.new(3,0.5).cumulative_function(2)
=> 0.49999999999999967

Mean

It calculates the mean of the negative binomial distribution.

[32] pry(main)> Distribution::NegativeBinomial.new(3,0.5).mean
=> 3.0

Variance

It returns the expected variance for the negative binomial distribution

[34] pry(main)> Distribution::NegativeBinomial.new(3,0.5).variance
=> 6.0

Mode

If the number of failures before a success is less or equal than one, the mode is zero. Otherwise, it calculates the mode properly.

[43] pry(main)> Distribution::NegativeBinomial.new(3, 0.351).mode
=> 2
[44] pry(main)> Distribution::NegativeBinomial.new(1, 0.5).mode
=> 0.0
[45] pry(main)> Distribution::NegativeBinomial.new(1, 0.5).mode
=> 0.0
[45] pry(main)> Distribution::NegativeBinomial.new(-2, 0.5).mode
=> 0.0

Skewness

It calculates the skewness for the negative binomial distribution

[11] pry(main)> Distribution::NegativeBinomial.new(3, 0.5).skewness
=> 1.2247448713915892