statsample 0.7.0 → 0.8.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.
Files changed (62) hide show
  1. data/History.txt +7 -0
  2. data/Manifest.txt +15 -9
  3. data/README.txt +6 -0
  4. data/Rakefile +8 -0
  5. data/{demo → examples}/correlation_matrix.rb +0 -0
  6. data/{demo/dominanceanalysis.rb → examples/dominance_analysis.rb} +0 -0
  7. data/{demo → examples}/dominance_analysis_bootstrap.rb +0 -0
  8. data/{demo → examples}/levene.rb +0 -0
  9. data/{demo → examples}/multiple_regression.rb +5 -3
  10. data/{demo → examples}/multivariate_correlation.rb +0 -0
  11. data/{demo → examples}/polychoric.rb +0 -0
  12. data/{demo → examples}/principal_axis.rb +0 -0
  13. data/examples/t_test.rb +11 -0
  14. data/{demo → examples}/tetrachoric.rb +0 -0
  15. data/lib/statistics2.rb +1 -1
  16. data/lib/statsample.rb +57 -6
  17. data/lib/statsample/bivariate/polychoric.rb +12 -25
  18. data/lib/statsample/bivariate/tetrachoric.rb +1 -3
  19. data/lib/statsample/converter/csv.rb +11 -12
  20. data/lib/statsample/dominanceanalysis/bootstrap.rb +2 -3
  21. data/lib/statsample/factor/principalaxis.rb +0 -2
  22. data/lib/statsample/factor/rotation.rb +6 -8
  23. data/lib/statsample/graph.rb +8 -0
  24. data/lib/statsample/graph/svggraph.rb +0 -4
  25. data/lib/statsample/regression/multiple/baseengine.rb +25 -28
  26. data/lib/statsample/regression/multiple/matrixengine.rb +30 -34
  27. data/lib/statsample/test.rb +36 -1
  28. data/lib/statsample/test/levene.rb +11 -7
  29. data/lib/statsample/test/t.rb +189 -0
  30. data/test/test_anova.rb +8 -10
  31. data/test/test_bivariate.rb +40 -37
  32. data/test/test_codification.rb +9 -13
  33. data/test/test_combination.rb +37 -39
  34. data/test/test_crosstab.rb +46 -48
  35. data/test/test_csv.rb +40 -45
  36. data/test/test_dataset.rb +150 -152
  37. data/test/test_distribution.rb +24 -21
  38. data/test/test_dominance_analysis.rb +10 -12
  39. data/test/test_factor.rb +95 -91
  40. data/test/test_ggobi.rb +30 -33
  41. data/test/test_gsl.rb +4 -4
  42. data/test/test_helpers.rb +26 -0
  43. data/test/test_histogram.rb +5 -6
  44. data/test/test_logit.rb +20 -21
  45. data/test/test_matrix.rb +47 -48
  46. data/test/test_mle.rb +130 -131
  47. data/test/test_multiset.rb +95 -96
  48. data/test/test_permutation.rb +35 -36
  49. data/test/test_promise_after.rb +39 -0
  50. data/test/test_regression.rb +49 -51
  51. data/test/test_reliability.rb +29 -30
  52. data/test/test_resample.rb +22 -23
  53. data/test/test_srs.rb +8 -9
  54. data/test/test_statistics.rb +12 -6
  55. data/test/test_stest.rb +18 -10
  56. data/test/test_stratified.rb +15 -16
  57. data/test/test_svg_graph.rb +11 -22
  58. data/test/test_test_t.rb +40 -0
  59. data/test/test_umannwhitney.rb +14 -15
  60. data/test/test_vector.rb +33 -37
  61. data/test/test_xls.rb +34 -41
  62. metadata +22 -11
@@ -0,0 +1,8 @@
1
+ require 'statsample/graph/svggraph'
2
+ require 'statsample/graph/svghistogram'
3
+ require 'statsample/graph/svgscatterplot'
4
+
5
+ module Statsample
6
+ module Graph
7
+ end
8
+ end
@@ -3,7 +3,6 @@ require 'SVG/Graph/BarHorizontal'
3
3
  require 'SVG/Graph/Pie'
4
4
  require 'SVG/Graph/Line'
5
5
  require 'SVG/Graph/Plot'
6
- require 'statsample/graph/svghistogram'
7
6
 
8
7
  module Statsample
9
8
  class Vector
@@ -183,6 +182,3 @@ module SVG #:nodoc:
183
182
  end
184
183
  end
