statsample 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/test_matrix.rb CHANGED
@@ -3,7 +3,23 @@ require(File.dirname(__FILE__)+'/helpers_tests.rb')
3
3
 
4
4
  class StatsampleMatrixTestCase < MiniTest::Unit::TestCase
5
5
 
6
-
6
+ def test_to_dataset
7
+ m=Matrix[[1,4],[2,5],[3,6]]
8
+ m.extend Statsample::NamedMatrix
9
+ m.fields_y=%w{x1 x2}
10
+ m.name="test"
11
+ samples=100
12
+ x1=[1,2,3].to_scale
13
+ x2=[4,5,6].to_scale
14
+ ds={'x1'=>x1,'x2'=>x2}.to_dataset
15
+ ds.name="test"
16
+ obs=m.to_dataset
17
+ assert_equal(ds['x1'],obs['x1'])
18
+ assert_equal(ds['x2'],obs['x2'])
19
+ assert_equal(ds['x1'].mean,obs['x1'].mean)
20
+
21
+
22
+ end
7
23
  def test_covariate
8
24
  a=Matrix[[1.0, 0.3, 0.2], [0.3, 1.0, 0.5], [0.2, 0.5, 1.0]]
9
25
  a.extend Statsample::CovariateMatrix
@@ -1,7 +1,14 @@
1
- require(File.dirname(__FILE__)+'/helpers_tests.rb')
1
+ require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
2
2
 
3
3
 
4
4
  class StatsampleMultisetTestCase < MiniTest::Unit::TestCase
5
+ def setup
6
+ @x=%w{a a a a b b b b}.to_vector
7
+ @y=[1,2,3,4,5,6,7,8].to_scale
8
+ @z=[10,11,12,13,14,15,16,17].to_scale
9
+ @ds={'x'=>@x,'y'=>@y,'z'=>@z}.to_dataset
10
+ @ms=@ds.to_multiset_by_split('x')
11
+ end
5
12
  def test_creation
6
13
  v1a=[1,2,3,4,5].to_vector
7
14
  v2b=[11,21,31,41,51].to_vector
@@ -88,7 +95,64 @@ class StatsampleMultisetTestCase < MiniTest::Unit::TestCase
88
95
  assert_equal(75,ss.mean('test'))
89
96
  assert_in_delta(1.45,ss.standard_error_wor('test'),0.01)
90
97
  assert_in_delta(ss.standard_error_wor('test'), ss.standard_error_wor_2('test'),0.00001)
98
+ end
99
+ def test_each
100
+ xpe={
101
+ 'a'=>%w{a a a a}.to_vector,
102
+ 'b'=>%w{b b b b}.to_vector
103
+ }
104
+ ype={
105
+ 'a'=>[1,2,3,4].to_scale,
106
+ 'b'=>[5,6,7,8].to_scale,
107
+ }
108
+ zpe={
109
+ 'a'=>[10,11,12,13].to_scale,
110
+ 'b'=>[14,15,16,17].to_scale,
111
+ }
112
+ xp,yp,zp=Hash.new(),Hash.new(),Hash.new()
113
+ @ms.each {|k,ds|
114
+ xp[k]=ds['x']
115
+ yp[k]=ds['y']
116
+ zp[k]=ds['z']
117
+ }
118
+ assert_equal(xpe,xp)
119
+ assert_equal(ype,yp)
120
+ assert_equal(zpe,zp)
91
121
 
92
-
122
+ end
123
+ def test_multiset_union_with_block
124
+
125
+ r1=rand()
126
+ r2=rand()
127
+ ye=[1*r1,2*r1,3*r1,4*r1,5*r2,6*r2,7*r2,8*r2].to_scale
128
+
129
+ ze=[10*r1,11*r1,12*r1,13*r1, 14*r2,15*r2,16*r2,17*r2].to_scale
130
+
131
+ ds2=@ms.union {|k,ds|
132
+ ds['y'].recode!{|v|
133
+ k=='a' ? v*r1 : v*r2}
134
+ ds['z'].recode!{|v|
135
+ k=='a' ? v*r1 : v*r2}
136
+ }
137
+ assert_equal(ye,ds2['y'])
138
+ assert_equal(ze,ds2['z'])
139
+ end
140
+ def test_multiset_union
141
+ r1=rand()
142
+ r2=rand()
143
+ ye=[1*r1,2*r1,3*r1,4*r1,5*r2,6*r2,7*r2,8*r2].to_scale
144
+
145
+ ze=[10*r1,11*r1,12*r1,13*r1, 14*r2,15*r2,16*r2,17*r2].to_scale
146
+ @ms.each {|k,ds|
147
+ ds['y'].recode!{|v|
148
+ k=='a' ? v*r1 : v*r2}
149
+ ds['z'].recode!{|v|
150
+ k=='a' ? v*r1 : v*r2}
151
+
152
+ }
153
+ ds2=@ms.union
154
+ assert_equal(ye,ds2['y'])
155
+ assert_equal(ze,ds2['z'])
156
+
93
157
  end
