Class: Rubystats::BinomialDistribution
- Inherits:
-
ProbabilityDistribution
- Object
- ProbabilityDistribution
- Rubystats::BinomialDistribution
- Includes:
- ExtraMath, MakeDiscrete, NumericalConstants, SpecialMath
- Defined in:
- lib/rubystats/binomial_distribution.rb
Constant Summary
Constants included from NumericalConstants
NumericalConstants::EPS, NumericalConstants::GAMMA, NumericalConstants::GAMMA_X_MAX_VALUE, NumericalConstants::GOLDEN_RATIO, NumericalConstants::LOG_GAMMA_X_MAX_VALUE, NumericalConstants::MAX_FLOAT, NumericalConstants::MAX_ITERATIONS, NumericalConstants::MAX_VALUE, NumericalConstants::PRECISION, NumericalConstants::SQRT2, NumericalConstants::SQRT2PI, NumericalConstants::TWO_PI, NumericalConstants::XMININ
Instance Attribute Summary collapse
-
#n ⇒ Object
Returns the value of attribute n.
-
#p ⇒ Object
Returns the value of attribute p.
Attributes included from SpecialMath
#log_beta_cache_p, #log_beta_cache_q, #log_beta_cache_res, #log_gamma_cache_res, #log_gamma_cache_x
Instance Method Summary collapse
-
#get_mean ⇒ Object
returns the mean.
-
#get_probability_parameter ⇒ Object
returns the probability.
-
#get_trials_parameter ⇒ Object
returns the number of trials.
-
#get_variance ⇒ Object
returns the variance.
-
#initialize(trials, prob) ⇒ BinomialDistribution
constructor
Constructs a binomial distribution.
Methods included from MakeDiscrete
Methods included from ExtraMath
Methods included from SpecialMath
#beta, #beta_fraction, #complementary_error, #error, #gamma, #gamma_fraction, #gamma_series_expansion, #incomplete_beta, #incomplete_gamma, #log_beta, #log_gamma, #orig_gamma
Methods inherited from ProbabilityDistribution
#cdf, #check_range, #find_root, #get_factorial, #icdf, #mean, #pdf, #rng, #variance
Constructor Details
#initialize(trials, prob) ⇒ BinomialDistribution
Constructs a binomial distribution
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubystats/binomial_distribution.rb', line 18 def initialize (trials, prob) if trials <= 0 raise ArgumentError.new("Error: trials must be greater than 0") end @n = trials.to_i if prob < 0.0 || prob > 1.0 raise ArgumentError.new("prob must be between 0 and 1") end @p = prob.to_f end |
Instance Attribute Details
#n ⇒ Object
Returns the value of attribute n.
14 15 16 |
# File 'lib/rubystats/binomial_distribution.rb', line 14 def n @n end |
#p ⇒ Object
Returns the value of attribute p.
14 15 16 |
# File 'lib/rubystats/binomial_distribution.rb', line 14 def p @p end |
Instance Method Details
#get_mean ⇒ Object
returns the mean
40 41 42 |
# File 'lib/rubystats/binomial_distribution.rb', line 40 def get_mean @n * @p end |
#get_probability_parameter ⇒ Object
returns the probability
35 36 37 |
# File 'lib/rubystats/binomial_distribution.rb', line 35 def get_probability_parameter @p end |
#get_trials_parameter ⇒ Object
returns the number of trials
30 31 32 |
# File 'lib/rubystats/binomial_distribution.rb', line 30 def get_trials_parameter @n end |
#get_variance ⇒ Object
returns the variance
45 46 47 |
# File 'lib/rubystats/binomial_distribution.rb', line 45 def get_variance @n * @p * (1.0 - @p) end |