185
184
  end
186
-
187
- require 'statsample/graph/svgscatterplot'
188
- require 'statsample/graph/svgboxplot'
@@ -160,34 +160,31 @@ module Statsample
160
160
  rp.add(self)
161
161
  rp.to_text
162
162
  end
163
- def report_building(generator)
164
- anchor=generator.toc_entry(_("Multiple Regression: ")+@name)
165
- generator.html "<div class='multiple-regression'>#{@name}<a name='#{anchor}'></a>"
166
- c=coeffs
167
- generator.text(_("Engine: %s") % self.class)
168
- generator.text(_("Cases(listwise)=%d(%d)") % [@ds.cases, @ds_valid.cases])
169
- generator.text("R=#{sprintf('%0.3f',r)}")
170
- generator.text("R^2=#{sprintf('%0.3f',r2)}")
171
-
172
- generator.text(_("Equation")+"="+ sprintf('%0.3f',constant) +" + "+ @fields.collect {|k| sprintf('%0.3f%s',c[k],k)}.join(' + ') )
173
-
174
- t=ReportBuilder::Table.new(:name=>"ANOVA", :header=>%w{source ss df ms f s})
175
- t.row([_("Regression"), sprintf("%0.3f",ssr), df_r, sprintf("%0.3f",msr), sprintf("%0.3f",f), sprintf("%0.3f", significance)])
176
- t.row([_("Error"), sprintf("%0.3f",sse), df_e, sprintf("%0.3f",mse)])
177
-
178
- t.row([_("Total"), sprintf("%0.3f",sst), df_r+df_e])
179
- generator.parse_element(t)
180
- sc=standarized_coeffs
181
- cse=coeffs_se
182
- t=ReportBuilder::Table.new(:name=>"Beta coefficients", :header=>%w{coeff b beta se t}.collect{|field| _(field)} )
183
-
184
- t.row([_("Constant"), sprintf("%0.3f", constant), "-", sprintf("%0.3f", constant_se), sprintf("%0.3f", constant_t)])
185
-
186
- @fields.each do |f|
187
- t.row([f, sprintf("%0.3f", c[f]), sprintf("%0.3f", sc[f]), sprintf("%0.3f", cse[f]), sprintf("%0.3f", c[f].quo(cse[f]))])
188
- end
189
- generator.parse_element(t)
190
- generator.html("</div>")
163
+ def report_building(b)
164
+ b.section(:name=>_("Multiple Regression: ")+@name) do |g|
165
+ c=coeffs
166
+ g.text(_("Engine: %s") % self.class)
167
+ g.text(_("Cases(listwise)=%d(%d)") % [@ds.cases, @ds_valid.cases])
168
+ g.text("R=#{sprintf('%0.3f',r)}")
169
+ g.text("R^2=#{sprintf('%0.3f',r2)}")
170
+
171
+ g.text(_("Equation")+"="+ sprintf('%0.3f',constant) +" + "+ @fields.collect {|k| sprintf('%0.3f%s',c[k],k)}.join(' + ') )
172
+
173
+ g.table(:name=>"ANOVA", :header=>%w{source ss df ms f s}) do |t|
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)])
176
+
177
+ t.row([_("Total"), sprintf("%0.3f",sst), df_r+df_e])
178
+ end
179
+ sc=standarized_coeffs
180
+ cse=coeffs_se
181
+ g.table(:name=>"Beta coefficients", :header=>%w{coeff b beta se t}.collect{|field| _(field)} ) do |t|
182
+ t.row([_("Constant"), sprintf("%0.3f", constant), "-", sprintf("%0.3f", constant_se), sprintf("%0.3f", constant_t)])
183
+ @fields.each do |f|
184
+ t.row([f, sprintf("%0.3f", c[f]), sprintf("%0.3f", sc[f]), sprintf("%0.3f", cse[f]), sprintf("%0.3f", c[f].quo(cse[f]))])
185
+ end
186
+ end
187
+ end
191
188
  end
192
189
 
193
190
 
@@ -194,41 +194,37 @@ class MatrixEngine < BaseEngine
194
194
  matrix.collect {|i| Math::sqrt(i) if i>0 }[0,0]
195
195
  end
196
196
 
