Module: Statistics2
- Defined in:
- lib/statistics2.rb
Overview
statistics2.rb
distributions of statistics
by Shin-ichiro HARA
URL: blade.nagaokaut.ac.jp/~sinara/ruby/math/
2003.09.25
Ref:
[1] http://www.matsusaka-u.ac.jp/~okumura/algo/
[2] http://www5.airnet.ne.jp/tomy/cpro/sslib11.htm
Constant Summary collapse
- SQ2PI =
:nodoc:
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
Class Method Summary collapse
- .bin_x(n, p, x) ⇒ Object
- .bindens(n, p, x) ⇒ Object
- .bindist(n, p, x) ⇒ Object
-
.binX_(n, p, x) ⇒ Object
discrete distributions.
-
.chi2_x(n, x) ⇒ Object
chi2-distribution.
-
.chi2dist(n, x) ⇒ Object
chi-square-distribution interface.
- .chi2X_(n, x) ⇒ Object
-
.f_x(n1, n2, x) ⇒ Object
F-distribution.
-
.fdist(n1, n2, f) ⇒ Object
F-distribution interface.
- .fX_(n1, n2, x) ⇒ Object
- .normal___x(z) ⇒ Object
- .normal__X_(z) ⇒ Object
-
.normaldist(z) ⇒ Object
normal-distribution interface.
- .normalx__x(z) ⇒ Object
-
.normalxXX_(z) ⇒ Object
normal-distribution.
-
.pchi2_x(n, y) ⇒ Object
inverse of chi2-distribution.
- .pchi2dist(n, y) ⇒ Object
- .pchi2X_(n, y) ⇒ Object
-
.pf_x(n1, n2, x) ⇒ Object
inverse of F-distribution.
- .pfdist(n1, n2, y) ⇒ Object
- .pfX_(n1, n2, x) ⇒ Object
- .pnormal___x(y) ⇒ Object
- .pnormal__X_(y) ⇒ Object
- .pnormaldist(y) ⇒ Object
- .pnormalx__x(y) ⇒ Object
-
.pnormalxXX_(z) ⇒ Object
inverse of normal-distribution.
- .poisson_x(m, x) ⇒ Object
- .poissondens(m, x) ⇒ Object
- .poissondist(m, x) ⇒ Object
- .poissonX_(m, x) ⇒ Object
- .pt___x(n, y) ⇒ Object
- .pt__X_(n, y) ⇒ Object
- .ptdist(n, y) ⇒ Object
-
.ptx__x(n, y) ⇒ Object
inverse of t-distribution.
- .ptxXX_(n, y) ⇒ Object
- .t___x(n, x) ⇒ Object
- .t__X_(n, x) ⇒ Object
-
.tdist(n, t) ⇒ Object
t-distribution interface.
-
.tx__x(n, x) ⇒ Object
t-distribution.
- .txXX_(n, x) ⇒ Object
Class Method Details
.bin_x(n, p, x) ⇒ Object
514 |
# File 'lib/statistics2.rb', line 514 def bin_x(n, p, x); bindist(n, 1.0 - p, n - x); end |
.bindens(n, p, x) ⇒ Object
435 436 437 438 439 |
# File 'lib/statistics2.rb', line 435 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
441 442 443 444 445 |
# File 'lib/statistics2.rb', line 441 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
513 |
# File 'lib/statistics2.rb', line 513 def binX_(n, p, x); bindist(n, p, x); end |
.chi2_x(n, x) ⇒ Object
chi2-distribution
477 |
# File 'lib/statistics2.rb', line 477 def chi2_x(n, x); 1.0 - chi2dist(n, x); end |
.chi2dist(n, x) ⇒ Object
chi-square-distribution interface
215 |
# File 'lib/statistics2.rb', line 215 def chi2dist(n, x); 1.0 - q_chi2(n, x); end |
.chi2X_(n, x) ⇒ Object
478 |
# File 'lib/statistics2.rb', line 478 def chi2X_(n, x); chi2dist(n, x); end |
.f_x(n1, n2, x) ⇒ Object
F-distribution
503 |
# File 'lib/statistics2.rb', line 503 def f_x(n1, n2, x); 1.0 - fdist(n1, n2, x); end |
.fdist(n1, n2, f) ⇒ Object
F-distribution interface
409 |
# File 'lib/statistics2.rb', line 409 def fdist(n1, n2, f); 1.0 - q_f(n1, n2, f); end |
.fX_(n1, n2, x) ⇒ Object
504 |
# File 'lib/statistics2.rb', line 504 def fX_(n1, n2, x); fdist(n1, n2, x); end |
.normal___x(z) ⇒ Object
464 |
# File 'lib/statistics2.rb', line 464 def normal___x(z); 1.0 - normaldist(z); end |
.normal__X_(z) ⇒ Object
463 |
# File 'lib/statistics2.rb', line 463 def normal__X_(z); normaldist(z) - 0.5; end |
.normaldist(z) ⇒ Object
normal-distribution interface
137 138 139 |
# File 'lib/statistics2.rb', line 137 def normaldist(z) p_nor(z) end |
.normalx__x(z) ⇒ Object
465 |
# File 'lib/statistics2.rb', line 465 def normalx__x(z); 2.0 - normaldist(z) * 2.0; end |
.normalxXX_(z) ⇒ Object
normal-distribution
462 |
# File 'lib/statistics2.rb', line 462 def normalxXX_(z); normaldist(z); end |
.pchi2_x(n, y) ⇒ Object
inverse of chi2-distribution
482 |
# File 'lib/statistics2.rb', line 482 def pchi2_x(n, y); pchi2dist(n, 1.0 - y); end |
.pchi2dist(n, y) ⇒ Object
216 |
# File 'lib/statistics2.rb', line 216 def pchi2dist(n, y); pchi2(n, 1.0 - y); end |
.pchi2X_(n, y) ⇒ Object
483 |
# File 'lib/statistics2.rb', line 483 def pchi2X_(n, y); pchi2dist(n, y); end |
.pf_x(n1, n2, x) ⇒ Object
inverse of F-distribution
508 |
# File 'lib/statistics2.rb', line 508 def pf_x(n1, n2, x); pfdist(n1, n2, 1.0 - x); end |
.pfdist(n1, n2, y) ⇒ Object
410 |
# File 'lib/statistics2.rb', line 410 def pfdist(n1, n2, y); pf(1.0 - y, n1, n2); end |
.pfX_(n1, n2, x) ⇒ Object
509 |
# File 'lib/statistics2.rb', line 509 def pfX_(n1, n2, x); pfdist(n1, n2, x); end |
.pnormal___x(y) ⇒ Object
471 |
# File 'lib/statistics2.rb', line 471 def pnormal___x(y); pnormalxXX_(1.0 - y); end |
.pnormal__X_(y) ⇒ Object
470 |
# File 'lib/statistics2.rb', line 470 def pnormal__X_(y); pnormalxXX_(y + 0.5); end |
.pnormaldist(y) ⇒ Object
141 142 143 |
# File 'lib/statistics2.rb', line 141 def pnormaldist(y) pnorm(y) end |
.pnormalx__x(y) ⇒ Object
472 |
# File 'lib/statistics2.rb', line 472 def pnormalx__x(y); pnormalxXX_(1.0 - y/2.0); end |
.pnormalxXX_(z) ⇒ Object
inverse of normal-distribution
469 |
# File 'lib/statistics2.rb', line 469 def pnormalxXX_(z); pnormaldist(z); end |
.poisson_x(m, x) ⇒ Object
518 |
# File 'lib/statistics2.rb', line 518 def poisson_x(m, x); 1.0 - poissondist(m, x-1); end |
.poissondens(m, x) ⇒ Object
447 448 449 450 451 |
# File 'lib/statistics2.rb', line 447 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
453 454 455 456 457 |
# File 'lib/statistics2.rb', line 453 def poissondist(m, x) (0..x).inject(0.0) do |s, k| s + poissondens(m, k) end end |
.poissonX_(m, x) ⇒ Object
517 |
# File 'lib/statistics2.rb', line 517 def poissonX_(m, x); poissondist(m, x); end |
.pt___x(n, y) ⇒ Object
498 |
# File 'lib/statistics2.rb', line 498 def pt___x(n, y); ptdist(n, 1.0 - y); end |
.pt__X_(n, y) ⇒ Object
497 |
# File 'lib/statistics2.rb', line 497 def pt__X_(n, y); ptdist(n, 0.5 + y); end |
.ptdist(n, y) ⇒ Object
302 303 304 305 306 307 308 |
# File 'lib/statistics2.rb', line 302 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
inverse of t-distribution
495 |
# File 'lib/statistics2.rb', line 495 def ptx__x(n, y); ptdist(n, 1.0 - y / 2.0); end |
.ptxXX_(n, y) ⇒ Object
496 |
# File 'lib/statistics2.rb', line 496 def ptxXX_(n, y); ptdist(n, y); end |
.t___x(n, x) ⇒ Object
491 |
# File 'lib/statistics2.rb', line 491 def t___x(n, x); 1.0 - tdist(n, x); end |
.t__X_(n, x) ⇒ Object
490 |
# File 'lib/statistics2.rb', line 490 def t__X_(n, x); tdist(n, x) - 0.5; end |
.tdist(n, t) ⇒ Object
t-distribution interface
301 |
# File 'lib/statistics2.rb', line 301 def tdist(n, t); p_t(n, t); end |
.tx__x(n, x) ⇒ Object
t-distribution
488 |
# File 'lib/statistics2.rb', line 488 def tx__x(n, x); 2.0 - tdist(n, x) * 2.0; end |
.txXX_(n, x) ⇒ Object
489 |
# File 'lib/statistics2.rb', line 489 def txXX_(n, x); tdist(n, x); end |