statistics2 0.54
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +12 -0
- data/Manifest.txt +15 -0
- data/README.rdoc +29 -0
- data/Rakefile +41 -0
- data/examples/mklist.rb +18 -0
- data/examples/show.rb +12 -0
- data/ext/extconf.rb +2 -0
- data/ext/statistics2.c +848 -0
- data/lib/statistics2.rb +617 -0
- data/lib/statistics2/no_ext.rb +8 -0
- data/lib/statistics2/version.rb +3 -0
- data/statistics2.gemspec +35 -0
- data/test/sample_tbl.rb +134 -0
- data/test/test_ext.rb +53 -0
- data/test/test_inv.rb +57 -0
- metadata +84 -0
data/statistics2.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{statistics2}
|
5
|
+
s.version = "0.54"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Brendan Ribera", "Shin-ichiro Hara"]
|
9
|
+
s.date = %q{2010-01-26}
|
10
|
+
s.description = %q{Statistics2 is a module that provides normal, Chi-square, t- and F- probability distributions for Ruby. It is a fork/continuation of Shin-ichiro Hara's original code. It can provides a native, compiled extension and a pure Ruby implementation.}
|
11
|
+
s.email = ["brendan.ribera@gmail.com", "sinara@blade.nagaokaut.ac.jp"]
|
12
|
+
s.extensions = ["ext/extconf.rb"]
|
13
|
+
s.extra_rdoc_files = ["Manifest.txt"]
|
14
|
+
s.files = ["History.rdoc", "Manifest.txt", "README.rdoc", "Rakefile", "examples/mklist.rb", "examples/show.rb", "ext/extconf.rb", "ext/statistics2.c", "lib/statistics2.rb", "lib/statistics2/no_ext.rb", "lib/statistics2/version.rb", "statistics2.gemspec", "test/sample_tbl.rb", "test/test_ext.rb", "test/test_inv.rb"]
|
15
|
+
s.homepage = %q{http://github.com/abscondment/statistics2}
|
16
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib", "ext"]
|
18
|
+
s.rubyforge_project = %q{statistics2}
|
19
|
+
s.rubygems_version = %q{1.3.5}
|
20
|
+
s.summary = %q{Statistical Distributions for Ruby. Based on Shin-ichiro Hara's original library, updated for Ruby 1.9}
|
21
|
+
s.test_files = ["test/test_ext.rb", "test/test_inv.rb"]
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_development_dependency(%q<hoe>, [">= 2.4.0"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<hoe>, [">= 2.4.0"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<hoe>, [">= 2.4.0"])
|
34
|
+
end
|
35
|
+
end
|
data/test/sample_tbl.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$test ||= false
|
3
|
+
if $test
|
4
|
+
def nop(*a); ""; end
|
5
|
+
alias _sprintf nop
|
6
|
+
alias _printf nop
|
7
|
+
alias _puts nop
|
8
|
+
else
|
9
|
+
alias _sprintf sprintf
|
10
|
+
alias _printf printf
|
11
|
+
alias _puts puts
|
12
|
+
end
|
13
|
+
|
14
|
+
def norm_line(x, n)
|
15
|
+
s = sprintf("%1.1f|", x)
|
16
|
+
(0.00).step(0.09, 0.01) do |y|
|
17
|
+
s << _sprintf(" %1.#{n}f", yield(x + y))
|
18
|
+
end
|
19
|
+
s
|
20
|
+
end
|
21
|
+
|
22
|
+
def norm_tbl(s, e, ln = nil, tn = nil, &b)
|
23
|
+
n = 4
|
24
|
+
unless ln
|
25
|
+
_printf(" " + (" "*(n-1) + "%1.2f")*10 + "\n", * (0..9).map {|x| x*0.01})
|
26
|
+
end
|
27
|
+
i = 0
|
28
|
+
(s.to_f).step(e.to_f, 0.1) do |x|
|
29
|
+
next if ln && ln.to_i != i+1
|
30
|
+
_puts norm_line(x, n, &b)
|
31
|
+
i += 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def chi2_tbl(ln = nil, tn = nil)
|
36
|
+
pers = [0.995, 0.99, 0.975, 0.95, 0.05, 0.025, 0.01, 0.005]
|
37
|
+
arbi = (1..30).to_a + [40, 60, 80, 100]
|
38
|
+
form = " %7.5f"
|
39
|
+
unless ln
|
40
|
+
_printf(" "); pers.each do |a|; _printf(form, a); end; _puts
|
41
|
+
end
|
42
|
+
arbi.each_with_index do |n, i|
|
43
|
+
next if ln && ln.to_i != i+1
|
44
|
+
_printf("%4d|", n) unless tn
|
45
|
+
pers.each_with_index do |a, j|
|
46
|
+
next if tn && tn.to_i != j+1
|
47
|
+
form = case n
|
48
|
+
when 1; a >= 0.95 ? " %.4e" : " %6.3f"
|
49
|
+
when 2..5; a >= 0.95 ? " %7.5f" : " %7.3f"
|
50
|
+
when 6..24; " %7.3f"
|
51
|
+
else; " %7.2f" # 26..100
|
52
|
+
end
|
53
|
+
_printf(form, yield(n, a))
|
54
|
+
end
|
55
|
+
_puts
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def t_tbl(ln = nil, tn = nil)
|
60
|
+
pers = [0.5, 0.4, 0.3, 0.2, 0.1, 0.05, 0.02, 0.01, 0.001]
|
61
|
+
arbi = (1..30).to_a + [40, 60, 120]#, 9999]
|
62
|
+
form = " %7.3f"
|
63
|
+
unless ln
|
64
|
+
_printf(" "); pers.each do |a|; _printf(form, a); end; _puts
|
65
|
+
end
|
66
|
+
arbi.each_with_index do |n, i|
|
67
|
+
next if ln && ln.to_i != i+1
|
68
|
+
_printf("%4d|", n) unless tn
|
69
|
+
pers.each_with_index do |a, j|
|
70
|
+
next if tn && tn.to_i != j+1
|
71
|
+
_printf(form, yield(n, a))
|
72
|
+
end
|
73
|
+
_puts
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def f_tbl(a, k1 = nil, k2 = nil)
|
78
|
+
arbi1 = (1..10).to_a + [12, 15, 20, 24, 30, 40, 60, 120]#, 9999]
|
79
|
+
arbi2 = (1..30).to_a + [40, 60, 120]#, 9999]
|
80
|
+
unless k1
|
81
|
+
_printf(" "); arbi1.each do |n1|; _printf(" %4d", n1); end; _puts
|
82
|
+
end
|
83
|
+
arbi2.each do |n2|
|
84
|
+
form = n2 == 1 ? " %4d" : n2 == 2 ? " %4.1f" : " %4.2f"
|
85
|
+
next if k2 && k2.to_i != n2
|
86
|
+
_printf("%4d|", n2) unless k2
|
87
|
+
arbi1.each do |n1|
|
88
|
+
next if k1 && k1.to_i != n1
|
89
|
+
_printf(form, yield(n1, n2, a.to_f))
|
90
|
+
end
|
91
|
+
_puts
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def show_tbl(mod, dist, *opts)
|
96
|
+
case dist
|
97
|
+
when nil, "norm"
|
98
|
+
norm_tbl(0.0, 3.1, *opts) do |x|
|
99
|
+
mod.normal___x(x)
|
100
|
+
end
|
101
|
+
when "chi", "chi2"
|
102
|
+
chi2_tbl(*opts) do |n, x|
|
103
|
+
mod.pchi2_x(n, x)
|
104
|
+
end
|
105
|
+
when "t"
|
106
|
+
t_tbl(*opts) do |n, x|
|
107
|
+
mod.ptx__x(n, x)
|
108
|
+
end
|
109
|
+
when "f"
|
110
|
+
f_tbl(*opts) do |n1, n2, a|
|
111
|
+
mod.pf_x(n1, n2, a)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
if $0 == __FILE__
|
118
|
+
if ARGV.empty?
|
119
|
+
puts "-- This script makes tables of distributions"
|
120
|
+
puts "Example:"
|
121
|
+
puts " #$0 norm"
|
122
|
+
puts " #$0 chi2"
|
123
|
+
puts " #$0 t"
|
124
|
+
puts " #$0 f 0.01"
|
125
|
+
exit
|
126
|
+
end
|
127
|
+
|
128
|
+
$:.unshift File.dirname(__FILE__)
|
129
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
130
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'ext')
|
131
|
+
|
132
|
+
require 'statistics2'
|
133
|
+
show_tbl(Statistics2, *ARGV)
|
134
|
+
end
|
data/test/test_ext.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'ext')
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
+
|
5
|
+
$test = true
|
6
|
+
|
7
|
+
require 'test/unit' unless defined?(Hoe)
|
8
|
+
require 'sample_tbl'
|
9
|
+
|
10
|
+
require 'statistics2.so'
|
11
|
+
$mod = Statistics2
|
12
|
+
|
13
|
+
|
14
|
+
# Request extension to be skipped.
|
15
|
+
module Statistics20
|
16
|
+
NO_EXT = true
|
17
|
+
end
|
18
|
+
eval(File.read('lib/statistics2.rb').gsub(/Statistics2/, 'Statistics20'))
|
19
|
+
$mod0 = Statistics20
|
20
|
+
|
21
|
+
class T_Statistics2 < Test::Unit::TestCase
|
22
|
+
|
23
|
+
def test_normal
|
24
|
+
norm_tbl(0.0, 3.1) do |x|
|
25
|
+
a, b = $mod.normal___x(x), $mod0.normal___x(x)
|
26
|
+
assert_in_delta a, b, 0.000001
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_chi
|
31
|
+
chi2_tbl() do |n, x|
|
32
|
+
a, b = $mod.pchi2_x(n, x), $mod0.pchi2_x(n, x)
|
33
|
+
assert_in_delta a/b, 1.0, 0.01
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_t
|
38
|
+
t_tbl() do |n, x|
|
39
|
+
a, b = $mod.ptx__x(n, x), $mod.ptx__x(n, x)
|
40
|
+
assert_in_delta a, b, 0.001
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_f
|
45
|
+
[0.01, 0.025, 0.05].each do |opt|
|
46
|
+
f_tbl(opt) do |n1, n2, y|
|
47
|
+
a, b = $mod.pf_x(n1, n2, y), $mod0.pf_x(n1, n2, y)
|
48
|
+
assert_in_delta a/b, 1.0, 0.01
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/test/test_inv.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'ext')
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
+
|
5
|
+
$test = true
|
6
|
+
|
7
|
+
require 'test/unit' unless defined?(Hoe)
|
8
|
+
require 'sample_tbl'
|
9
|
+
require 'lib/statistics2'
|
10
|
+
|
11
|
+
class T_Statistics2 < Test::Unit::TestCase
|
12
|
+
$mod = Statistics2
|
13
|
+
|
14
|
+
def inv(s); "p" + s; end
|
15
|
+
|
16
|
+
def test_inv_normal
|
17
|
+
delta = 1.0e-6
|
18
|
+
meth = "normal___x"
|
19
|
+
norm_tbl(0.00001, 4.0) do |x|
|
20
|
+
pr = $mod.send(meth, x)
|
21
|
+
x0 = $mod.send(inv(meth), pr)
|
22
|
+
assert_in_delta x0/x, 1.0, delta
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_inv_chi
|
27
|
+
delta = 1.0e-4
|
28
|
+
meth = "chi2_x"
|
29
|
+
chi2_tbl() do |n, pr|
|
30
|
+
x = $mod.send(inv(meth), n, pr)
|
31
|
+
pr0 = $mod.send(meth, n, x)
|
32
|
+
assert_in_delta pr0/pr, 1.0, delta
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_inv_t
|
37
|
+
delta = 1.0e-3
|
38
|
+
meth = "tx__x"
|
39
|
+
t_tbl() do |n, pr|
|
40
|
+
x = $mod.send(inv(meth), n, pr)
|
41
|
+
pr0 = $mod.send(meth, n, x)
|
42
|
+
assert_in_delta pr0/pr, 1.0, delta
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_inv_f
|
47
|
+
delta = 1.0e-3
|
48
|
+
meth = "f_x"
|
49
|
+
[0.01, 0.025, 0.05].each do |opt|
|
50
|
+
f_tbl(opt) do |n1, n2, pr|
|
51
|
+
x = $mod.send(inv(meth), n1, n2, pr)
|
52
|
+
pr0 = $mod.send(meth, n1, n2, x)
|
53
|
+
assert_in_delta pr0/pr, 1.0, delta
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: statistics2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.54"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brendan Ribera
|
8
|
+
- Shin-ichiro Hara
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2010-01-26 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: hoe
|
18
|
+
type: :development
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.4.0
|
25
|
+
version:
|
26
|
+
description: Statistics2 is a module that provides normal, Chi-square, t- and F- probability distributions for Ruby. It is a fork/continuation of Shin-ichiro Hara's original code. It provides a native, compiled extension and a pure Ruby implementation.
|
27
|
+
email:
|
28
|
+
- brendan.ribera@gmail.com
|
29
|
+
- sinara@blade.nagaokaut.ac.jp
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions:
|
33
|
+
- ext/extconf.rb
|
34
|
+
extra_rdoc_files:
|
35
|
+
- Manifest.txt
|
36
|
+
files:
|
37
|
+
- History.rdoc
|
38
|
+
- Manifest.txt
|
39
|
+
- README.rdoc
|
40
|
+
- Rakefile
|
41
|
+
- examples/mklist.rb
|
42
|
+
- examples/show.rb
|
43
|
+
- ext/extconf.rb
|
44
|
+
- ext/statistics2.c
|
45
|
+
- lib/statistics2.rb
|
46
|
+
- lib/statistics2/no_ext.rb
|
47
|
+
- lib/statistics2/version.rb
|
48
|
+
- statistics2.gemspec
|
49
|
+
- test/sample_tbl.rb
|
50
|
+
- test/test_ext.rb
|
51
|
+
- test/test_inv.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/abscondment/statistics2
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options:
|
58
|
+
- --main
|
59
|
+
- README.rdoc
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
- ext
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project: statistics2
|
78
|
+
rubygems_version: 1.3.5
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Statistical Distributions for Ruby. Based on Shin-ichiro Hara's original library, updated for Ruby 1.9
|
82
|
+
test_files:
|
83
|
+
- test/test_ext.rb
|
84
|
+
- test/test_inv.rb
|