Module: Distribution::F::Ruby_
- Extended by:
- MathExtension
- Defined in:
- lib/distribution/f/ruby.rb
Overview
The upper and lower cumulative distribution functions are related by P(x) + Q(x) = 1 and satisfy 0 <= P(x) <= 1, 0 <= Q(x).
Constant Summary
Constants included from MathExtension
MathExtension::EULER, MathExtension::LN2, MathExtension::LNPI, MathExtension::LOG_FLOAT_MIN, MathExtension::ROOT3_FLOAT_EPSILON, MathExtension::ROOT3_FLOAT_MIN, MathExtension::ROOT4_FLOAT_EPSILON, MathExtension::ROOT4_FLOAT_MIN, MathExtension::ROOT5_FLOAT_EPSILON, MathExtension::ROOT5_FLOAT_MIN, MathExtension::ROOT6_FLOAT_EPSILON, MathExtension::ROOT6_FLOAT_MIN, MathExtension::SQRT2, MathExtension::SQRTPI
Class Method Summary collapse
-
.cdf(x, n, m) ⇒ Object
Cumulative Distribution Function.
- .entropy ⇒ Object
- .kurtosis ⇒ Object
-
.mean ⇒ Float
Return the corresponding F value for a p-value
y
withn
andm
degrees of freedom. - .mode ⇒ Object
-
.pdf(x, n, m) ⇒ Object
F Distribution (Ruby) -- Probability Density Function.
-
.q(x, n, m) ⇒ Object
Upper cumulative function.
-
.quantile(probability, n, m) ⇒ Object
(also: p_value)
Return the F value corresponding to
probability
with degrees of freedomn
andm
. - .skewness ⇒ Object
Methods included from MathExtension
beta, binomial_coefficient, binomial_coefficient_gamma, binomial_coefficient_multiplicative, erfc_e, exact_regularized_beta, exp_err, factorial, fast_factorial, gammq, incomplete_beta, incomplete_gamma, lbeta, logbeta, loggamma, permutations, regularized_beta, rising_factorial, unnormalized_incomplete_gamma
Class Method Details
.cdf(x, n, m) ⇒ Object
Cumulative Distribution Function.
44 45 46 47 48 |
# File 'lib/distribution/f/ruby.rb', line 44 def cdf(x, n, m) x = x.to_f xx = (x * n).to_f / (x * n + m).to_f regularized_beta(xx, n / 2.0, m / 2.0) end |
.entropy ⇒ Object
111 112 |
# File 'lib/distribution/f/ruby.rb', line 111 def entropy end |
.kurtosis ⇒ Object
108 109 |
# File 'lib/distribution/f/ruby.rb', line 108 def kurtosis end |
.mean ⇒ Float
Return the corresponding F value for a p-value y
with n
and m
degrees of freedom.
99 100 |
# File 'lib/distribution/f/ruby.rb', line 99 def mean end |
.mode ⇒ Object
102 103 |
# File 'lib/distribution/f/ruby.rb', line 102 def mode end |
.pdf(x, n, m) ⇒ Object
F Distribution (Ruby) -- Probability Density Function
35 36 37 38 39 40 41 |
# File 'lib/distribution/f/ruby.rb', line 35 def pdf(x, n, m) x = x.to_f numerator = ((n * x)**n * (m**m)) / (n * x + m)**(n + m) denominator = x * Math.beta(n / 2.0, m / 2.0) Math.sqrt(numerator) / denominator end |
.q(x, n, m) ⇒ Object
Upper cumulative function.
If cdf(x, n, m) = p, then q(x, n, m) = 1 - p
53 54 55 |
# File 'lib/distribution/f/ruby.rb', line 53 def q(x, n, m) 1.0 - cdf(x, n, m) end |
.quantile(probability, n, m) ⇒ Object Also known as: p_value
Return the F value corresponding to probability
with degrees of
freedom n
and m
.
If x = quantile(p, n, m), then cdf(x, n, m) = p.
Taken from: https://github.com/JuliaLang/Rmath-julia/blob/master/src/qf.c
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/distribution/f/ruby.rb', line 64 def quantile(probability, n, m) return Float::NAN if n <= 0.0 || m <= 0.0 if n == Float::INFINITY || n == -Float::INFINITY || m == Float::INFINITY || m == -Float::INFINITY return 1.0 end if n <= m && m > 4e5 return Distribution::ChiSquare.p_value(probability, n) / n.to_f elsif n > 4e5 # thus n > m return m.to_f / Distribution::ChiSquare.p_value(1.0 - probability, m) else # O problema está aqui. tmp = Distribution::Beta.p_value(1.0 - probability, m.to_f / 2, n.to_f / 2) value = (1.0 / tmp - 1.0) * (m.to_f / n.to_f) return value.nan? ? Float::NAN : value end end |
.skewness ⇒ Object
105 106 |
# File 'lib/distribution/f/ruby.rb', line 105 def skewness end |