rubystats 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9002f153bddfc7d2089ad357dd7eb2ded0580315
4
+ data.tar.gz: 6ee9d7ac4a874ce488f09b13fd52d41b34c26de8
5
+ SHA512:
6
+ metadata.gz: b960257b9ba3aa6bbf0507db971b0a8a069c8baa10c83727b52f94a939b20dbfa52966c74c184b1daebde3f2d53be990237d17cc6248b1dfb394a03d8ad4c933
7
+ data.tar.gz: b42484ba551d47356f2345fe4119a8e81768ccff8d6e40077f5243e4137fddb70230dd66c75e4a3a1db1f78050cc703264ed6803c0ad3cc81b90ac1c2000d198
@@ -0,0 +1,19 @@
1
+ .rvmrc
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ coverage
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ before_script:
5
+ - 'echo ''gem: --no-ri --no-rdoc'' > ~/.gemrc' # skip installing docs for gems
6
+ script: 'bundle exec rake test'
7
+ rvm:
8
+ - 2.0.0
9
+ - 2.1.0
10
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
File without changes
data/Rakefile CHANGED
@@ -1,48 +1,15 @@
1
- # -*- ruby -*-
2
-
3
1
  require 'rubygems'
4
- require 'hoe'
5
- $:.unshift(File.dirname(__FILE__) + "/lib")
6
- require 'rubystats'
7
- #require './lib/rubystats.rb'
8
-
9
- Hoe.new('rubystats', Rubystats::VERSION) do |p|
10
- p.name = "rubystats"
11
- p.author = "Bryan Donovan - http://www.bryandonovan.com"
12
- p.email = "b.dondo+rubyforge@gmail.com"
13
- p.description = "Ruby Stats is a port of the statistics libraries from PHPMath. Probability distributions include binomial, beta, and normal distributions with PDF, CDF and inverse CDF as well as Fisher's Exact Test."
14
- p.summary = "Port of PHPMath to Ruby"
15
- p.url = "http://rubyforge.org/projects/rubystats/"
16
- p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
17
- p.remote_rdoc_dir = '' # Release to root
18
- end
19
-
20
- desc "Run all tests"
21
- task :test do
22
- Rake::TestTask.new("test") do |t|
23
- t.test_files = FileList['test/tc*.rb']
24
- t.verbose = false
25
- end
26
- end
27
-
28
- #Use Allison template if available
29
- ALLISON = "/opt/local/lib/ruby/gems/1.8/gems/allison-2.0.3/lib/allison.rb"
2
+ require 'bundler'
3
+ require 'rake'
4
+ require 'rake/testtask'
30
5
 
31
- Rake::RDocTask.new do |rd|
32
- rd.main = "README.txt"
33
- rd.rdoc_dir = "doc"
34
- rd.rdoc_files.include(
35
- "README.txt",
36
- "History.txt",
37
- "Manifest.txt",
38
- "lib/**/*.rb",
39
- "examples/**/*.rb",
40
- "test/**/*.rb")
41
- rd.title = "Rubystats RDoc"
6
+ Bundler::GemHelper.install_tasks
42
7
 
43
- rd.options << '-S' # inline source
8
+ desc 'Default: run the specs and features.'
9
+ task :default => 'test'
44
10
 
45
- rd.template = ALLISON if File.exist?(ALLISON)
46
- end
47
-
48
- # vim: syntax=Ruby
11
+ Rake::TestTask.new('test') do |t|
12
+ t.libs << 'test'
13
+ t.test_files = FileList['test/tc*.rb']
14
+ t.verbose = true
15
+ end
@@ -1,10 +1,12 @@
1
- module Rubystats
2
- VERSION = '0.2.3'
3
- end
4
-
5
1
  require 'rubystats/normal_distribution'
6
2
  require 'rubystats/binomial_distribution'
7
3
  require 'rubystats/beta_distribution'
8
4
  require 'rubystats/fishers_exact_test'
9
5
  require 'rubystats/exponential_distribution'
6
+ require 'rubystats/version'
7
+
8
+ module Rubystats
9
+
10
+ end
11
+
10
12
  include Rubystats
@@ -13,7 +13,7 @@ module Rubystats
13
13
  def initialize(mu=0.0, sigma=1.0)
14
14
  @mean = mu
15
15
  if sigma <= 0.0
16
- return "error"
16
+ raise "error, invalid sigma #{sigma}, should be > 0"
17
17
  end
