statsample 0.6.3 → 0.6.4

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.
@@ -0,0 +1,43 @@
1
+ $:.unshift(File.dirname(__FILE__)+'/../lib/')
2
+ require 'statsample'
3
+ require 'test/unit'
4
+
5
+ class StatsampleCSVTestCase < Test::Unit::TestCase
6
+ def aatest_dominance_univariate
7
+ # Example from Budescu (1993)
8
+ m=Matrix[[1, 0.683, 0.154, 0.460, 0.618],[0.683, 1, -0.050, 0.297, 0.461], [0.154, -0.050, 1, 0.006, 0.262],[0.460, 0.297, 0.006, 1, 0.507],[0.618, 0.461, 0.262, 0.507, 1]]
9
+ m.extend Statsample::CovariateMatrix
10
+ m.fields=%w{x1 x2 x3 x4 y}
11
+ da=Statsample::DominanceAnalysis.new(m,'y')
12
+
13
+ contr_x1={'x2'=>0.003, 'x3'=>0.028, 'x4'=>0.063}
14
+ contr_x1.each do |k,v|
15
+ assert_in_delta(v, da.models_data[['x1']].contributions[k], 0.001)
16
+ end
17
+ assert_in_delta(0.052, da.models_data[['x2','x3','x4']].contributions['x1'], 0.001)
18
+ expected_dominances=[1, 1, 0.5, 0.5, 0,0]
19
+ expected_g_dominances=[1, 1, 1, 1, 0,0]
20
+
21
+ da.pairs.each_with_index do |a,i|
22
+ assert_equal(expected_dominances[i], da.total_dominance_pairwise(a[0],a[1]))
23
+ assert_equal(expected_dominances[i], da.conditional_dominance_pairwise(a[0],a[1]))
24
+ assert_equal(expected_g_dominances[i], da.general_dominance_pairwise(a[0],a[1]))
25
+ end
26
+ end
27
+ def test_dominance_multivariate
28
+ m=Matrix[[1.0, -0.19, -0.358, -0.343, 0.359, 0.257], [-0.19, 1.0, 0.26, 0.29, -0.11, -0.11], [-0.358, 0.26, 1.0, 0.54, -0.49, -0.23], [-0.343, 0.29, 0.54, 1.0, -0.22, -0.41], [0.359, -0.11, -0.49, -0.22, 1.0, 0.62], [0.257, -0.11, -0.23, -0.41, 0.62, 1]]
29
+ m.extend Statsample::CovariateMatrix
30
+ m.fields=%w{y1 y2 x1 x2 x3 x4}
31
+ m2=m.submatrix(%w{y1 x1 x2 x3 x4})
32
+
33
+
34
+ da=Statsample::DominanceAnalysis.new(m, ['y1','y2'], :cases=>683, :method_association=>:p2yx)
35
+
36
+ contr_x1={'x2'=>0.027, 'x3'=>0.024, 'x4'=>0.017}
37
+ contr_x1.each do |k,v|
38
+ assert_in_delta(v, da.models_data[['x1']].contributions[k], 0.003)
39
+ end
40
+
41
+
42
+ end
43
+ end
@@ -0,0 +1,52 @@
1
+ $:.unshift(File.dirname(__FILE__)+'/../lib/')
2
+ require 'test/unit'
3
+ require 'statsample'
4
+
5
+ class StatsampleMatrixTestCase < Test::Unit::TestCase
6
+
7
+ def setup
8
+ end
9
+ def test_subindex
10
+ matrix=Matrix[[1,2,3],[4,5,6],[7,8,9]]
11
+ assert_equal(5, matrix[1,1])
12
+ assert_equal(Matrix[[1,2,3]], matrix[0,:*])
13
+ assert_equal(Matrix[[1],[4],[7]], matrix[:*,0])
14
+ assert_equal(Matrix[[1,2],[4,5],[7,8]], matrix[:*,0..1])
15
+ assert_equal(Matrix[[1,2],[4,5]], matrix[0..1,0..1])
16
+ end
17
+ def test_sums
18
+ matrix=Matrix[[1,2,3],[4,5,6],[7,8,9]]
19
+ assert_equal(6,matrix.row_sum[0])
20
+ assert_equal(12,matrix.column_sum[0])
21
+ assert_equal(45,matrix.total_sum)
22
+ m=matrix.to_gsl
23
+ end
24
+ def test_covariate
25
+ a=Matrix[[1.0, 0.3, 0.2], [0.3, 1.0, 0.5], [0.2, 0.5, 1.0]]
26
+ a.extend Statsample::CovariateMatrix
27
+ a.fields=%w{a b c}
28
+ assert_equal(:correlation, a.type)
29
+
30
+ assert_equal(Matrix[[0.5],[0.3]], a.submatrix(%w{c a}, %w{b}))
31
+ assert_equal(Matrix[[1.0, 0.2] , [0.2, 1.0]], a.submatrix(%w{c a}))
32
+ assert_equal(:correlation, a.submatrix(%w{c a}).type)
33
+
34
+ a=Matrix[[20,30,10], [30,60,50], [10,50,50]]
35
+
36
+ a.extend Statsample::CovariateMatrix
37
+
38
+ assert_equal(:covariance, a.type)
39
+
40
+ a=100.times.collect {rand()}.to_scale
41
+ b=100.times.collect {rand()}.to_scale
42
+ c=100.times.collect {rand()}.to_scale
43
+ ds={'a'=>a,'b'=>b,'c'=>c}.to_dataset
44
+ corr=Statsample::Bivariate.correlation_matrix(ds)
45
+ real=Statsample::Bivariate.covariance_matrix(ds).correlation
46
+ corr.row_size.times do |i|
47
+ corr.column_size.times do |j|
48
+ assert_in_delta(corr[i,j], real[i,j],1e-15)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -13,141 +13,186 @@ class StatsampleRegressionTestCase < Test::Unit::TestCase
13
13
  assert_in_delta(-0.957, @reg.b,0.001)