94
158
  end
data/test/test_vector.rb CHANGED
@@ -1,4 +1,4 @@
1
- require(File.dirname(__FILE__)+'/helpers_tests.rb')
1
+ require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
2
2
 
3
3
  class StatsampleTestVector < MiniTest::Unit::TestCase
4
4
  def setup
@@ -250,6 +250,11 @@ class StatsampleTestVector < MiniTest::Unit::TestCase
250
250
  a=[1,2,2,3,4,5,5,5,6,10].to_scale
251
251
  expected=[10,25,25,40,50,70,70,70,90,100].to_scale
252
252
  assert_equal(expected, a.vector_percentil)
253
+ a=[1,nil,nil,2,2,3,4,nil,nil,5,5,5,6,10].to_scale
254
+ expected=[10,nil,nil,25,25,40,50,nil,nil,70,70,70,90,100].to_scale
255
+ assert_equal(expected, a.vector_percentil)
256
+
257
+
253
258
  end
254
259
  def test_ordinal
255
260
  @c.type=:ordinal
@@ -269,6 +274,9 @@ class StatsampleTestVector < MiniTest::Unit::TestCase
269
274
  v1=[0.8,1.2,1.2,2.3,18].to_vector(:ordinal)
270
275
  expected=[1,2.5,2.5,4,5].to_vector(:ordinal)
271
276
  assert_equal(expected,v1.ranked)
277
+ v1=[nil,0.8,1.2,1.2,2.3,18,nil].to_vector(:ordinal)
278
+ expected=[nil,1,2.5,2.5,4,5,nil].to_vector(:ordinal)
279
+ assert_equal(expected,v1.ranked)
272
280
  end
273
281
  def test_scale
274
282
  a=Statsample::Vector.new([1,2,3,4,"STRING"], :scale)
@@ -281,6 +289,16 @@ class StatsampleTestVector < MiniTest::Unit::TestCase
281
289
  i+=1
282
290
  }
283
291
  end
292
+ def test_vector_centered
293
+ mean=rand()
294
+ samples=11
295
+ centered=samples.times.map {|i| i-((samples/2).floor).to_i}.to_scale
296
+ not_centered=centered.recode {|v| v+mean}
297
+ obs=not_centered.centered
298
+ centered.each_with_index do |v,i|
299
+ assert_in_delta(v,obs[i],0.0001)
300
+ end
301
+ end
284
302
  def test_vector_standarized
285
303
  v1=[1,2,3,4,nil].to_vector(:scale)
286
304
  sds=v1.sds
@@ -292,7 +310,8 @@ class StatsampleTestVector < MiniTest::Unit::TestCase
292
310
  end
293
311
  def test_vector_standarized_with_zero_variance
294
312
  v1=100.times.map {|i| 1}.to_scale
295
- assert(v1.standarized.nil?)
313
+ exp=100.times.map {nil}.to_scale
314
+ assert_equal(exp,v1.standarized)
296
315
  end
297
316
 
298
317
  def test_add
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsample
3
3
  version: !ruby/object:Gem::Version
4
- hash: 91
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 17
7
+ - 18
9
8
  - 0
10
- version: 0.17.0
9
+ version: 0.18.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Claudio Bustos
@@ -36,7 +35,7 @@ cert_chain:
36
35
  rpP0jjs0
37
36
  -----END CERTIFICATE-----
38
37
 
39
- date: 2010-12-09 00:00:00 -03:00
38
+ date: 2011-01-07 00:00:00 -03:00
40
39
  default_executable:
41
40
  dependencies:
42
41
  - !ruby/object:Gem::Dependency
@@ -47,12 +46,11 @@ dependencies:
47
46
  requirements:
48
47
  - - ~>
49
48
  - !ruby/object:Gem::Version
50
- hash: 7
51
49
  segments:
52
50
  - 0
53
51
  - 6
54
- - 0
55
- version: 0.6.0
52
+ - 5
53
+ version: 0.6.5
56
54
  type: :runtime
57
55
  version_requirements: *id001
58
56
  - !ruby/object:Gem::Dependency
@@ -63,7 +61,6 @@ dependencies:
63
61
  requirements:
64
62
  - - ~>