18
18
  @stdev = sigma
19
19
  @variance = sigma**2
@@ -0,0 +1,3 @@
1
+ module Rubystats
2
+ VERSION = '0.2.4'
3
+ end
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH << File.expand_path("../lib", __FILE__)
2
+ require 'rubystats/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'rubystats'
6
+ s.version = Rubystats::VERSION
7
+ s.summary = ''
8
+ s.description = "Ruby Stats is a port of the statistics libraries from PHPMath. Probability distributions include binomial, beta, and normal distributions with PDF, CDF and inverse CDF as well as Fisher's Exact Test."
9
+
10
+ s.files = `git ls-files`.split("\n")
11
+ s.test_files = `git ls-files -- Appraisals {test,spec,features,gemfiles}/*`.split("\n")
12
+
13
+ s.require_paths = ['lib']
14
+ s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
15
+
16
+ s.authors = ['Ilya Scharrenbroich', 'Bryan Donovan - http://www.bryandonovan.com', 'Phillip Baker']
17
+
18
+ s.homepage = 'https://github.com/phillbaker/rubystats'
19
+
20
+ s.add_development_dependency("minitest", ">= 4.2", "< 5.0")
21
+ s.add_development_dependency("hoe", ">= 1.7.0")
22
+ end
23
+
@@ -1,51 +1,51 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
- require 'test/unit'
2
+ require 'minitest/autorun'
3
3
  require 'rubystats/beta_distribution'
4
4
 
5
- class TestBeta < Test::Unit::TestCase
6
- def test_simple
7
- p = 12
8
- q = 59
9
- beta = Rubystats::BetaDistribution.new(p,q)
10
- assert_equal("0.169014084507042", beta.mean.to_s)
11
- assert_equal("0.0441664031038187", beta.standard_deviation.to_s)
12
- assert_equal("6.26075815849967", beta.pdf(0.2).to_s)
13
- assert_equal("0.999999997766913", beta.cdf(0.50).to_s)
14
- assert_equal("0.102003194113565", beta.icdf(0.05).to_s)
5
+ class TestBeta < MiniTest::Unit::TestCase
6
+ def test_simple
7
+ p = 12
8
+ q = 59
9
+ beta = Rubystats::BetaDistribution.new(p,q)
10
+ assert_equal("0.16901408450704225", beta.mean.to_s)
11
+ assert_equal("0.04416640310381873", beta.standard_deviation.to_s)
12
+ assert_equal("6.260758158499666", beta.pdf(0.2).to_s)
13
+ assert_equal("0.9999999977669126", beta.cdf(0.50).to_s)
14
+ assert_equal("0.10200319411356515", beta.icdf(0.05).to_s)
15
+
16
+ x_vals = [0.1, 0.15, 0.2, 0.25, 0.3, 0.35]
17
+ p_vals = beta.pdf(x_vals)
18
+ c_vals = beta.cdf(x_vals)
19
+ expected_pvals = [ 2.83232625227534,
20
+ 8.89978000366836,
21
+ 6.26075815849967,
22
+ 1.72572305993386,
23
+ 0.234475706454223,
24
+ 0.0173700433944934]
25
+ expected_cvals = [0.0440640755091473,
26
+ 0.356009606171447,
27
+ 0.768319101921981,
28
+ 0.956058132801147,
29
+ 0.995358286711105,
30
+ 0.99971672771575]
15
31
 
16
- x_vals = [0.1, 0.15, 0.2, 0.25, 0.3, 0.35]
17
- p_vals = beta.pdf(x_vals)
18
- c_vals = beta.cdf(x_vals)
19
- expected_pvals = [ 2.83232625227534,
20
- 8.89978000366836,
21
- 6.26075815849967,
22
- 1.72572305993386,
23
- 0.234475706454223,
24
- 0.0173700433944934]
25
- expected_cvals = [0.0440640755091473,
26
- 0.356009606171447,
27
- 0.768319101921981,
28
- 0.956058132801147,
29
- 0.995358286711105,
30
- 0.99971672771575]
31
-
32
32
  0.upto(x_vals.size - 1) do |i|
33
33
  assert_in_delta expected_pvals[i], p_vals[i], 0.00000001
34
34
  assert_in_delta expected_cvals[i], c_vals[i], 0.00000001
35
35
  i += 1
36
36
  end