197
- def report_building(generator) # :nodoc:
198
- anchor=generator.toc_entry(_("Multiple Regression: ")+@name)
199
- generator.html "<div class='multiple-regression'>#{@name}<a name='#{anchor}'></a>"
200
- c=coeffs
201
- generator.text(_("Engine: %s") % self.class)
202
- generator.text(_("Cases=%d") % [@cases])
203
- generator.text("R=#{sprintf('%0.3f',r)}")
204
- generator.text("R^2=#{sprintf('%0.3f',r2)}")
205
-
206
- generator.text(_("Equation")+"="+ sprintf('%0.3f',constant) +" + "+ @fields.collect {|k| sprintf('%0.3f%s',c[k],k)}.join(' + ') )
207
-
208
- t=ReportBuilder::Table.new(:name=>"ANOVA", :header=>%w{source ss df ms f s})
209
- t.row([_("Regression"), sprintf("%0.3f",ssr), df_r, sprintf("%0.3f",msr), sprintf("%0.3f",f), sprintf("%0.3f", significance)])
210
- t.row([_("Error"), sprintf("%0.3f",sse), df_e, sprintf("%0.3f",mse)])
211
-
212
- t.row([_("Total"), sprintf("%0.3f",sst), df_r+df_e])
213
- generator.parse_element(t)
214
- sc=standarized_coeffs
215
- cse=coeffs_se
216
- t=ReportBuilder::Table.new(:name=>"Beta coefficients", :header=>%w{coeff b beta se t}.collect{|field| _(field)} )
217
-
218
- if (constant_se.nil?)
219
- t.row([_("Constant"), sprintf("%0.3f", constant),"--","?","?"])
220
- else
221
- t.row([_("Constant"), sprintf("%0.3f", constant), "-", sprintf("%0.3f", constant_se), sprintf("%0.3f", constant_t)])
222
- end
223
-
224
- @fields.each do |f|
225
- t.row([f, sprintf("%0.3f", c[f]), sprintf("%0.3f", sc[f]), sprintf("%0.3f", cse[f]), sprintf("%0.3f", c[f].quo(cse[f]))])
226
- end
227
- generator.parse_element(t)
228
- generator.html("</div>")
197
+ def report_building(builder) # :nodoc:
198
+ builder.section(:name=>_("Multiple Regression: ")+@name) do |g|
199
+ c=coeffs
200
+ g.text(_("Engine: %s") % self.class)
201
+ g.text(_("Cases=%d") % [@cases])
202
+ g.text("R=#{sprintf('%0.3f',r)}")
203
+ g.text("R^2=#{sprintf('%0.3f',r2)}")
204
+
205
+ g.text(_("Equation")+"="+ sprintf('%0.3f',constant) +" + "+ @fields.collect {|k| sprintf('%0.3f%s',c[k],k)}.join(' + ') )
206
+
207
+ g.table(:name=>"ANOVA", :header=>%w{source ss df ms f s}) do |t|
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)])
210
+
211
+ t.row([_("Total"), sprintf("%0.3f",sst), df_r+df_e])
212
+ end
213
+ sc=standarized_coeffs
214
+ cse=coeffs_se
215
+ g.table(:name=>"Beta coefficients", :header=>%w{coeff b beta se t}.collect{|field| _(field)} ) do |t|
216
+ if (constant_se.nil?)
217
+ t.row([_("Constant"), sprintf("%0.3f", constant),"--","?","?"])
218
+ else
219
+ t.row([_("Constant"), sprintf("%0.3f", constant), "-", sprintf("%0.3f", constant_se), sprintf("%0.3f", constant_t)])
220
+ end
221
+
222
+ @fields.each do |f|
223
+ t.row([f, sprintf("%0.3f", c[f]), sprintf("%0.3f", sc[f]), sprintf("%0.3f", cse[f]), sprintf("%0.3f", c[f].quo(cse[f]))])
224
+ end
225
+ end
226
+ end
229
227
  end
230
-
231
-
232
228
  end
233
229
  end
234
230
  end
@@ -4,7 +4,28 @@ module Statsample
4
4
  module Test
5
5
  autoload(:UMannWhitney, 'statsample/test/umannwhitney')
6
6
  autoload(:Levene, 'statsample/test/levene')
7
-
7
+ autoload(:T, 'statsample/test/t')
8
+
9
+ # Returns probability of getting a value lower or higher
10
+ # than sample, using cdf and number of tails.
11
+ # * For one tail left, return the cdf
12
+ # * For one tail right, return 1-cdf
13
+ # * For two tails, returns 2*right_tail(cdf.abs)
14
+ def p_using_cdf(cdf, tails=:both)
15
+ tails=:both if tails==2
16
+ tails=:right if tails==1 or tails==:positive
17
+ tails=:left if tails==:negative
18
+ case tails
19
+ when :left then cdf
20
+ when :right then 1-cdf
21
+ when :both
22
+ if cdf>=0.5
23
+ cdf=1-cdf
24
+ end
25
+ 2*cdf
26
+ end
27
+ end
28
+ extend self
8
29
  # Calculate chi square for two Matrix