65
63
  - !ruby/object:Gem::Version
66
- hash: 7
67
64
  segments:
68
65
  - 1
69
66
  - 4
@@ -78,7 +75,6 @@ dependencies:
78
75
  requirements:
79
76
  - - ~>
80
77
  - !ruby/object:Gem::Version
81
- hash: 23
82
78
  segments:
83
79
  - 0
84
80
  - 2
@@ -94,7 +90,6 @@ dependencies:
94
90
  requirements:
95
91
  - - ">"
96
92
  - !ruby/object:Gem::Version
97
- hash: 3
98
93
  segments:
99
94
  - 0
100
95
  version: "0"
@@ -108,7 +103,6 @@ dependencies:
108
103
  requirements:
109
104
  - - ~>
110
105
  - !ruby/object:Gem::Version
111
- hash: 11
112
106
  segments:
113
107
  - 0
114
108
  - 0
@@ -123,7 +117,6 @@ dependencies:
123
117
  requirements:
124
118
  - - ~>
125
119
  - !ruby/object:Gem::Version
126
- hash: 17
127
120
  segments:
128
121
  - 0
129
122
  - 3
@@ -139,7 +132,6 @@ dependencies:
139
132
  requirements:
140
133
  - - ">"
141
134
  - !ruby/object:Gem::Version
142
- hash: 3
143
135
  segments:
144
136
  - 0
145
137
  version: "0"
@@ -153,7 +145,6 @@ dependencies:
153
145
  requirements:
154
146
  - - ~>
155
147
  - !ruby/object:Gem::Version
156
- hash: 29
157
148
  segments:
158
149
  - 0
159
150
  - 2
@@ -169,28 +160,24 @@ dependencies:
169
160
  requirements:
170
161
  - - ~>
171
162
  - !ruby/object:Gem::Version
172
- hash: 21
173
163
  segments:
174
164
  - 0
175
- - 3
176
- - 3
177
- version: 0.3.3
165
+ - 4
166
+ - 0
167
+ version: 0.4.0
178
168
  type: :runtime
179
169
  version_requirements: *id009
180
170
  - !ruby/object:Gem::Dependency
181
- name: rubyforge
171
+ name: hoe
182
172
  prerelease: false
183
173
  requirement: &id010 !ruby/object:Gem::Requirement
184
174
  none: false
185
175
  requirements:
186
- - - ">="
176
+ - - ~>
187
177
  - !ruby/object:Gem::Version
188
- hash: 7
189
178
  segments:
190
- - 2
191
179
  - 0
192
- - 4
193
- version: 2.0.4
180
+ version: "0"
194
181
  type: :development
195
182
  version_requirements: *id010
196
183
  - !ruby/object:Gem::Dependency
@@ -199,9 +186,8 @@ dependencies:
199
186
  requirement: &id011 !ruby/object:Gem::Requirement
200
187
  none: false
201
188
  requirements:
202
- - - ">="
189
+ - - ~>
203
190
  - !ruby/object:Gem::Version
204
- hash: 3
205
191
  segments:
206
192
  - 0
207
193
  version: "0"
@@ -215,7 +201,6 @@ dependencies:
215
201
  requirements:
216
202
  - - ~>
217
203
  - !ruby/object:Gem::Version
218
- hash: 3
219
204
  segments:
220
205
  - 2
221
206
  - 0
@@ -230,12 +215,11 @@ dependencies:
230
215
  requirements:
231
216
  - - ">="
232
217
  - !ruby/object:Gem::Version
233
- hash: 19
234
218
  segments:
235
219
  - 2
236
- - 7
220
+ - 8
237
221
  - 0
238
- version: 2.7.0
222
+ version: 2.8.0
239
223
  type: :development
240
224
  version_requirements: *id013
241
225
  description: |-
@@ -376,6 +360,7 @@ files:
376
360
  - po/statsample.pot
377
361
  - references.txt
378
362
  - setup.rb
363
+ - test/fixtures/bank2.dat
379
364
  - test/fixtures/correlation_matrix.rb
380
365
  - test/helpers_tests.rb
381
366
  - test/test_anovaoneway.rb
@@ -448,7 +433,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
448
433
  requirements:
449
434
  - - ">="
450
435
  - !ruby/object:Gem::Version
451
- hash: 3
452
436
  segments:
453
437
  - 0
454
438
  version: "0"
@@ -457,7 +441,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
457
441
  requirements:
458
442
  - - ">="
459
443
  - !ruby/object:Gem::Version
460
- hash: 3
461
444
  segments:
462
445
  - 0
463
446
  version: "0"
metadata.gz.sig CHANGED
Binary file