statsample 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,5 @@
1
+ === 0.8.1 / 2010-03-29
2
+ * Fixed Regression summaries
1
3
  === 0.8.0 / 2010-03-29
2
4
  * New Statsample::Test::T module, with classes and methods to do Student's t tests for one and two samples.
3
5
  * Statsample::PromiseAfter module to set a number of variables without explicitly call the compute or iterate method
data/lib/statsample.rb CHANGED
@@ -111,7 +111,7 @@ module Statsample
111
111
  false
112
112
  end
113
113
  end
114
- VERSION = '0.8.0'
114
+ VERSION = '0.8.1'
115
115
  SPLIT_TOKEN = ","
116
116
  autoload(:Database, 'statsample/converters')
117
117
  autoload(:Anova, 'statsample/anova')
@@ -313,59 +313,58 @@ module Statsample
313
313
  rp.add(self)
314
314
  rp.to_text
315
315
  end
316
- def report_building(generator)
316
+ def report_building(g)
317
317
  compute if @models.nil?
318
318
 
319
- anchor=generator.toc_entry(_("DA: ")+@name)
320
-
321
- generator.html "<div class='dominance-analysis'>#{@name}<a name='#{anchor}'></a>"
322
- header=["","r2",_("sign")]+@predictors.collect {|c| DominanceAnalysis.predictor_name(c) }
323
- t=ReportBuilder::Table.new(:name=>_("Dominance Analysis result"),:header=>header)
324
-
325
- row=[_("Model 0"),"",""]+@predictors.collect{|f|
326
- sprintf("%0.3f", md([f]).r2)
327
- }
328
-
329
- t.row(row)
330
- t.hr
331
- for i in 1..@predictors.size
332
- mk=md_k(i)
333
- mk.each{|m|
334
- t.row(m.add_table_row)
335
- }
336
- # Report averages
337
- a=average_k(i)
338
- if !a.nil?
339
- t.hr
340
- row=[_("k=%d Average") % i,"",""] + @predictors.collect{|f|
341
- sprintf("%0.3f",a[f])
319
+ g.section(:name=>@name) do |generator|
320
+ header=["","r2",_("sign")]+@predictors.collect {|c| DominanceAnalysis.predictor_name(c) }
321
+
322
+ generator.table(:name=>_("Dominance Analysis result"), :header=>header) do |t|
323
+
324
+ row=[_("Model 0"),"",""]+@predictors.collect{|f|
325
+ sprintf("%0.3f", md([f]).r2)
326
+ }
327
+
328
+ t.row(row)
329
+ t.hr
330
+ for i in 1..@predictors.size
331
+ mk=md_k(i)
332
+ mk.each{|m|
333
+ t.row(m.add_table_row)
342
334
  }
335
+ # Report averages
336
+ a=average_k(i)
337
+ if !a.nil?
338
+ t.hr
339
+ row=[_("k=%d Average") % i,"",""] + @predictors.collect{|f|
340
+ sprintf("%0.3f",a[f])
341
+ }
342
+ t.row(row)
343
+ t.hr
344
+
345
+ end
346
+ end
347
+
348
+ g=general_averages
349
+ t.hr
350
+
351
+ row=[_("Overall averages"),"",""]+@predictors.collect{|f|
352
+ sprintf("%0.3f",g[f])
353
+ }
354
+ t.row(row)
355
+ end
356
+
357
+ td=total_dominance
358
+ cd=conditional_dominance
359
+ gd=general_dominance
360
+ generator.table(:name=>_("Pairwise dominance"), :header=>[_("Pairs"),_("Total"),_("Conditional"),_("General")]) do |t|
361
+ pairs.each{|p|
362
+ name=p.join(" - ")
363
+ row=[name, sprintf("%0.1f",td[p]), sprintf("%0.1f",cd[p]), sprintf("%0.1f",gd[p])]
343
364
  t.row(row)
344
- t.hr
345
-
365
+ }
346
366
  end
347
367
  end
348
-
349
- g=general_averages
350
- t.hr
351
-
352
- row=[_("Overall averages"),"",""]+@predictors.collect{|f|
353
- sprintf("%0.3f",g[f])
354
- }
355
- t.row(row)
356
- generator.parse_element(t)
357
-
358
- td=total_dominance
359
- cd=conditional_dominance
360
- gd=general_dominance
361
- t=ReportBuilder::Table.new(:name=>_("Pairwise dominance"), :header=>[_("Pairs"),_("Total"),_("Conditional"),_("General")])
362
- pairs.each{|p|
363
- name=p.join(" - ")
364
- row=[name, sprintf("%0.1f",td[p]), sprintf("%0.1f",cd[p]), sprintf("%0.1f",gd[p])]
365
- t.row(row)
366
- }
367
- generator.parse_element(t)
368
- generator.html("</div>")
369
368
  end
370
369
  class ModelData # :nodoc:
371
370
  attr_reader :contributions
@@ -172,9 +172,9 @@ module Statsample
172
172
 
173
173
  g.table(:name=>"ANOVA", :header=>%w{source ss df ms f s}) do |t|
174
174
  t.row([_("Regression"), sprintf("%0.3f",ssr), df_r, sprintf("%0.3f",msr), sprintf("%0.3f",f), sprintf("%0.3f", significance)])
175
- t.row([_("Error"), sprintf("%0.3f",sse), df_e, sprintf("%0.3f",mse)])
175
+ t.row([_("Error"), sprintf("%0.3f",sse), df_e, sprintf("%0.3f",mse),"",""])
176
176
 
177
- t.row([_("Total"), sprintf("%0.3f",sst), df_r+df_e])
177
+ t.row([_("Total"), sprintf("%0.3f",sst), df_r+df_e,"","",""])
178
178
  end
179
179
  sc=standarized_coeffs
180
180
  cse=coeffs_se
@@ -206,9 +206,9 @@ class MatrixEngine < BaseEngine
206
206
 
207
207
  g.table(:name=>"ANOVA", :header=>%w{source ss df ms f s}) do |t|
208
208
  t.row([_("Regression"), sprintf("%0.3f",ssr), df_r, sprintf("%0.3f",msr), sprintf("%0.3f",f), sprintf("%0.3f", significance)])
209
- t.row([_("Error"), sprintf("%0.3f",sse), df_e, sprintf("%0.3f",mse)])
209
+ t.row([_("Error"), sprintf("%0.3f",sse), df_e, sprintf("%0.3f",mse),"",""])
210
210
 
211
- t.row([_("Total"), sprintf("%0.3f",sst), df_r+df_e])
211
+ t.row([_("Total"), sprintf("%0.3f",sst), df_r+df_e,"","",""])
212
212
  end
213
213
  sc=standarized_coeffs
214
214
  cse=coeffs_se
@@ -4,7 +4,7 @@ require(File.dirname(__FILE__)+'/test_helpers.rb')
4
4
  class StatsamplePromiseAfterTestCase < MiniTest::Unit::TestCase
5
5
  class ExpensiveClass
6
6
  extend Statsample::PromiseAfter
7
- attr_reader :a, :dirty
7
+ attr_reader :dirty
8
8
  def initialize
9
9
  @a=nil
10
10
  @b=nil
@@ -18,7 +18,17 @@ class StatsampleRegressionTestCase < MiniTest::Unit::TestCase
18
18
  assert_in_delta(-0.957, reg.b,0.001)
19
19
  assert_in_delta(4.248,reg.standard_error,0.002)
20
20
  end
21
-
21
+ def test_summaries
22
+ a=100.times.map{rand(100)}.to_scale
23
+ b=100.times.map{rand(100)}.to_scale
24
+ y=100.times.map{rand(100)}.to_scale
25
+ ds={'a'=>a,'b'=>b,'y'=>y}.to_dataset
26
+ lr=Statsample::Regression::Multiple::RubyEngine.new(ds,'y')
27
+ assert(lr.summary.size>0)
28
+
29
+
30
+
31
+ end
22
32
  def test_multiple_dependent
23
33
  complete=Matrix[
24
34
  [1,0.53,0.62,0.19,-0.09,0.08,0.02,-0.12,0.08],
@@ -40,8 +50,8 @@ class StatsampleRegressionTestCase < MiniTest::Unit::TestCase
40
50
  assert_in_delta(0.197, lr.r2yx_covariance,0.001)
41
51
  assert_in_delta(0.07, lr.p2yx,0.001)
42
52
 
43
-
44
53
  end
54
+
45
55
  def test_multiple_regression_pairwise_2
46
56
  @a=[1,3,2,4,3,5,4,6,5,7,3,nil,3,nil,3].to_vector(:scale)
47
57
  @b=[3,3,4,4,5,5,6,6,4,4,2,2,nil,6,2].to_vector(:scale)
@@ -67,6 +77,7 @@ class StatsampleRegressionTestCase < MiniTest::Unit::TestCase
67
77
  @y=[3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
68
78
  ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
69
79
  lr=Statsample::Regression::Multiple::GslEngine.new(ds,'y')
80
+ assert(lr.summary.size>0)
70
81
  model_test(lr,'gsl')
71
82
  predicted=[1.7857, 6.0989, 3.2433, 7.2908, 4.9667, 10.3428, 8.8158, 10.4717, 23.6639, 25.3198]
72
83
  c_predicted=lr.predicted
@@ -148,6 +159,7 @@ class StatsampleRegressionTestCase < MiniTest::Unit::TestCase
148
159
 
149
160
  covariance=Statsample::Bivariate.covariance_matrix(ds)
150
161
  lr=Statsample::Regression::Multiple::MatrixEngine.new(covariance,'y', :y_mean=>@y.mean, :x_mean=>{'a'=>ds['a'].mean, 'b'=>ds['b'].mean, 'c'=>ds['c'].mean}, :cases=>@a.size)
162
+ assert(lr.summary.size>0)
151
163
 
152
164
  model_test(lr , "covariance matrix")
153
165
  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.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Bustos