statsample 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ $:.unshift(File.dirname(__FILE__)+'/../lib/')
2
+ require 'statsample'
3
+ require 'test/unit'
4
+
5
+ class StatsampleCombinationTestCase < Test::Unit::TestCase
6
+ def initialize(*args)
7
+ super
8
+ end
9
+ def test_basic
10
+ k=3
11
+ n=5
12
+ expected=[[0,1,2],[0,1,3],[0,1,4],[0,2,3],[0,2,4],[0,3,4],[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
13
+ comb=Statsample::Combination.new(k,n)
14
+ a=[]
15
+ comb.each{|y|
16
+ a.push(y)
17
+ }
18
+ assert_equal(expected,a)
19
+ end
20
+ def test_gsl_versus_ruby
21
+ if HAS_GSL
22
+ k=3
23
+ n=10
24
+ gsl=Statsample::Combination.new(k,n,false)
25
+ gsl_array=[]
26
+ gsl.each{|y|
27
+ gsl_array.push(y)
28
+ }
29
+ rb=Statsample::Combination.new(k,n,true)
30
+ rb_array=[]
31
+ rb.each{|y|
32
+ rb_array.push(y)
33
+ }
34
+ assert(gsl.d.is_a? Statsample::Combination::CombinationGsl)
35
+ assert(rb.d.is_a? Statsample::Combination::CombinationRuby)
36
+
37
+ assert_equal(rb_array,gsl_array)
38
+ else
39
+ puts "Not CombinationRuby vs CombinationGSL (no gsl)"
40
+ end
41
+ end
42
+ end
data/test/test_csv.rb CHANGED
@@ -9,7 +9,7 @@ class StatsampleCSVTestCase < Test::Unit::TestCase
9
9
  super
10
10
  end
11
11
  def test_read
12
- assert_equal(6,@ds.cases)
12
+ assert_equal(6,@ds.cases)
13
13
  assert_equal(%w{id name age city a1},@ds.fields)
14
14
  id=[1,2,3,4,5,6].to_vector(:scale)
15
15
  name=["Alex","Claude","Peter","Franz","George","Fernand"].to_vector(:nominal)
data/test/test_dataset.rb CHANGED
@@ -148,7 +148,12 @@ class StatsampleDatasetTestCase < Test::Unit::TestCase
148
148
  def test_case_as
149
149
  assert_equal({'id'=>1,'name'=>'Alex','city'=>'New York','age'=>20,'a1'=>'a,b'},@ds.case_as_hash(0))
150
150
  assert_equal([5,'George',5,'Tome','a,b,c'],@ds.case_as_array(4))
151
+ # Native methods
152
+ assert_equal({'id'=>1,'name'=>'Alex','city'=>'New York','age'=>20,'a1'=>'a,b'},@ds._case_as_hash(0))
153
+ assert_equal([5,'George',5,'Tome','a,b,c'],@ds._case_as_array(4))
151
154
 
155
+
156
+
152
157
  end
153
158
  def test_delete_vector
154
159
  @ds.delete_vector('name')
@@ -65,8 +65,23 @@ class StatsampleStatisicsTestCase < Test::Unit::TestCase
65
65
  end
66
66
  def test_prop_pearson
67
67
  if HAS_GSL
68
- assert_in_delta(0.42,Statsample::Bivariate.prop_pearson(Statsample::Bivariate.t_r(0.084,94),94),0.01)
69
- assert_in_delta(0.65,Statsample::Bivariate.prop_pearson(Statsample::Bivariate.t_r(0.046,95),95),0.01)
68
+ assert_in_delta(0.42, Statsample::Bivariate.prop_pearson(Statsample::Bivariate.t_r(0.084,94), 94),0.01)
69
+ assert_in_delta(0.65, Statsample::Bivariate.prop_pearson(Statsample::Bivariate.t_r(0.046,95), 95),0.01)
70
+ r=0.9
71
+ n=100
72
+ t=Statsample::Bivariate.t_r(r,n)
73
+ assert(Statsample::Bivariate.prop_pearson(t,n,:both)<0.05)
74
+ assert(Statsample::Bivariate.prop_pearson(t,n,:right)<0.05)
75
+ assert(Statsample::Bivariate.prop_pearson(t,n,:left)>0.05)
76
+
77
+ r=-0.9
78
+ n=100
79
+ t=Statsample::Bivariate.t_r(r,n)
80
+ assert(Statsample::Bivariate.prop_pearson(t,n,:both)<0.05)
81
+ assert(Statsample::Bivariate.prop_pearson(t,n,:right)>0.05)
82
+ assert(Statsample::Bivariate.prop_pearson(t,n,:left)<0.05)
83
+
84
+
70
85
  else
71
86
  puts "Bivariate.prop_pearson not tested (no ruby-gsl)"
72
87
  end
@@ -79,10 +94,12 @@ class StatsampleStatisicsTestCase < Test::Unit::TestCase
79
94
 
80
95
  end
81
96
  end
97
+
82
98
  def test_spearman
83
99
  v1=[86,97,99,100,101,103,106,110,112,113].to_vector(:scale)
84
100
  v2=[0,20,28,27,50,29,7,17,6,12].to_vector(:scale)
85
101
  assert_in_delta(-0.175758,Statsample::Bivariate.spearman(v1,v2),0.0001)
102
+
86
103
  end
87
104
  def test_point_biserial
88
105
  c=[1,3,5,6,7,100,200,300,400,300].to_vector(:scale)
@@ -1,13 +1,16 @@
1
1
  $:.unshift(File.dirname(__FILE__)+'/../lib/')
2
2
  require 'statsample'
3
+ require 'tmpdir'
3
4
  require 'tempfile'
5
+ require 'fileutils'
4
6
  require 'test/unit'
5
7
  begin
6
8
  require 'statsample/graph/svggraph'
7
9
  class StatsampleSvgGraphTestCase < Test::Unit::TestCase
8
10
 
9
11
  def initialize(*args)
10
- @image_path=File.dirname(__FILE__)+"/images"
12
+ @image_path=Dir::tmpdir+"/images"
13
+ FileUtils.mkdir(@image_path) if !File.exists? @image_path
11
14
  super
12
15
  end
13
16
  def test_histogram
@@ -50,7 +53,7 @@ class StatsampleSvgGraphTestCase < Test::Unit::TestCase
50
53
  file=@image_path+"/svggraph_histogram.svg"
51
54
  hist=vector.svggraph_histogram(5)
52
55
  File.open(file,"wb") {|fp|
53
- fp.write(hist.burn)
56
+ fp.write(hist.burn)
54
57
  }
55
58
  assert(File.exists?(file))
56
59
  else
data/test/test_vector.rb CHANGED
@@ -87,6 +87,7 @@ class StatsampleVectorTestCase < Test::Unit::TestCase
87
87
  def test_nominal
88
88
  assert_equal(@c[1],5)
89
89
  assert_equal({ 1=>1,2=>1,3=>1,4=>1,5=>5,6=>2,7=>1,8=>1, 9=>1,10=>1},@c.frequencies)
90
+ assert_equal({ 1=>1,2=>1,3=>1,4=>1,5=>5,6=>2,7=>1,8=>1, 9=>1,10=>1},@c._frequencies)
90
91
  assert_equal({ 1 => 1.quo(15) ,2=>1.quo(15), 3=>1.quo(15),4=>1.quo(15),5=>5.quo(15),6=>2.quo(15),7=>1.quo(15), 8=>1.quo(15), 9=>1.quo(15),10=>1.quo(15)}, @c.proportions)
91
92
  assert_equal(@c.proportion, 1.quo(15))
92
93
  assert_equal(@c.proportion(2), 1.quo(15))
@@ -266,5 +267,9 @@ class StatsampleVectorTestCase < Test::Unit::TestCase
266
267
  assert_equal(v1.labels,v3.labels)
267
268
  assert_not_same(v1.labels,v3.labels)
268
269
  end
269
-
270
+ def test_paired_ties
271
+ a=[0,0,0,1,1,2,3,3,4,4,4].to_vector(:ordinal)
272
+ expected=[2,2,2,4.5,4.5,6,7.5,7.5,10,10,10].to_vector(:ordinal)
273
+ assert_equal(expected,a.ranked)
274
+ end
270
275
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsample
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Bustos
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-11 00:00:00 -04:00
12
+ date: 2009-08-21 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -82,6 +82,7 @@ files:
82
82
  - lib/statsample/bivariate.rb
83
83
  - lib/statsample/chidistribution.rb
84
84
  - lib/statsample/codification.rb
85
+ - lib/statsample/combination.rb
85
86
  - lib/statsample/converters.rb
86
87
  - lib/statsample/crosstab.rb
87
88
  - lib/statsample/dataset.rb
@@ -95,6 +96,7 @@ files:
95
96
  - lib/statsample/htmlreport.rb
96
97
  - lib/statsample/multiset.rb
97
98
  - lib/statsample/regression.rb
99
+ - lib/statsample/regression/logit.rb
98
100
  - lib/statsample/regression/multiple.rb
99
101
  - lib/statsample/regression/multiple/alglibengine.rb
100
102
  - lib/statsample/regression/multiple/gslengine.rb
@@ -111,6 +113,7 @@ files:
111
113
  - test/_test_chart.rb
112
114
  - test/test_anova.rb
113
115
  - test/test_codification.rb
116
+ - test/test_combination.rb
114
117
  - test/test_crosstab.rb
115
118
  - test/test_csv.csv
116
119
  - test/test_csv.rb
@@ -162,6 +165,7 @@ test_files:
162
165
  - test/test_crosstab.rb
163
166
  - test/test_svg_graph.rb
164
167
  - test/test_csv.rb
168
+ - test/test_combination.rb
165
169
  - test/test_resample.rb
166
170
  - test/test_stratified.rb
167
171
  - test/test_vector.rb