9
30
  class << self
10
31
  def chi_square(real,expected)
@@ -22,6 +43,20 @@ module Statsample
22
43
  def u_mannwhitney(v1p,v2p)
23
44
  Statsample::Test::UMannWhitney.new(v1p,v2p)
24
45
  end
46
+ # Shorthand for Statsample::Test::T::OneSample.new
47
+ def t_one_sample(vector, opts=Hash.new)
48
+ Statsample::Test::T::OneSample.new(vector,opts)
49
+ end
50
+ # Shorthand for Statsample::Test::T::TwoSamplesIndependent.new
51
+ def t_two_samples_independent(v1,v2, opts=Hash.new)
52
+ Statsample::Test::T::TwoSamplesIndependent.new(v1,v2,opts)
53
+ end
54
+
55
+ # Shorthand for Statsample::Test::Levene.new
56
+ def levene(input, opts=Hash.new)
57
+ Statsample::Test::Levene.new(input,opts)
58
+ end
59
+
25
60
  end
26
61
  end
27
62
  end
@@ -27,7 +27,11 @@ module Statsample
27
27
  attr_accessor :name
28
28
  # Input could be an array of vectors or a dataset
29
29
  def initialize(input, opts=Hash.new())
30
- @vectors=input
30
+ if input.is_a? Statsample::Dataset
31
+ @vectors=input.vectors.values
32
+ else
33
+ @vectors=input
34
+ end
31
35
  @name="Levene Test"