14
14
  assert_in_delta(4.248,@reg.standard_error,0.002)
15
15
  end
16
- def test_multiple_regression_pairwise_2
17
- @a=[1,3,2,4,3,5,4,6,5,7,3,nil,3,nil,3].to_vector(:scale)
18
- @b=[3,3,4,4,5,5,6,6,4,4,2,2,nil,6,2].to_vector(:scale)
19
- @c=[11,22,30,40,50,65,78,79,99,100,nil,3,7,nil,7].to_vector(:scale)
20
- @y=[3,4,5,6,7,8,9,10,20,30,30,40,nil,50,nil].to_vector(:scale)
21
- ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
22
- lr=Statsample::Regression::Multiple::RubyEngine.new(ds,'y')
23
- assert_in_delta(2407.436,lr.sst,0.001)
24
- assert_in_delta(0.752,lr.r,0.001)
25
- assert_in_delta(0.565,lr.r2,0.001)
26
- assert_in_delta(1361.130,lr.ssr,0.001)
27
- assert_in_delta(1046.306,lr.sse,0.001)
28
- assert_in_delta(3.035,lr.f,0.001)
29
-
30
- end
16
+ def test_multiple_dependent
17
+ complete=Matrix[
18
+ [1,0.53,0.62,0.19,-0.09,0.08,0.02,-0.12,0.08],
19
+ [0.53,1,0.61,0.23,0.1,0.18,0.02,-0.1,0.15],
20
+ [0.62,0.61,1,0.03,0.1,0.12,0.03,-0.06,0.12],
21
+ [0.19,0.23,0.03,1,-0.02,0.02,0,-0.02,-0.02],
22
+ [-0.09,0.1,0.1,-0.02,1,0.05,0.06,0.18,0.02],
23
+ [0.08,0.18,0.12,0.02,0.05,1,0.22,-0.07,0.36],
24
+ [0.02,0.02,0.03,0,0.06,0.22,1,-0.01,-0.05],
25
+ [-0.12,-0.1,-0.06,-0.02,0.18,-0.07,-0.01,1,-0.03],
26
+ [0.08,0.15,0.12,-0.02,0.02,0.36,-0.05,-0.03,1]]
27
+ complete.extend Statsample::CovariateMatrix
28
+ complete.fields=%w{adhd cd odd sex age monly mwork mage poverty}
29
+
30
+ lr=Statsample::Regression::Multiple::MultipleDependent.new(complete, %w{adhd cd odd})
31
+
32
+
33
+ assert_in_delta(0.197, lr.r2yx,0.001)
34
+ assert_in_delta(0.197, lr.r2yx_covariance,0.001)
35
+ assert_in_delta(0.07, lr.p2yx,0.001)
36
+
31
37
 