37
37
 
38
- x_vals.each do |x|
39
- cdf = beta.cdf(x)
40
- inv_cdf = beta.icdf(cdf)
41
- assert_in_delta(x, inv_cdf, 0.00000001)
42
- end
43
- end
38
+ x_vals.each do |x|
39
+ cdf = beta.cdf(x)
40
+ inv_cdf = beta.icdf(cdf)
41
+ assert_in_delta(x, inv_cdf, 0.00000001)
42
+ end
43
+ end
44
44
 
45
45
  def test_low_p_and_q_values
46
- p = 1.5
47
- q = 1.0
48
- beta = Rubystats::BetaDistribution.new(p,q)
46
+ p = 1.5
47
+ q = 1.0
48
+ beta = Rubystats::BetaDistribution.new(p,q)
49
49
 
50
50
  #from PHPExcel/PHPMath output
51
51
  expected_icdf_vals = [
@@ -60,41 +60,41 @@ class TestBeta < Test::Unit::TestCase
60
60
  end
61
61
  end
62
62
 
63
- def test_control_limits
64
- trials = 50
65
- alpha = 0.05
66
- p = 10
67
- lcl = get_lower_limit(trials, alpha, p)
68
- ucl = get_upper_limit(trials, alpha, p)
69
- assert_equal("0.112721613414076",lcl.to_s)
70
- assert_equal("0.315596061420013",ucl.to_s)
63
+ def test_control_limits
64
+ trials = 50
65
+ alpha = 0.05
66
+ p = 10
67
+ lcl = get_lower_limit(trials, alpha, p)
68
+ ucl = get_upper_limit(trials, alpha, p)
69
+ assert_equal("0.1127216134140763",lcl.to_s)
70
+ assert_equal("0.3155960614200132",ucl.to_s)
71
71
 
72
- trials = 210
73
- alpha = 0.10
74
- p = 47
75
- lcl = get_lower_limit(trials, alpha, p)
76
- ucl = get_upper_limit(trials, alpha, p)
77
- assert_equal("0.186679485269901",lcl.to_s)
78
- assert_equal("0.264957601783544",ucl.to_s)
79
- end
72
+ trials = 210
73
+ alpha = 0.10
74
+ p = 47
75
+ lcl = get_lower_limit(trials, alpha, p)
76
+ ucl = get_upper_limit(trials, alpha, p)
77
+ assert_equal("0.18667948526990116",lcl.to_s)
78
+ assert_equal("0.2649576017835441",ucl.to_s)
79
+ end
80
80
 
81
- def get_lower_limit(trials,alpha,p)
82
- if p==0
83
- lcl=0
84
- else
85
- q=trials-p+1
86
- bin= Rubystats::BetaDistribution.new(p,q)
87
- lcl=bin.icdf(alpha)
88
- end
89
- return lcl
90
- end
81
+ def get_lower_limit(trials,alpha,p)
82
+ if p==0
83
+ lcl=0
84
+ else
85
+ q=trials-p+1
86
+ bin= Rubystats::BetaDistribution.new(p,q)
87
+ lcl=bin.icdf(alpha)
88
+ end
89
+ return lcl
90
+ end
91
91
 
92
- def get_upper_limit(trials,alpha,p)
93
- q=trials-p
94
- p=p+1
95
- bin= Rubystats::BetaDistribution.new(p,q)
96
- ucl=bin.icdf(1-alpha)
97
- return ucl
98
- end
92
+ def get_upper_limit(trials,alpha,p)
93
+ q=trials-p
94
+ p=p+1
95
+ bin= Rubystats::BetaDistribution.new(p,q)
96
+ ucl=bin.icdf(1-alpha)
97
+ return ucl
98
+ end
99
99
 
100
100
  end
@@ -1,22 +1,22 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
- require 'test/unit'
2
+ require 'minitest/autorun'
3
3
  require 'rubystats/binomial_distribution'
4
4
 
5
- class TestBinomial < Test::Unit::TestCase
6
- def test_simple
7
- t = 100
8
- f = 7
9
- p = 0.05
5
+ class TestBinomial < MiniTest::Unit::TestCase
6
+ def test_simple
7
+ t = 100
8
+ f = 7
9
+ p = 0.05
10
10
 
11
- bin = Rubystats::BinomialDistribution.new(t,p)
12
- cdf = bin.cdf(f)
13
- pdf = bin.pdf(f)
14
- mean = bin.mean
15
- inv_cdf = bin.icdf(cdf)
11
+ bin = Rubystats::BinomialDistribution.new(t,p)
12
+ cdf = bin.cdf(f)
13
+ pdf = bin.pdf(f)
14
+ mean = bin.mean
15
+ inv_cdf = bin.icdf(cdf)
16
16
 
17
- assert_in_delta(0.10602553736479, pdf, 0.00000000000001 )
18
- assert_in_delta(0.87203952137960, cdf, 0.00000000000001)
19
- assert_equal("5.0",mean.to_s)
20
- assert_equal(f,inv_cdf)
21
- end
17
+ assert_in_delta(0.10602553736479, pdf, 0.00000000000001 )
18
+ assert_in_delta(0.87203952137960, cdf, 0.00000000000001)
19
+ assert_equal("5.0",mean.to_s)
20
+ assert_equal(f,inv_cdf)
21
+ end
22
22
  end
@@ -1,8 +1,8 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
- require 'test/unit'
2
+ require 'minitest/autorun'
3
3
  require 'rubystats/exponential_distribution'
4
4
 
5
- class TestExponential < Test::Unit::TestCase
5
+ class TestExponential < MiniTest::Unit::TestCase
6
6
  def test_simple
7
7
  lmbda = 1
8
8
  expd = Rubystats::ExponentialDistribution.new(lmbda)
@@ -16,7 +16,7 @@ class TestExponential < Test::Unit::TestCase
16
16
  rngs = []
17
17
  rngsum = 0
18
18
  n = 5000
19
- n.times do
19
+ n.times do
20
20
  rng = expd.rng
21
21
  rngs << rng
22
22
  rngsum += rng
@@ -1,20 +1,20 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
- require 'test/unit'
2
+ require 'minitest/autorun'
3
3
  require 'rubystats/fishers_exact_test'
4
4
 
5
- class TestFisher < Test::Unit::TestCase
6
- def test_simple
7
- tested1 = 20
8
- tested2 = 30
9
- f1 = 10
10
- f2 = 10
11
- t1 = tested1 - f1
12
- t2 = tested2 - f2
13
- fet = Rubystats::FishersExactTest.new
14
- fisher = fet.calculate(t1,t2,f1,f2)
5
+ class TestFisher < MiniTest::Unit::TestCase
6
+ def test_simple
7
+ tested1 = 20
8
+ tested2 = 30
9
+ f1 = 10
10
+ f2 = 10
11
+ t1 = tested1 - f1
12
+ t2 = tested2 - f2
13
+ fet = Rubystats::FishersExactTest.new
14
+ fisher = fet.calculate(t1,t2,f1,f2)
15
15
 
16
- assert_equal("0.188301375769922",fisher[:left].to_s)
17
- assert_equal("0.929481131661052",fisher[:right].to_s)
18
- assert_equal("0.257549242810992",fisher[:twotail].to_s)
19
- end
16
+ assert_equal("0.18830137576992229",fisher[:left].to_s)
17
+ assert_equal("0.9294811316610517",fisher[:right].to_s)
18
+ assert_equal("0.2575492428109919",fisher[:twotail].to_s)
19
+ end
20
20
  end
@@ -1,8 +1,8 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
- require 'test/unit'
2
+ require 'minitest/autorun'
3
3
  require 'rubystats/normal_distribution'
4
4
 
5
- class TestNormal < Test::Unit::TestCase
5
+ class TestNormal < MiniTest::Unit::TestCase
6
6
  def test_simple
7
7
 
8
8
  norm = Rubystats::NormalDistribution.new(10,2)
@@ -4,16 +4,16 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
4
4
  # test that we can use old api that wasn't namespaced
5
5
  #
6
6
 
7
- require 'test/unit'
7
+ require 'minitest/autorun'
8
8
  require 'rubystats'
9
9
 
10
- class TestNormal < Test::Unit::TestCase
10
+ class TestNormal < MiniTest::Unit::TestCase
11
11
  def test_simple
12
12
  norm = NormalDistribution.new(10,2)
13
13
  cdf = norm.cdf(11)
14
14
 
15
- assert_equal("0.691462461274013",cdf.to_s)
16
- assert_not_nil(norm.rng)
15
+ assert_equal("0.6914624612740131",cdf.to_s)
16
+ refute_nil(norm.rng)
17
17
 
18
18
  expd = ExponentialDistribution.new(2)
19
19
  end
@@ -1,4 +1,4 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'tc_fisher'
3
3
  require 'tc_binomial'
4
4
  require 'tc_beta'
metadata CHANGED
@@ -1,41 +1,65 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rubystats
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.4
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
+ - Ilya Scharrenbroich
7
8
  - Bryan Donovan - http://www.bryandonovan.com
9
+ - Phillip Baker
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
-
12
- date: 2008-07-06 00:00:00 -07:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
13
+ date: 2016-02-01 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: minitest
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '4.2'
22
+ - - "<"
23
+ - !ruby/object:Gem::Version
24
+ version: '5.0'
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '4.2'
32
+ - - "<"
33
+ - !ruby/object:Gem::Version
34
+ version: '5.0'
35
+ - !ruby/object:Gem::Dependency
16
36
  name: hoe
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 1.7.0
17
42
  type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
21
46
  - - ">="
22
- - !ruby/object:Gem::Version
47
+ - !ruby/object:Gem::Version
23
48
  version: 1.7.0
24
- version:
25
- description: Ruby Stats is a port of the statistics libraries from PHPMath. Probability distributions include binomial, beta, and normal distributions with PDF, CDF and inverse CDF as well as Fisher's Exact Test.
26
- email: b.dondo+rubyforge@gmail.com
49
+ description: Ruby Stats is a port of the statistics libraries from PHPMath. Probability
50
+ distributions include binomial, beta, and normal distributions with PDF, CDF and
51
+ inverse CDF as well as Fisher's Exact Test.
52
+ email:
27
53
  executables: []
28
-
29
54
  extensions: []
30
-
31
- extra_rdoc_files:
32
- - History.txt
33
- - Manifest.txt
34
- - README.txt
35
- files:
55
+ extra_rdoc_files: []
56
+ files:
57
+ - ".gitignore"
58
+ - ".travis.yml"
59
+ - Gemfile
36
60
  - History.txt
37
61
  - Manifest.txt
38
- - README.txt
62
+ - README.rdoc
39
63
  - Rakefile
40
64
  - examples/beta.rb
41
65
  - examples/binomial.rb
@@ -51,6 +75,8 @@ files:
51
75
  - lib/rubystats/modules.rb
52
76
  - lib/rubystats/normal_distribution.rb
53
77
  - lib/rubystats/probability_distribution.rb
78
+ - lib/rubystats/version.rb
79
+ - rubystats.gemspec
54
80
  - test/tc_beta.rb
55
81
  - test/tc_binomial.rb
56
82
  - test/tc_exponential.rb
@@ -58,32 +84,34 @@ files:
58
84
  - test/tc_norm.rb
59
85
  - test/tc_require_all.rb
60
86
  - test/ts_stats.rb
61
- has_rdoc: true
62
- homepage: http://rubyforge.org/projects/rubystats/
87
+ homepage: https://github.com/phillbaker/rubystats
88
+ licenses: []
89
+ metadata: {}
63
90
  post_install_message:
64
- rdoc_options:
65
- - --main
66
- - README.txt
67
- require_paths:
91
+ rdoc_options: []
92
+ require_paths:
68
93
  - lib
69
- required_ruby_version: !ruby/object:Gem::Requirement
70
- requirements:
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
71
96
  - - ">="
72
- - !ruby/object:Gem::Version
73
- version: "0"
74
- version:
75
- required_rubygems_version: !ruby/object:Gem::Requirement
76
- requirements:
97
+ - !ruby/object:Gem::Version
98
+ version: 1.9.2
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
77
101
  - - ">="
78
- - !ruby/object:Gem::Version
79
- version: "0"
80
- version:
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
81
104
  requirements: []
82
-
83
- rubyforge_project: rubystats
84
- rubygems_version: 1.2.0
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.3
85
107
  signing_key:
86
- specification_version: 2
87
- summary: Port of PHPMath to Ruby
88
- test_files: []
89
-
108
+ specification_version: 4
109
+ summary: ''
110
+ test_files:
111
+ - test/tc_beta.rb
112
+ - test/tc_binomial.rb
113
+ - test/tc_exponential.rb
114
+ - test/tc_fisher.rb
115
+ - test/tc_norm.rb
116
+ - test/tc_require_all.rb
117
+ - test/ts_stats.rb