32
36
  opts.each{|k,v|
33
37
  self.send("#{k}=",v) if self.respond_to? k
@@ -39,15 +43,15 @@ module Statsample
39
43
  @w
40
44
  end
41
45
 
42
- def report_building(generator) # :nodoc:
43
- generator.text(summary)
44
-
46
+ def report_building(g) # :nodoc:
47
+ g.text @name
48
+ g.text "F: #{"%0.4f" % f}"
49
+ g.text "p: #{"%0.4f" % probability}"
50
+
45
51
  end
46
52
  # Summary of results
47
53
  def summary
48
- "#{@name}
49
- F: #{f}
50
- p: #{probability}"
54
+ ReportBuilder.new(:no_title=>true).add(self).to_text
51
55
  end
52
56
 
53
57
  def compute
@@ -0,0 +1,189 @@
1
+ module Statsample
2
+ module Test
3
+ module T
4
+ class << self
5
+ include Math
6
+ # Test the null hypothesis that the population mean is equal to a specified value u, one uses the statistic.
7
+ # Is the same formula used on t-test for paired sample.
8
+ # * <tt>x</tt>: sample/differences mean
9
+ # * <tt>u</tt>: population mean
10
+ # * <tt>s</tt>: sample/differences standard deviation
11
+ # * <tt>n</tt>: sample size
12
+ def one_sample(x,u,s,n)
13
+ (x-u).quo(s.quo(Math::sqrt(n)))
14
+ end
15
+ # Test if means of two samples are different.
16
+ # * <tt>x1</tt>: sample 1 mean
17
+ # * <tt>x2</tt>: sample 2 mean
18
+ # * <tt>s1</tt>: sample 1 standard deviation
19
+ # * <tt>s2</tt>: sample 2 standard deviation
20
+ # * <tt>n1</tt>: sample 1 size
21
+ # * <tt>n2</tt>: sample 2 size
22
+ # * <tt>equal_variance</tt>: true if equal_variance assumed
23
+ #
24
+ def two_sample_independent(x1, x2, s1, s2, n1, n2, equal_variance = false)
25
+ num=x1-x2
26
+ if equal_variance
27
+ sx1x2 = sqrt(((n1-1)*s1**2 + (n2-1)*s2**2).quo(n1+n2-2))
28
+ den = sx1x2*sqrt(1.quo(n1)+1.quo(n2))
29
+ else
30
+ den=sqrt((s1**2).quo(n1) + (s2**2).quo(n2))
31
+ end
32
+ num.quo(den)
33
+ end
34
+ # Degrees of freedom for equal variance
35
+ def df_equal_variance(n1,n2)
36
+ n1+n2-2
37
+ end
38
+ # Degrees of freedom for unequal variance
39
+ # * <tt>s1</tt>: sample 1 standard deviation
40
+ # * <tt>s2</tt>: sample 2 standard deviation
41
+ # * <tt>n1</tt>: sample 1 size
42
+ # * <tt>n2</tt>: sample 2 size
43
+ # == Reference
44
+ # * http://en.wikipedia.org/wiki/Welch-Satterthwaite_equation
45
+ def df_not_equal_variance(s1,s2,n1,n2)
46
+ s2_1=s1**2
47
+ s2_2=s2**2
48
+ num=(s2_1.quo(n1)+s2_2.quo(n2))**2
49
+ den=(s2_1.quo(n1)**2).quo(n1-1) + (s2_2.quo(n2)**2).quo(n2-1)
50
+ num.quo(den)
51
+ end
52
+ end
53
+ # One Sample t-test
54
+ # == Usage
55
+ # a=1000.times.map {rand(100)}.to_scale
56
+ # t_1=Statsample::Test::T::OneSample.new(a, {:u=>50})
57
+ # t_1.summary
58
+ class OneSample
59
+ include Math
60
+ include Statsample::Test
61
+ extend Statsample::PromiseAfter
62
+ # Options
63
+ attr_accessor :opts
64
+ # Name of test
65
+ attr_accessor :name
66
+ # Population mean to contrast
67
+ attr_accessor :u
68
+ # Degress of freedom
69
+ attr_reader :df
70
+ # Value of t
71
+ attr_reader :t
72
+ # Probability
73
+ attr_reader :probability
74
+ # Tails for probability (:both, :left or :right)
75
+ attr_accessor :tails
76
+ def initialize(vector, opts=Hash.new)
77
+ @vector=vector
78
+ default={:u=>0, :name=>"One Sample T Test", :tails=>:both}
79
+ @opts=default.merge(opts)
80
+ @name=@opts[:name]
81
+ @u=@opts[:u]
82
+ @tails=@opts[:tails]
83
+ @df= @vector.n_valid-1
84
+ @t=nil
85
+ end
86
+
87
+ promise_after :compute, :t, :probability
88
+
89
+ # Set t and probability for given u
90
+ def compute
91
+ @t = T.one_sample(@vector.mean, @u, @vector.sd, @vector.n_valid)
92
+ @probability = p_using_cdf(Distribution::T.cdf(@t, @df), tails)
93
+ end
94
+ # Presents summary of analysis
95
+ #
96
+ def summary
97
+ ReportBuilder.new(:no_title=>true).add(self).to_text
98
+ end
99
+ def report_building(b) # :nodoc:
100
+ b.section(:name=>@name) {|s|
101
+ s.text "Sample mean: #{@vector.mean}"
102
+ s.text "Population mean:#{u}"
103
+ s.text "Tails: #{tails}"
104
+ s.text sprintf("t = %0.4f, p=%0.4f, d.f=%d", t, probability, df)
105
+
106
+ }
107
+ end
108
+ end
109
+ # Two Sample t-test.
110
+ #
111
+ # == Usage
112
+ # a=1000.times.map {rand(100)}.to_scale
113
+ # b=1000.times.map {rand(100)}.to_scale
114
+ # t_2=Statsample::Test::T::OneSample.new(a,b)
115
+ # t_2.summary
116
+
117
+ class TwoSamplesIndependent
118
+ include Math
119
+ include Statsample::Test
120
+ extend Statsample::PromiseAfter
121
+ # Options
122
+ attr_accessor :opts
123
+ # Name of test
124
+ attr_accessor :name
125
+ # Degress of freedom (equal variance)
126
+ attr_reader :df_equal_variance
127
+ # Degress of freedom (not equal variance)
128
+ attr_reader :df_not_equal_variance
129
+ # Value of t for equal_variance
130
+ attr_reader :t_equal_variance
131
+ # Value of t for non-equal_variance
132
+ attr_reader :t_not_equal_variance
133
+ # Probability(equal variance)
134
+ attr_reader :probability_equal_variance
135
+ # Probability(unequal variance)
136
+ attr_reader :probability_not_equal_variance
137
+ # Tails for probability (:both, :left or :right)
138
+ attr_accessor :tails
139
+ # Create the object
140
+ def initialize(v1, v2, opts=Hash.new)
141
+ @v1=v1
142
+ @v2=v2
143
+ default={:u=>0, :name=>"Two Sample T Test", :paired_samples=>false, :tails=>:both}
144
+ @opts=default.merge(opts)
145
+ @name=@opts[:name]
146
+ @tails=@opts[:tails]
147
+ end
148
+
149
+ promise_after :compute, :t_equal_variance, :t_not_equal_variance, :probability_equal_variance, :probability_not_equal_variance, :df_equal_variance, :df_not_equal_variance
150
+
151
+ # Set t and probability for given u
152
+ def compute
153
+ @t_equal_variance= T.two_sample_independent(@v1.mean, @v2.mean, @v1.sd, @v2.sd, @v1.n_valid, @v2.n_valid,true)
154
+
155
+ @t_not_equal_variance= T.two_sample_independent(@v1.mean, @v2.mean, @v1.sd, @v2.sd, @v1.n_valid, @v2.n_valid, false)
156
+
157
+ @df_equal_variance=T.df_equal_variance(@v1.n_valid, @v2.n_valid)
158
+ @df_not_equal_variance=T.df_not_equal_variance(@v1.sd, @v2.sd, @v1.n_valid, @v2.n_valid)
159
+
160
+ @probability_equal_variance = p_using_cdf(Distribution::T.cdf(@t_equal_variance, @df_equal_variance), tails)
161
+
162
+ @probability_not_equal_variance = p_using_cdf(Distribution::T.cdf(@t_not_equal_variance, @df_not_equal_variance), tails)
163
+
164
+ end
165
+ # Presents summary of analysis
166
+ #
167
+ def summary
168
+ ReportBuilder.new(:no_title=>true).add(self).to_text
169
+ end
170
+ def report_building(b) # :nodoc:
171
+ b.section(:name=>@name) {|g|
172
+ g.table(:name=>"Mean and standard deviation", :header=>["Variable", "m", "sd","n"]) {|t|
173
+ t.row([1,"%0.4f" % @v1.mean,"%0.4f" % @v1.sd,@v1.n_valid])
174
+ t.row([2,"%0.4f" % @v2.mean,"%0.4f" % @v2.sd, @v2.n_valid])
175
+ }
176
+ g.section(:name=>"Levene Test") {|g1|
177
+ g1.parse_element(Statsample::Test.levene([@v1,@v2]))
178
+ }
179
+
180
+ g.table(:name=>"T statistics",:header=>["Type","t","df", "p (#{tails} tails)"]) {|t|
181
+ t.row(["Equal variance", "%0.4f" % t_equal_variance, df_equal_variance, "%0.4f" % probability_equal_variance])
182
+ t.row(["Non equal variance", "%0.4f" % t_not_equal_variance, "%0.4f" % df_not_equal_variance, "%0.4f" % probability_not_equal_variance])
183
+ }
184
+ }
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
data/test/test_anova.rb CHANGED
@@ -1,15 +1,13 @@
1
- $:.unshift(File.dirname(__FILE__)+'/../lib/')
2
- require 'statsample'
3
- require 'minitest/unit'
4
- MiniTest::Unit.autorun
1
+ require(File.dirname(__FILE__)+'/test_helpers.rb')
2
+
5
3
  class StatsampleAnovaTestCase < MiniTest::Unit::TestCase
6
- def initialize(*args)
4
+ def initialize(*args)
7
5
  @v1=[3,3,2,3,6].to_vector(:scale)
8
6
  @v2=[7,6,5,6,7].to_vector(:scale)
9
7
  @v3=[9,8,9,7,8].to_vector(:scale)
10
8
  @anova=Statsample::Anova::OneWay.new([@v1,@v2,@v3])
11
- super
12
- end
9
+ super
10
+ end
13
11
  def test_basic
14
12
  assert_in_delta(72.933, @anova.sst,0.001)
15
13
  assert_in_delta(14.8,@anova.sswg,0.001)
@@ -21,7 +19,7 @@ class StatsampleAnovaTestCase < MiniTest::Unit::TestCase
21
19
  assert_in_delta(23.568,@anova.f,0.001)
22
20
  anova2=Statsample::Anova::OneWay.new([@v1,@v1,@v1,@v1,@v2])
23
21
  assert_in_delta(3.960, anova2.f,0.001)
24
- assert(@anova.significance<0.01)
25
- assert_in_delta(0.016, anova2.significance,0.001)
22
+ assert(@anova.significance<0.01)
23
+ assert_in_delta(0.016, anova2.significance,0.001)
26
24
  end
27
- end
25
+ end