Module: Statistics2
- Defined in:
- lib/statistics2.rb,
lib/statistics2/no_ext.rb,
lib/statistics2/version.rb,
ext/statistics2.c
Overview
Indicate that we should skip loading of the C extension.
Constant Summary collapse
- SQ2PI =
Math.sqrt(2 * Math::PI)
- LOG_2PI =
Gamma function
Math.log(2 * Math::PI)
- N =
8
- B0 =
1.0
- B1 =
-1.0 / 2.0
- B2 =
1.0 / 6.0
- B4 =
-1.0 / 30.0
- B6 =
1.0 / 42.0
- B8 =
-1.0 / 30.0
- B10 =
5.0 / 66.0
- B12 =
-691.0 / 2730.0
- B14 =
7.0 / 6.0
- B16 =
-3617.0 / 510.0
- NO_EXT =
true
- VERSION =
0.54
Class Method Summary collapse
- .bin_x(n, p, x) ⇒ Object
-
.bindens(n, p, x) ⇒ Object
discrete distributions.
- .bindist(n, p, x) ⇒ Object
-
.binX_(n, p, x) ⇒ Object
discrete distributions.
-
.chi2_x(n, x) ⇒ Object
chi-square-distribution.
-
.chi2dist(n, x) ⇒ Object
inverse of chi-square-distribution.
-
.chi2X_(n, x) ⇒ Object
Returns the integral of Chi-squared distribution with n degrees of freedom over [0, x].
-
.f_x(n1, n2, x) ⇒ Object
Returns the integral of F-distribution with n1 and n2 degrees of freedom over [x, Infty).
-
.fdist(n1, n2, f) ⇒ Object
F-distribution.
-
.fX_(n1, n2, x) ⇒ Object
Returns the integral of F-distribution with n1 and n2 degrees of freedom over [0, x].
-
.metaclass ⇒ Object
Easy access to our singleton.
-
.normal___x(z) ⇒ Object
Returns the integral of normal distribution over [x, Infty).
-
.normal__X_(z) ⇒ Object
Returns the integral of normal distribution over [0, x].
-
.normaldist(z) ⇒ Object
normal-distribution.
-
.normalx__x(z) ⇒ Object
Returns the integral of normal distribution over (-Infty, -x] + [x, Infty).
-
.normalxXX_(z) ⇒ Object
Returns the integral of normal distribution over (-Infty, x].
-
.pchi2_x(n, y) ⇒ Object
Return the P-value of the corresponding integral.
-
.pchi2dist(n, y) ⇒ Object
Returns the P-value of chi2dist().
-
.pchi2X_(n, y) ⇒ Object
Return the P-value of the corresponding integral.
-
.pf_x(n1, n2, x) ⇒ Object
Return the P-value of the corresponding integral.
-
.pfdist(n1, n2, y) ⇒ Object
inverse of F-distribution.
-
.pfX_(n1, n2, x) ⇒ Object
Return the P-value of the corresponding integral.
-
.pnormal___x(y) ⇒ Object
Return the P-value of the corresponding integral.
-
.pnormal__X_(y) ⇒ Object
Return the P-value of the corresponding integral.
-
.pnormaldist(y) ⇒ Object
inverse of normal-distribution.
-
.pnormalx__x(y) ⇒ Object
Return the P-value of the corresponding integral.
-
.pnormalxXX_(z) ⇒ Object
Return the P-value of the corresponding integral.
- .poisson_x(m, x) ⇒ Object
- .poissondens(m, x) ⇒ Object
- .poissondist(m, x) ⇒ Object
- .poissonX_(m, x) ⇒ Object
-
.pt___x(n, y) ⇒ Object
Return the P-value of the corresponding integral.
-
.pt__X_(n, y) ⇒ Object
Return the P-value of the corresponding integral.
-
.ptdist(n, y) ⇒ Object
inverse of t-distribution.
-
.ptx__x(n, y) ⇒ Object
Return the P-value of the corresponding integral.
-
.ptxXX_(n, y) ⇒ Object
Return the P-value of the corresponding integral.
-
.t___x(n, x) ⇒ Object
Returns the integral of t-distribution with n degrees of freedom over [x, Infty).
-
.t__X_(n, x) ⇒ Object
Returns the integral of t-distribution with n degrees of freedom over [0, x].
-
.tdist(n, t) ⇒ Object
t-distribution.
-
.tx__x(n, x) ⇒ Object
Returns the integral of normal distribution with n degrees of freedom over (-Infty, -x] + [x, Infty).
-
.txXX_(n, x) ⇒ Object
Returns the integral of t-distribution with n degrees of freedom over (-Infty, x].
Class Method Details
.bin_x(n, p, x) ⇒ Object
730 |
# File 'ext/statistics2.c', line 730 def bin_x(n, p, x); bindist(n, 1.0 - p, n - x); end |
.bindens(n, p, x) ⇒ Object
discrete distributions
709 710 711 712 713 |
# File 'ext/statistics2.c', line 709 def bindens(n, p, x) p = p.to_f q = 1.0 - p combi(n, x) * p**x * q**(n - x) end |
.bindist(n, p, x) ⇒ Object
716 717 718 719 720 |
# File 'ext/statistics2.c', line 716 def bindist(n, p, x) (0..x).inject(0.0) do |s, k| s + bindens(n, p, k) end end |
.binX_(n, p, x) ⇒ Object
discrete distributions
596 |
# File 'lib/statistics2.rb', line 596 def binX_(n, p, x); bindist(n, p, x); end |
.chi2_x(n, x) ⇒ Object
chi-square-distribution
521 |
# File 'lib/statistics2.rb', line 521 def chi2_x(n, x); 1.0 - chi2dist(n, x); end |
.chi2dist(n, x) ⇒ Object
inverse of chi-square-distribution
233 |
# File 'lib/statistics2.rb', line 233 def chi2dist(n, x); 1.0 - q_chi2(n, x); end |
.chi2X_(n, x) ⇒ Object
Returns the integral of Chi-squared distribution with n degrees of freedom over [0, x].
524 |
# File 'lib/statistics2.rb', line 524 def chi2X_(n, x); chi2dist(n, x); end |
.f_x(n1, n2, x) ⇒ Object
Returns the integral of F-distribution with n1 and n2 degrees of freedom over [x, Infty).
577 |
# File 'lib/statistics2.rb', line 577 def f_x(n1, n2, x); 1.0 - fdist(n1, n2, x); end |
.fdist(n1, n2, f) ⇒ Object
F-distribution
431 |
# File 'lib/statistics2.rb', line 431 def fdist(n1, n2, f); 1.0 - q_f(n1, n2, f); end |
.fX_(n1, n2, x) ⇒ Object
Returns the integral of F-distribution with n1 and n2 degrees of freedom over [0, x].
580 |
# File 'lib/statistics2.rb', line 580 def fX_(n1, n2, x); fdist(n1, n2, x); end |
.metaclass ⇒ Object
Easy access to our singleton
17 |
# File 'lib/statistics2.rb', line 17 def self.; class << self; self; end; end |
.normal___x(z) ⇒ Object
Returns the integral of normal distribution over [x, Infty).
493 |
# File 'lib/statistics2.rb', line 493 def normal___x(z); 1.0 - normaldist(z); end |
.normal__X_(z) ⇒ Object
Returns the integral of normal distribution over [0, x].
490 |
# File 'lib/statistics2.rb', line 490 def normal__X_(z); normaldist(z) - 0.5; end |
.normaldist(z) ⇒ Object
normal-distribution
154 155 156 |
# File 'lib/statistics2.rb', line 154 def normaldist(z) p_nor(z) end |
.normalx__x(z) ⇒ Object
Returns the integral of normal distribution over (-Infty, -x] + [x, Infty).
496 |
# File 'lib/statistics2.rb', line 496 def normalx__x(z); 2.0 - normaldist(z) * 2.0; end |
.normalxXX_(z) ⇒ Object
Returns the integral of normal distribution over (-Infty, x].
487 |
# File 'lib/statistics2.rb', line 487 def normalxXX_(z); normaldist(z); end |
.pchi2_x(n, y) ⇒ Object
Return the P-value of the corresponding integral.
532 |
# File 'lib/statistics2.rb', line 532 def pchi2_x(n, y); pchi2dist(n, 1.0 - y); end |
.pchi2dist(n, y) ⇒ Object
Returns the P-value of chi2dist().
236 |
# File 'lib/statistics2.rb', line 236 def pchi2dist(n, y); pchi2(n, 1.0 - y); end |
.pchi2X_(n, y) ⇒ Object
Return the P-value of the corresponding integral.
535 |
# File 'lib/statistics2.rb', line 535 def pchi2X_(n, y); pchi2dist(n, y); end |
.pf_x(n1, n2, x) ⇒ Object
Return the P-value of the corresponding integral.
587 |
# File 'lib/statistics2.rb', line 587 def pf_x(n1, n2, x); pfdist(n1, n2, 1.0 - x); end |
.pfdist(n1, n2, y) ⇒ Object
inverse of F-distribution
434 |
# File 'lib/statistics2.rb', line 434 def pfdist(n1, n2, y); pf(1.0 - y, n1, n2); end |
.pfX_(n1, n2, x) ⇒ Object
Return the P-value of the corresponding integral.
590 |
# File 'lib/statistics2.rb', line 590 def pfX_(n1, n2, x); pfdist(n1, n2, x); end |
.pnormal___x(y) ⇒ Object
Return the P-value of the corresponding integral.
510 |
# File 'lib/statistics2.rb', line 510 def pnormal___x(y); pnormalxXX_(1.0 - y); end |
.pnormal__X_(y) ⇒ Object
Return the P-value of the corresponding integral.
507 |
# File 'lib/statistics2.rb', line 507 def pnormal__X_(y); pnormalxXX_(y + 0.5); end |
.pnormaldist(y) ⇒ Object
inverse of normal-distribution
159 160 161 |
# File 'lib/statistics2.rb', line 159 def pnormaldist(y) pnorm(y) end |
.pnormalx__x(y) ⇒ Object
Return the P-value of the corresponding integral.
513 |
# File 'lib/statistics2.rb', line 513 def pnormalx__x(y); pnormalxXX_(1.0 - y/2.0); end |
.pnormalxXX_(z) ⇒ Object
Return the P-value of the corresponding integral.
504 |
# File 'lib/statistics2.rb', line 504 def pnormalxXX_(z); pnormaldist(z); end |
.poisson_x(m, x) ⇒ Object
730 |
# File 'ext/statistics2.c', line 730 def poisson_x(m, x); 1.0 - poissondist(m, x-1); end |
.poissondens(m, x) ⇒ Object
737 738 739 740 741 |
# File 'ext/statistics2.c', line 737 def poissondens(m, x) return 0.0 if x < 0 m = m.to_f m ** x * Math::E ** (-m) / perm(x) end |
.poissondist(m, x) ⇒ Object
744 745 746 747 748 |
# File 'ext/statistics2.c', line 744 def poissondist(m, x) (0..x).inject(0.0) do |s, k| s + poissondens(m, k) end end |
.poissonX_(m, x) ⇒ Object
751 |
# File 'ext/statistics2.c', line 751 def poissonX_(m, x); poissondist(m, x); end |
.pt___x(n, y) ⇒ Object
Return the P-value of the corresponding integral.
569 |
# File 'lib/statistics2.rb', line 569 def pt___x(n, y); ptdist(n, 1.0 - y); end |
.pt__X_(n, y) ⇒ Object
Return the P-value of the corresponding integral.
566 |
# File 'lib/statistics2.rb', line 566 def pt__X_(n, y); ptdist(n, 0.5 + y); end |
.ptdist(n, y) ⇒ Object
inverse of t-distribution
324 325 326 327 328 329 330 |
# File 'lib/statistics2.rb', line 324 def ptdist(n, y) if y > 0.5 pt(2.0 - y*2.0, n) else - pt(y*2.0, n) end end |
.ptx__x(n, y) ⇒ Object
Return the P-value of the corresponding integral.
560 |
# File 'lib/statistics2.rb', line 560 def ptx__x(n, y); ptdist(n, 1.0 - y / 2.0); end |
.ptxXX_(n, y) ⇒ Object
Return the P-value of the corresponding integral.
563 |
# File 'lib/statistics2.rb', line 563 def ptxXX_(n, y); ptdist(n, y); end |
.t___x(n, x) ⇒ Object
Returns the integral of t-distribution with n degrees of freedom over [x, Infty).
552 |
# File 'lib/statistics2.rb', line 552 def t___x(n, x); 1.0 - tdist(n, x); end |
.t__X_(n, x) ⇒ Object
Returns the integral of t-distribution with n degrees of freedom over [0, x].
549 |
# File 'lib/statistics2.rb', line 549 def t__X_(n, x); tdist(n, x) - 0.5; end |
.tdist(n, t) ⇒ Object
t-distribution
321 |
# File 'lib/statistics2.rb', line 321 def tdist(n, t); p_t(n, t); end |
.tx__x(n, x) ⇒ Object
Returns the integral of normal distribution with n degrees of freedom over (-Infty, -x] + [x, Infty).
543 |
# File 'lib/statistics2.rb', line 543 def tx__x(n, x); 2.0 - tdist(n, x) * 2.0; end |
.txXX_(n, x) ⇒ Object
Returns the integral of t-distribution with n degrees of freedom over (-Infty, x].
546 |
# File 'lib/statistics2.rb', line 546 def txXX_(n, x); tdist(n, x); end |