38
+ end
39
+ def test_multiple_regression_pairwise_2
40
+ @a=[1,3,2,4,3,5,4,6,5,7,3,nil,3,nil,3].to_vector(:scale)
41
+ @b=[3,3,4,4,5,5,6,6,4,4,2,2,nil,6,2].to_vector(:scale)
42
+ @c=[11,22,30,40,50,65,78,79,99,100,nil,3,7,nil,7].to_vector(:scale)
43
+ @y=[3,4,5,6,7,8,9,10,20,30,30,40,nil,50,nil].to_vector(:scale)
44
+ ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
45
+ lr=Statsample::Regression::Multiple::RubyEngine.new(ds,'y')
46
+ assert_in_delta(2407.436,lr.sst,0.001)
47
+ assert_in_delta(0.752,lr.r,0.001, "pairwise r")
48
+ assert_in_delta(0.565,lr.r2,0.001)
49
+ assert_in_delta(1361.130,lr.ssr,0.001)
50
+ assert_in_delta(1046.306,lr.sse,0.001)
51
+ assert_in_delta(3.035,lr.f,0.001)
52
+
53
+ end
32
54
 
33
- def test_multiple_regression_gsl
34
- if HAS_GSL
35
- @a=[1,3,2,4,3,5,4,6,5,7].to_vector(:scale)
36
- @b=[3,3,4,4,5,5,6,6,4,4].to_vector(:scale)
37
- @c=[11,22,30,40,50,65,78,79,99,100].to_vector(:scale)
38
- @y=[3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
39
- ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
40
- lr=Statsample::Regression::Multiple::GslEngine.new(ds,'y')
41
- model_test(lr)
42
- predicted=[1.7857, 6.0989, 3.2433, 7.2908, 4.9667, 10.3428, 8.8158, 10.4717, 23.6639, 25.3198]
43
- c_predicted=lr.predicted
44
- predicted.each_index{|i|
45
- assert_in_delta(predicted[i],c_predicted[i],0.001)
46
- }
47
- residuals=[1.2142, -2.0989, 1.7566, -1.29085, 2.033, -2.3428, 0.18414, -0.47177, -3.66395, 4.6801]
48
- c_residuals=lr.residuals
49
- residuals.each_index{|i|
50
- assert_in_delta(residuals[i],c_residuals[i],0.001)
51
- }
52
- else
53
- puts "Regression::Multiple::GslEngine not tested (no Gsl)"
54
- end
55
+
56
+ def test_multiple_regression_gsl
57
+ if HAS_GSL
58
+ @a=[1,3,2,4,3,5,4,6,5,7].to_vector(:scale)
59
+ @b=[3,3,4,4,5,5,6,6,4,4].to_vector(:scale)
60
+ @c=[11,22,30,40,50,65,78,79,99,100].to_vector(:scale)
61
+ @y=[3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
62
+ ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
63
+ lr=Statsample::Regression::Multiple::GslEngine.new(ds,'y')
64
+ model_test(lr,'gsl')
65
+ predicted=[1.7857, 6.0989, 3.2433, 7.2908, 4.9667, 10.3428, 8.8158, 10.4717, 23.6639, 25.3198]
66
+ c_predicted=lr.predicted
67
+ predicted.each_index{|i|
68
+ assert_in_delta(predicted[i],c_predicted[i],0.001)
69
+ }
70
+ residuals=[1.2142, -2.0989, 1.7566, -1.29085, 2.033, -2.3428, 0.18414, -0.47177, -3.66395, 4.6801]
71
+ c_residuals=lr.residuals
72
+ residuals.each_index{|i|
73
+ assert_in_delta(residuals[i],c_residuals[i],0.001)
74
+ }
75
+ else
76
+ puts "Regression::Multiple::GslEngine not tested (no Gsl)"
55
77
  end
78
+ end
56
79
 
57
80
 
58
- def test_multiple_regression_alglib
59
- if HAS_ALGIB
60
- @a=[1,3,2,4,3,5,4,6,5,7].to_vector(:scale)
61
- @b=[3,3,4,4,5,5,6,6,4,4].to_vector(:scale)
62
- @c=[11,22,30,40,50,65,78,79,99,100].to_vector(:scale)
63
- @y=[3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
64
- ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
65
- lr=Statsample::Regression::Multiple::AlglibEngine.new(ds,'y')
66
- model_test(lr)
67
- predicted=[1.7857, 6.0989, 3.2433, 7.2908, 4.9667, 10.3428, 8.8158, 10.4717, 23.6639, 25.3198]
68
- c_predicted=lr.predicted
69
- predicted.each_index{|i|
70
- assert_in_delta(predicted[i],c_predicted[i],0.001)
71
- }
72
- residuals=[1.2142, -2.0989, 1.7566, -1.29085, 2.033, -2.3428, 0.18414, -0.47177, -3.66395, 4.6801]
73
- c_residuals=lr.residuals
74
- residuals.each_index{|i|
75
- assert_in_delta(residuals[i],c_residuals[i],0.001)
76
- }
77
- else
78
- puts "Regression::Multiple::AlglibEngine not tested (no Alglib)"
79
- end
80
- end
81
- def model_test(lr)
82
- assert_in_delta(0.695,lr.coeffs['a'],0.001)
83
- assert_in_delta(11.027,lr.constant,0.001)
84
- assert_in_delta(1.785,lr.process([1,3,11]),0.001)
85
-
86
-
87
- s_coeffs={'a'=>0.151,'b'=>-0.547,'c'=>0.997}
88
- cs_coeefs=lr.standarized_coeffs
89
- s_coeffs.each_key{|k|
90
- assert_in_delta(s_coeffs[k], cs_coeefs[k],0.001)
91
- }
92
- assert_in_delta(639.6,lr.sst,0.001)
93
- assert_in_delta(583.76,lr.ssr,0.001)
94
- assert_in_delta(55.840,lr.sse,0.001)
95
- assert_in_delta(0.955,lr.r,0.001)
96
- assert_in_delta(0.913,lr.r2,0.001)
97
- assert_in_delta(20.908, lr.f,0.001)
98
- assert_in_delta(0.001, lr.significance, 0.001)
99
- assert_in_delta(0.226,lr.tolerance("a"),0.001)
100
- coeffs_se={"a"=>1.171,"b"=>1.129,"c"=>0.072}
101
- ccoeffs_se=lr.coeffs_se
102
- coeffs_se.each_key{|k|
103
- assert_in_delta(coeffs_se[k],ccoeffs_se[k],0.001)
104
- }
105
- coeffs_t={"a"=>0.594,"b"=>-3.796,"c"=>3.703}
106
- ccoeffs_t=lr.coeffs_t
107
- coeffs_t.each_key{|k|
108
- assert_in_delta(coeffs_t[k], ccoeffs_t[k],0.001)
109
- }
110
- assert_in_delta(4.559, lr.constant_se,0.001)
111
- assert_in_delta(2.419, lr.constant_t,0.001)
81
+ def test_multiple_regression_alglib
82
+ if HAS_ALGIB
83
+ @a=[1,3,2,4,3,5,4,6,5,7].to_vector(:scale)
84
+ @b=[3,3,4,4,5,5,6,6,4,4].to_vector(:scale)
85
+ @c=[11,22,30,40,50,65,78,79,99,100].to_vector(:scale)
86
+ @y=[3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
87
+ ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
88
+ lr=Statsample::Regression::Multiple::AlglibEngine.new(ds,'y')
89
+ model_test(lr,'alglib')
90
+ predicted=[1.7857, 6.0989, 3.2433, 7.2908, 4.9667, 10.3428, 8.8158, 10.4717, 23.6639, 25.3198]
91
+ c_predicted=lr.predicted
92
+ predicted.each_index{|i|
93
+ assert_in_delta(predicted[i],c_predicted[i],0.001)
94
+ }
95
+ residuals=[1.2142, -2.0989, 1.7566, -1.29085, 2.033, -2.3428, 0.18414, -0.47177, -3.66395, 4.6801]
96
+ c_residuals=lr.residuals
97
+ residuals.each_index{|i|
98
+ assert_in_delta(residuals[i],c_residuals[i],0.001)
99
+ }
100
+ else
101
+ puts "Regression::Multiple::AlglibEngine not tested (no Alglib)"
112
102
  end
113
- def test_regression_rubyengine
114
- @a=[nil,1,3,2,4,3,5,4,6,5,7].to_vector(:scale)
115
- @b=[nil,3,3,4,4,5,5,6,6,4,4].to_vector(:scale)
116
- @c=[nil,11,22,30,40,50,65,78,79,99,100].to_vector(:scale)
117
- @y=[nil,3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
118
- ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
119
- lr=Statsample::Regression::Multiple::RubyEngine.new(ds,'y')
120
- model_test(lr)
121
- predicted=[nil,1.7857, 6.0989, 3.2433, 7.2908, 4.9667, 10.3428, 8.8158, 10.4717, 23.6639, 25.3198]
122
- c_predicted = lr.predicted
123
-
124
- predicted.each_index{|i|
125
- if c_predicted[i].nil?
126
- assert(predicted[i].nil?)
127
- else
128
- assert_in_delta(predicted[i], c_predicted[i], 0.001)
129
- end
130
- }
131
- residuals=[nil,1.2142, -2.0989, 1.7566, -1.29085, 2.033, -2.3428, 0.18414, -0.47177, -3.66395, 4.6801]
132
- c_residuals=lr.residuals
133
- residuals.each_index{|i|
134
- if c_residuals[i].nil?
135
- assert(residuals[i].nil?)
136
- else
137
- assert_in_delta(residuals[i],c_residuals[i],0.001)
138
- end
139
- }
103
+ end
104
+ def model_test_matrix(lr,name='undefined')
105
+
106
+ stan_coeffs={'a'=>0.151,'b'=>-0.547,'c'=>0.997}
107
+ unstan_coeffs={'a'=>0.695, 'b'=>-4.286, 'c'=>0.266}
108
+
109
+ unstan_coeffs.each_key{|k|
110
+ assert_in_delta(unstan_coeffs[k], lr.coeffs[k],0.001,"b coeffs - #{name}")
111
+ }
112
+
113
+ stan_coeffs.each_key{|k|
114
+ assert_in_delta(stan_coeffs[k], lr.standarized_coeffs[k],0.001, "beta coeffs - #{name}")
115
+ }
116
+
117
+ assert_in_delta(11.027,lr.constant,0.001)
118
+
119
+ assert_in_delta(0.955,lr.r,0.001)
120
+ assert_in_delta(0.913,lr.r2,0.001)
121
+
122
+ assert_in_delta(20.908, lr.f,0.001)
123
+ assert_in_delta(0.001, lr.significance, 0.001)
124
+ assert_in_delta(0.226,lr.tolerance("a"),0.001)
125
+
126
+ coeffs_se={"a"=>1.171,"b"=>1.129,"c"=>0.072}
127
+
128
+
129
+
130
+ ccoeffs_se=lr.coeffs_se
131
+ coeffs_se.each_key{|k|
132
+ assert_in_delta(coeffs_se[k],ccoeffs_se[k],0.001)
133
+ }
134
+ coeffs_t={"a"=>0.594,"b"=>-3.796,"c"=>3.703}
135
+ ccoeffs_t=lr.coeffs_t
136
+ coeffs_t.each_key{|k|
137
+ assert_in_delta(coeffs_t[k], ccoeffs_t[k],0.001)
138
+ }
139
+
140
+ assert_in_delta(639.6,lr.sst,0.001)
141
+ assert_in_delta(583.76,lr.ssr,0.001)
142
+ assert_in_delta(55.840,lr.sse,0.001)
143
+
144
+ end
145
+ def model_test(lr,name='undefined')
146
+ model_test_matrix(lr,name)
147
+ assert_in_delta(4.559, lr.constant_se,0.001)
148
+ assert_in_delta(2.419, lr.constant_t,0.001)
149
+
150
+ assert_in_delta(1.785,lr.process([1,3,11]),0.001)
151
+ end
152
+ def test_regression_matrix
153
+ @a=[1,3,2,4,3,5,4,6,5,7].to_vector(:scale)
154
+ @b=[3,3,4,4,5,5,6,6,4,4].to_vector(:scale)
155
+ @c=[11,22,30,40,50,65,78,79,99,100].to_vector(:scale)
156
+ @y=[3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
157
+ ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
158
+
159
+ cor=Statsample::Bivariate.correlation_matrix(ds)
160
+ lr=Statsample::Regression::Multiple::MatrixEngine.new(cor,'y', :y_mean=>@y.mean, :x_mean=>{'a'=>ds['a'].mean, 'b'=>ds['b'].mean, 'c'=>ds['c'].mean}, :cases=>@a.size, :y_sd=>@y.sd , :x_sd=>{'a' => @a.sd, 'b' => @b.sd, 'c' => @c.sd})
161
+
162
+ model_test_matrix(lr, "correlation matrix")
163
+
164
+ covariance=Statsample::Bivariate.covariance_matrix(ds)
165
+ 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)
166
+ model_test_matrix(lr , "covariance matrix")
167
+ end
168
+ def test_regression_rubyengine
169
+ @a=[nil,1,3,2,4,3,5,4,6,5,7].to_vector(:scale)
170
+ @b=[nil,3,3,4,4,5,5,6,6,4,4].to_vector(:scale)
171
+ @c=[nil,11,22,30,40,50,65,78,79,99,100].to_vector(:scale)
172
+ @y=[nil,3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
173
+ ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
174
+ lr=Statsample::Regression::Multiple::RubyEngine.new(ds,'y')
175
+ model_test(lr, 'rubyengine with missing data')
176
+
177
+ predicted=[nil,1.7857, 6.0989, 3.2433, 7.2908, 4.9667, 10.3428, 8.8158, 10.4717, 23.6639, 25.3198]
178
+ c_predicted = lr.predicted
179
+
180
+ predicted.each_index do |i|
181
+ if c_predicted[i].nil?
182
+ assert(predicted[i].nil?)
183
+ else
184
+ assert_in_delta(predicted[i], c_predicted[i], 0.001)
185
+ end
140
186
  end
141
- def test_ds_by_exp
142
- @a= [1,3,2,4,3,5,4,6,5,7].to_vector(:scale)
143
- @b= [3,3,4,4,5,5,6,6,4,4].to_vector(:scale)
144
- @c= [11,22,30,40,50,65,78,79,99,100].to_vector(:scale)
145
- @d=%w{a b c a a c a a c a}.to_vector(:nominal)
146
- @y=[3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
147
- ds={'a'=>@a,'b'=>@b,'c'=>@c,'d'=>@d,'y'=>@y}.to_dataset
148
- #puts Statsample::Regression::Multiple.ds_by_exp(ds,"a+b=y")
149
- #puts Statsample::Regression::Multiple.ds_by_exp(ds,"a+b*d=y")
150
- #puts Statsample::Regression::Multiple.ds_by_exp(ds,"c+d=y")
187
+ residuals=[nil,1.2142, -2.0989, 1.7566, -1.29085, 2.033, -2.3428, 0.18414, -0.47177, -3.66395, 4.6801]
188
+ c_residuals=lr.residuals
189
+ residuals.each_index do |i|
190
+ if c_residuals[i].nil?
191
+ assert(residuals[i].nil?)
192
+ else
193
+ assert_in_delta(residuals[i],c_residuals[i],0.001)
194
+ end
151
195
  end
152
-
196
+
197
+ end
153
198
  end
@@ -8,58 +8,58 @@ begin
8
8
  require 'statsample/graph/svggraph'
9
9
  class StatsampleSvgGraphTestCase < Test::Unit::TestCase
10
10
 
11
- def initialize(*args)
12
- @image_path=Dir::tmpdir+"/images"
13
- FileUtils.mkdir(@image_path) if !File.exists? @image_path
14
- super
15
- end
16
- def test_histogram
17
- if HAS_GSL
18
- ar=(1..1000).to_a.collect {|a|
19
- rand(10)
20
- }.to_vector(:scale)
21
- h=ar.histogram([0,2,5,11])
22
- file=@image_path+"/svg_histogram_only.svg"
23
- graph = Statsample::Graph::SvgHistogram.new({})
24
- graph.histogram=h
25
- File.open(file,"w") {|f|
26
- f.puts(graph.burn)
27
- }
28
- else
29
- puts "Statsample::Graph::SvgHistogram.new not tested (no ruby-gsl)"
30
- end
11
+ def initialize(*args)
12
+ @image_path=Dir::tmpdir+"/images"
13
+ FileUtils.mkdir(@image_path) if !File.exists? @image_path
14
+ super
15
+ end
16
+ def test_histogram
17
+ if HAS_GSL
18
+ ar=(1..1000).to_a.collect {|a|
19
+ rand(10)
20
+ }.to_vector(:scale)
21
+ h=ar.histogram([0,2,5,11])
22
+ file=@image_path+"/svg_histogram_only.svg"
23
+ graph = Statsample::Graph::SvgHistogram.new({})
24
+ graph.histogram=h
25
+ File.open(file,"w") {|f|
26
+ f.puts(graph.burn)
27
+ }
28
+ else
29
+ puts "Statsample::Graph::SvgHistogram.new not tested (no ruby-gsl)"
31
30
  end
32
- def test_vector
33
- file=@image_path+"/gdchart_bar.jpg"
34
- ar=[]
35
- (1..1000).each {|a|
36
- ar.push(rand(10))
37
- }
38
- vector=ar.to_vector
39
- file=@image_path+"/svggraph_default.svg"
40
- vector.svggraph_frequencies(file)
41
- file=@image_path+"/svggraph_Bar.svg"
42
- vector.svggraph_frequencies(file,800,600,SVG::Graph::Bar,:graph_title=>'Bar')
43
- assert(File.exists?(file))
44
- file=@image_path+"/svggraph_BarHorizontal.svg"
45
- vector.svggraph_frequencies(file,800,600,SVG::Graph::BarHorizontalNoOp,:graph_title=>'Horizontal Bar')
46
- assert(File.exists?(file))
47
- file=@image_path+"/svggraph_Pie.svg"
48
- vector.svggraph_frequencies(file,800,600,SVG::Graph::PieNoOp,:graph_title=>'Pie')
49
- assert(File.exists?(file))
50
- vector.type=:scale
51
- if HAS_GSL
52
- file=@image_path+"/svggraph_histogram.svg"
53
- hist=vector.svggraph_histogram(5)
54
- File.open(file,"wb") {|fp|
55
- fp.write(hist.burn)
56
- }
57
- assert(File.exists?(file))
58
- else
59
- puts "Statsample::Vector#svggraph_histogram.new not tested (no ruby-gsl)"
60
-
61
- end
62
- end
31
+ end
32
+ def test_vector
33
+ file=@image_path+"/gdchart_bar.jpg"
34
+ ar=[]
35
+ (1..1000).each {|a|
36
+ ar.push(rand(10))
37
+ }
38
+ vector=ar.to_vector
39
+ file=@image_path+"/svggraph_default.svg"
40
+ vector.svggraph_frequencies(file)
41
+ file=@image_path+"/svggraph_Bar.svg"
42
+ vector.svggraph_frequencies(file,800,600,SVG::Graph::Bar,:graph_title=>'Bar')
43
+ assert(File.exists?(file))
44
+ file=@image_path+"/svggraph_BarHorizontal.svg"
45
+ vector.svggraph_frequencies(file,800,600,SVG::Graph::BarHorizontalNoOp,:graph_title=>'Horizontal Bar')
46
+ assert(File.exists?(file))
47
+ file=@image_path+"/svggraph_Pie.svg"
48
+ vector.svggraph_frequencies(file,800,600,SVG::Graph::PieNoOp,:graph_title=>'Pie')
49
+ assert(File.exists?(file))
50
+ vector.type=:scale
51
+ if HAS_GSL
52
+ file=@image_path+"/svggraph_histogram.svg"
53
+ hist=vector.svggraph_histogram(5)
54
+ File.open(file,"wb") {|fp|
55
+ fp.write(hist.burn)
56
+ }
57
+ assert(File.exists?(file))
58
+ else
59
+ puts "Statsample::Vector#svggraph_histogram.new not tested (no ruby-gsl)"
60
+
61
+ end
62
+ end
63
63
  end
64
64
  rescue LoadError
65
65
  puts "You should install SVG::Graph"