statsample 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -3
  3. data/History.txt +4 -0
  4. data/README.md +4 -0
  5. data/lib/statsample/converter/csv.rb +41 -54
  6. data/lib/statsample/converters.rb +18 -19
  7. data/lib/statsample/version.rb +1 -1
  8. data/test/fixtures/scientific_notation.csv +4 -0
  9. data/test/helpers_tests.rb +37 -38
  10. data/test/test_analysis.rb +96 -97
  11. data/test/test_anova_contrast.rb +22 -22
  12. data/test/test_anovaoneway.rb +12 -12
  13. data/test/test_anovatwoway.rb +16 -17
  14. data/test/test_anovatwowaywithdataset.rb +22 -24
  15. data/test/test_anovawithvectors.rb +67 -69
  16. data/test/test_awesome_print_bug.rb +9 -9
  17. data/test/test_bartlettsphericity.rb +13 -13
  18. data/test/test_bivariate.rb +122 -126
  19. data/test/test_codification.rb +51 -49
  20. data/test/test_crosstab.rb +44 -40
  21. data/test/test_csv.rb +52 -70
  22. data/test/test_dataset.rb +347 -330
  23. data/test/test_dominance_analysis.rb +22 -24
  24. data/test/test_factor.rb +163 -166
  25. data/test/test_factor_map.rb +25 -30
  26. data/test/test_factor_pa.rb +28 -28
  27. data/test/test_ggobi.rb +19 -18
  28. data/test/test_gsl.rb +13 -15
  29. data/test/test_histogram.rb +74 -77
  30. data/test/test_matrix.rb +29 -31
  31. data/test/test_multiset.rb +132 -126
  32. data/test/test_regression.rb +143 -149
  33. data/test/test_reliability.rb +149 -155
  34. data/test/test_reliability_icc.rb +100 -104
  35. data/test/test_reliability_skillscale.rb +38 -40
  36. data/test/test_resample.rb +14 -12
  37. data/test/test_rserve_extension.rb +33 -33
  38. data/test/test_srs.rb +5 -5
  39. data/test/test_statistics.rb +52 -50
  40. data/test/test_stest.rb +27 -28
  41. data/test/test_stratified.rb +10 -10
  42. data/test/test_test_f.rb +17 -17
  43. data/test/test_test_kolmogorovsmirnov.rb +21 -21
  44. data/test/test_test_t.rb +52 -52
  45. data/test/test_umannwhitney.rb +16 -16
  46. data/test/test_vector.rb +419 -410
  47. data/test/test_wilcoxonsignedrank.rb +60 -63
  48. data/test/test_xls.rb +41 -41
  49. metadata +55 -5
  50. data/web/Rakefile +0 -39
@@ -1,215 +1,210 @@
1
- require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
2
 
3
- class StatsampleRegressionTestCase < MiniTest::Unit::TestCase
4
- context "Example with missing data" do
5
- setup do
6
- @x=[0.285714285714286, 0.114285714285714, 0.314285714285714, 0.2, 0.2, 0.228571428571429, 0.2, 0.4, 0.714285714285714, 0.285714285714286, 0.285714285714286, 0.228571428571429, 0.485714285714286, 0.457142857142857, 0.257142857142857, 0.228571428571429, 0.285714285714286, 0.285714285714286, 0.285714285714286, 0.142857142857143, 0.285714285714286, 0.514285714285714, 0.485714285714286, 0.228571428571429, 0.285714285714286, 0.342857142857143, 0.285714285714286, 0.0857142857142857].to_scale
3
+ class StatsampleRegressionTestCase < Minitest::Test
4
+ context 'Example with missing data' do
5
+ setup do
6
+ @x = [0.285714285714286, 0.114285714285714, 0.314285714285714, 0.2, 0.2, 0.228571428571429, 0.2, 0.4, 0.714285714285714, 0.285714285714286, 0.285714285714286, 0.228571428571429, 0.485714285714286, 0.457142857142857, 0.257142857142857, 0.228571428571429, 0.285714285714286, 0.285714285714286, 0.285714285714286, 0.142857142857143, 0.285714285714286, 0.514285714285714, 0.485714285714286, 0.228571428571429, 0.285714285714286, 0.342857142857143, 0.285714285714286, 0.0857142857142857].to_scale
7
7
 
8
- @y=[nil, 0.233333333333333, nil, 0.266666666666667, 0.366666666666667, nil, 0.333333333333333, 0.3, 0.666666666666667, 0.0333333333333333, 0.333333333333333, nil, nil, 0.533333333333333, 0.433333333333333, 0.4, 0.4, 0.5, 0.4, 0.266666666666667, 0.166666666666667, 0.666666666666667, 0.433333333333333, 0.166666666666667, nil, 0.4, 0.366666666666667, nil].to_scale
9
- @ds={'x'=>@x,'y'=>@y}.to_dataset
10
- @lr=Statsample::Regression::Multiple::RubyEngine.new(@ds,'y')
8
+ @y = [nil, 0.233333333333333, nil, 0.266666666666667, 0.366666666666667, nil, 0.333333333333333, 0.3, 0.666666666666667, 0.0333333333333333, 0.333333333333333, nil, nil, 0.533333333333333, 0.433333333333333, 0.4, 0.4, 0.5, 0.4, 0.266666666666667, 0.166666666666667, 0.666666666666667, 0.433333333333333, 0.166666666666667, nil, 0.4, 0.366666666666667, nil].to_scale
9
+ @ds = { 'x' => @x, 'y' => @y }.to_dataset
10
+ @lr = Statsample::Regression::Multiple::RubyEngine.new(@ds, 'y')
11
+ end
12
+ should 'have correct values' do
13
+ assert_in_delta(0.455, @lr.r2, 0.001)
14
+ assert_in_delta(0.427, @lr.r2_adjusted, 0.001)
15
+ assert_in_delta(0.1165, @lr.se_estimate, 0.001)
16
+ assert_in_delta(15.925, @lr.f, 0.0001)
17
+ assert_in_delta(0.675, @lr.standarized_coeffs['x'], 0.001)
18
+ assert_in_delta(0.778, @lr.coeffs['x'], 0.001, 'coeff x')
19
+ assert_in_delta(0.132, @lr.constant, 0.001, 'constant')
20
+ assert_in_delta(0.195, @lr.coeffs_se['x'], 0.001, 'coeff x se')
21
+ assert_in_delta(0.064, @lr.constant_se, 0.001, 'constant se')
11
22
  end
12
- should "have correct values" do
13
- assert_in_delta(0.455,@lr.r2,0.001)
14
- assert_in_delta(0.427,@lr.r2_adjusted, 0.001)
15
- assert_in_delta(0.1165,@lr.se_estimate,0.001)
16
- assert_in_delta(15.925,@lr.f,0.0001)
17
- assert_in_delta(0.675, @lr.standarized_coeffs['x'],0.001)
18
- assert_in_delta(0.778, @lr.coeffs['x'],0.001, "coeff x")
19
- assert_in_delta(0.132, @lr.constant,0.001,"constant")
20
- assert_in_delta(0.195, @lr.coeffs_se['x'],0.001,"coeff x se")
21
- assert_in_delta(0.064, @lr.constant_se,0.001,"constant se")
22
- end
23
23
  end
24
- should "return an error if data is linearly dependent" do
25
- samples=100
26
-
27
- a,b=rand,rand
28
-
29
- x1=samples.times.map { rand}.to_scale
30
- x2=samples.times.map {rand}.to_scale
31
- x3=samples.times.map {|i| x1[i]*(1+a)+x2[i]*(1+b)}.to_scale
32
- y=samples.times.map {|i| x1[i]+x2[i]+x3[i]+rand}.to_scale
33
-
34
- ds={'x1'=>x1,'x2'=>x2,'x3'=>x3,'y'=>y}.to_dataset
24
+ should 'return an error if data is linearly dependent' do
25
+ samples = 100
26
+
27
+ a, b = rand, rand
28
+
29
+ x1 = samples.times.map { rand }.to_scale
30
+ x2 = samples.times.map { rand }.to_scale
31
+ x3 = samples.times.map { |i| x1[i] * (1 + a) + x2[i] * (1 + b) }.to_scale
32
+ y = samples.times.map { |i| x1[i] + x2[i] + x3[i] + rand }.to_scale
33
+
34
+ ds = { 'x1' => x1, 'x2' => x2, 'x3' => x3, 'y' => y }.to_dataset
35
35
 
36
36
  assert_raise(Statsample::Regression::LinearDependency) {
37
- Statsample::Regression::Multiple::RubyEngine.new(ds,'y')
37
+ Statsample::Regression::Multiple::RubyEngine.new(ds, 'y')
38
38
  }
39
39
  end
40
40
  def test_parameters
41
- @x=[13,20,10,33,15].to_vector(:scale)
42
- @y=[23,18,35,10,27 ].to_vector(:scale)
43
- reg=Statsample::Regression::Simple.new_from_vectors(@x,@y)
41
+ @x = [13, 20, 10, 33, 15].to_vector(:scale)
42
+ @y = [23, 18, 35, 10, 27].to_vector(:scale)
43
+ reg = Statsample::Regression::Simple.new_from_vectors(@x, @y)
44
44
  _test_simple_regression(reg)
45
- ds={'x'=>@x,'y'=>@y}.to_dataset
46
- reg=Statsample::Regression::Simple.new_from_dataset(ds,'x','y')
45
+ ds = { 'x' => @x, 'y' => @y }.to_dataset
46
+ reg = Statsample::Regression::Simple.new_from_dataset(ds, 'x', 'y')
47
47
  _test_simple_regression(reg)
48
- reg=Statsample::Regression.simple(@x,@y)
48
+ reg = Statsample::Regression.simple(@x, @y)
49
49
  _test_simple_regression(reg)
50
-
51
50
  end
51
+
52
52
  def _test_simple_regression(reg)
53
-
54
- assert_in_delta(40.009, reg.a,0.001)
55
- assert_in_delta(-0.957, reg.b,0.001)
56
- assert_in_delta(4.248,reg.standard_error,0.002)
53
+ assert_in_delta(40.009, reg.a, 0.001)
54
+ assert_in_delta(-0.957, reg.b, 0.001)
55
+ assert_in_delta(4.248, reg.standard_error, 0.002)
57
56
  assert(reg.summary)
58
57
  end
59
-
58
+
60
59
  def test_summaries
61
- a=10.times.map{rand(100)}.to_scale
62
- b=10.times.map{rand(100)}.to_scale
63
- y=10.times.map{rand(100)}.to_scale
64
- ds={'a'=>a,'b'=>b,'y'=>y}.to_dataset
65
- lr=Statsample::Regression::Multiple::RubyEngine.new(ds,'y')
66
- assert(lr.summary.size>0)
60
+ a = 10.times.map { rand(100) }.to_scale
61
+ b = 10.times.map { rand(100) }.to_scale
62
+ y = 10.times.map { rand(100) }.to_scale
63
+ ds = { 'a' => a, 'b' => b, 'y' => y }.to_dataset
64
+ lr = Statsample::Regression::Multiple::RubyEngine.new(ds, 'y')
65
+ assert(lr.summary.size > 0)
67
66
  end
67
+
68
68
  def test_multiple_dependent
69
- complete=Matrix[
70
- [1,0.53,0.62,0.19,-0.09,0.08,0.02,-0.12,0.08],
71
- [0.53,1,0.61,0.23,0.1,0.18,0.02,-0.1,0.15],
72
- [0.62,0.61,1,0.03,0.1,0.12,0.03,-0.06,0.12],
73
- [0.19,0.23,0.03,1,-0.02,0.02,0,-0.02,-0.02],
74
- [-0.09,0.1,0.1,-0.02,1,0.05,0.06,0.18,0.02],
75
- [0.08,0.18,0.12,0.02,0.05,1,0.22,-0.07,0.36],
76
- [0.02,0.02,0.03,0,0.06,0.22,1,-0.01,-0.05],
77
- [-0.12,-0.1,-0.06,-0.02,0.18,-0.07,-0.01,1,-0.03],
78
- [0.08,0.15,0.12,-0.02,0.02,0.36,-0.05,-0.03,1]]
69
+ complete = Matrix[
70
+ [1, 0.53, 0.62, 0.19, -0.09, 0.08, 0.02, -0.12, 0.08],
71
+ [0.53, 1, 0.61, 0.23, 0.1, 0.18, 0.02, -0.1, 0.15],
72
+ [0.62, 0.61, 1, 0.03, 0.1, 0.12, 0.03, -0.06, 0.12],
73
+ [0.19, 0.23, 0.03, 1, -0.02, 0.02, 0, -0.02, -0.02],
74
+ [-0.09, 0.1, 0.1, -0.02, 1, 0.05, 0.06, 0.18, 0.02],
75
+ [0.08, 0.18, 0.12, 0.02, 0.05, 1, 0.22, -0.07, 0.36],
76
+ [0.02, 0.02, 0.03, 0, 0.06, 0.22, 1, -0.01, -0.05],
77
+ [-0.12, -0.1, -0.06, -0.02, 0.18, -0.07, -0.01, 1, -0.03],
78
+ [0.08, 0.15, 0.12, -0.02, 0.02, 0.36, -0.05, -0.03, 1]]
79
79
  complete.extend Statsample::CovariateMatrix
80
- complete.fields=%w{adhd cd odd sex age monly mwork mage poverty}
80
+ complete.fields = %w(adhd cd odd sex age monly mwork mage poverty)
81
81
 
82
- lr=Statsample::Regression::Multiple::MultipleDependent.new(complete, %w{adhd cd odd})
83
-
84
-
85
- assert_in_delta(0.197, lr.r2yx,0.001)
86
- assert_in_delta(0.197, lr.r2yx_covariance,0.001)
87
- assert_in_delta(0.07, lr.p2yx,0.001)
82
+ lr = Statsample::Regression::Multiple::MultipleDependent.new(complete, %w(adhd cd odd))
88
83
 
84
+ assert_in_delta(0.197, lr.r2yx, 0.001)
85
+ assert_in_delta(0.197, lr.r2yx_covariance, 0.001)
86
+ assert_in_delta(0.07, lr.p2yx, 0.001)
89
87
  end
90
-
88
+
91
89
  def test_multiple_regression_pairwise_2
92
- @a=[1,3,2,4,3,5,4,6,5,7,3,nil,3,nil,3].to_vector(:scale)
93
- @b=[3,3,4,4,5,5,6,6,4,4,2,2,nil,6,2].to_vector(:scale)
94
- @c=[11,22,30,40,50,65,78,79,99,100,nil,3,7,nil,7].to_vector(:scale)
95
- @y=[3,4,5,6,7,8,9,10,20,30,30,40,nil,50,nil].to_vector(:scale)
96
- ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
97
- lr=Statsample::Regression::Multiple::RubyEngine.new(ds,'y')
98
- assert_in_delta(2407.436,lr.sst,0.001)
99
- assert_in_delta(0.752,lr.r,0.001, "pairwise r")
100
- assert_in_delta(0.565,lr.r2,0.001)
101
- assert_in_delta(1361.130,lr.ssr,0.001)
102
- assert_in_delta(1046.306,lr.sse,0.001)
103
- assert_in_delta(3.035,lr.f,0.001)
90
+ @a = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 3, nil, 3, nil, 3].to_vector(:scale)
91
+ @b = [3, 3, 4, 4, 5, 5, 6, 6, 4, 4, 2, 2, nil, 6, 2].to_vector(:scale)
92
+ @c = [11, 22, 30, 40, 50, 65, 78, 79, 99, 100, nil, 3, 7, nil, 7].to_vector(:scale)
93
+ @y = [3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 40, nil, 50, nil].to_vector(:scale)
94
+ ds = { 'a' => @a, 'b' => @b, 'c' => @c, 'y' => @y }.to_dataset
95
+ lr = Statsample::Regression::Multiple::RubyEngine.new(ds, 'y')
96
+ assert_in_delta(2407.436, lr.sst, 0.001)
97
+ assert_in_delta(0.752, lr.r, 0.001, 'pairwise r')
98
+ assert_in_delta(0.565, lr.r2, 0.001)
99
+ assert_in_delta(1361.130, lr.ssr, 0.001)
100
+ assert_in_delta(1046.306, lr.sse, 0.001)
101
+ assert_in_delta(3.035, lr.f, 0.001)
104
102
  end
105
103
 
106
-
107
104
  def test_multiple_regression_gsl
108
105
  if Statsample.has_gsl?
109
- @a=[1,3,2,4,3,5,4,6,5,7].to_vector(:scale)
110
- @b=[3,3,4,4,5,5,6,6,4,4].to_vector(:scale)
111
- @c=[11,22,30,40,50,65,78,79,99,100].to_vector(:scale)
112
- @y=[3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
113
- ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
114
- lr=Statsample::Regression::Multiple::GslEngine.new(ds,'y')
115
- assert(lr.summary.size>0)
116
- model_test(lr,'gsl')
117
- predicted=[1.7857, 6.0989, 3.2433, 7.2908, 4.9667, 10.3428, 8.8158, 10.4717, 23.6639, 25.3198]
118
- c_predicted=lr.predicted
106
+ @a = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7].to_vector(:scale)
107
+ @b = [3, 3, 4, 4, 5, 5, 6, 6, 4, 4].to_vector(:scale)
108
+ @c = [11, 22, 30, 40, 50, 65, 78, 79, 99, 100].to_vector(:scale)
109
+ @y = [3, 4, 5, 6, 7, 8, 9, 10, 20, 30].to_vector(:scale)
110
+ ds = { 'a' => @a, 'b' => @b, 'c' => @c, 'y' => @y }.to_dataset
111
+ lr = Statsample::Regression::Multiple::GslEngine.new(ds, 'y')
112
+ assert(lr.summary.size > 0)
113
+ model_test(lr, 'gsl')
114
+ predicted = [1.7857, 6.0989, 3.2433, 7.2908, 4.9667, 10.3428, 8.8158, 10.4717, 23.6639, 25.3198]
115
+ c_predicted = lr.predicted
119
116
  predicted.each_index{|i|
120
- assert_in_delta(predicted[i],c_predicted[i],0.001)
117
+ assert_in_delta(predicted[i], c_predicted[i], 0.001)
121
118
  }
122
- residuals=[1.2142, -2.0989, 1.7566, -1.29085, 2.033, -2.3428, 0.18414, -0.47177, -3.66395, 4.6801]
123
- c_residuals=lr.residuals
119
+ residuals = [1.2142, -2.0989, 1.7566, -1.29085, 2.033, -2.3428, 0.18414, -0.47177, -3.66395, 4.6801]
120
+ c_residuals = lr.residuals
124
121
  residuals.each_index{|i|
125
- assert_in_delta(residuals[i],c_residuals[i],0.001)
122
+ assert_in_delta(residuals[i], c_residuals[i], 0.001)
126
123
  }
127
124
  else
128
- skip "Regression::Multiple::GslEngine not tested (no Gsl)"
125
+ skip 'Regression::Multiple::GslEngine not tested (no Gsl)'
129
126
  end
130
127
  end
131
128
 
132
-
133
-
134
- def model_test_matrix(lr,name='undefined')
135
-
136
- stan_coeffs={'a'=>0.151,'b'=>-0.547,'c'=>0.997}
137
- unstan_coeffs={'a'=>0.695, 'b'=>-4.286, 'c'=>0.266}
129
+ def model_test_matrix(lr, name = 'undefined')
130
+ stan_coeffs = { 'a' => 0.151, 'b' => -0.547, 'c' => 0.997 }
131
+ unstan_coeffs = { 'a' => 0.695, 'b' => -4.286, 'c' => 0.266 }
138
132
 
139
133
  unstan_coeffs.each_key{|k|
140
- assert_in_delta(unstan_coeffs[k], lr.coeffs[k],0.001,"b coeffs - #{name}")
134
+ assert_in_delta(unstan_coeffs[k], lr.coeffs[k], 0.001, "b coeffs - #{name}")
141
135
  }
142
136
 
143
137
  stan_coeffs.each_key{|k|
144
- assert_in_delta(stan_coeffs[k], lr.standarized_coeffs[k],0.001, "beta coeffs - #{name}")
138
+ assert_in_delta(stan_coeffs[k], lr.standarized_coeffs[k], 0.001, "beta coeffs - #{name}")
145
139
  }
146
140
 
147
- assert_in_delta(11.027,lr.constant,0.001)
141
+ assert_in_delta(11.027, lr.constant, 0.001)
148
142
 
149
- assert_in_delta(0.955,lr.r,0.001)
150
- assert_in_delta(0.913,lr.r2,0.001)
143
+ assert_in_delta(0.955, lr.r, 0.001)
144
+ assert_in_delta(0.913, lr.r2, 0.001)
151
145
 
152
- assert_in_delta(20.908, lr.f,0.001)
146
+ assert_in_delta(20.908, lr.f, 0.001)
153
147
  assert_in_delta(0.001, lr.probability, 0.001)
154
- assert_in_delta(0.226,lr.tolerance("a"),0.001)
155
-
156
- coeffs_se={"a"=>1.171,"b"=>1.129,"c"=>0.072}
148
+ assert_in_delta(0.226, lr.tolerance('a'), 0.001)
157
149
 
150
+ coeffs_se = { 'a' => 1.171, 'b' => 1.129, 'c' => 0.072 }
158
151
 
159
-
160
- ccoeffs_se=lr.coeffs_se
152
+ ccoeffs_se = lr.coeffs_se
161
153
  coeffs_se.each_key{|k|
162
- assert_in_delta(coeffs_se[k],ccoeffs_se[k],0.001)
154
+ assert_in_delta(coeffs_se[k], ccoeffs_se[k], 0.001)
163
155
  }
164
- coeffs_t={"a"=>0.594,"b"=>-3.796,"c"=>3.703}
165
- ccoeffs_t=lr.coeffs_t
156
+ coeffs_t = { 'a' => 0.594, 'b' => -3.796, 'c' => 3.703 }
157
+ ccoeffs_t = lr.coeffs_t
166
158
  coeffs_t.each_key{|k|
167
- assert_in_delta(coeffs_t[k], ccoeffs_t[k],0.001)
159
+ assert_in_delta(coeffs_t[k], ccoeffs_t[k], 0.001)
168
160
  }
169
161
 
170
- assert_in_delta(639.6,lr.sst,0.001)
171
- assert_in_delta(583.76,lr.ssr,0.001)
172
- assert_in_delta(55.840,lr.sse,0.001)
173
- assert(lr.summary.size>0, "#{name} without summary")
162
+ assert_in_delta(639.6, lr.sst, 0.001)
163
+ assert_in_delta(583.76, lr.ssr, 0.001)
164
+ assert_in_delta(55.840, lr.sse, 0.001)
165
+ assert(lr.summary.size > 0, "#{name} without summary")
174
166
  end
175
- def model_test(lr,name='undefined')
176
- model_test_matrix(lr,name)
177
- assert_in_delta(4.559, lr.constant_se,0.001)
178
- assert_in_delta(2.419, lr.constant_t,0.001)
179
167
 
180
- assert_in_delta(1.785,lr.process([1,3,11]),0.001)
168
+ def model_test(lr, name = 'undefined')
169
+ model_test_matrix(lr, name)
170
+ assert_in_delta(4.559, lr.constant_se, 0.001)
171
+ assert_in_delta(2.419, lr.constant_t, 0.001)
172
+
173
+ assert_in_delta(1.785, lr.process([1, 3, 11]), 0.001)
181
174
  end
175
+
182
176
  def test_regression_matrix
183
- @a=[1,3,2,4,3,5,4,6,5,7].to_vector(:scale)
184
- @b=[3,3,4,4,5,5,6,6,4,4].to_vector(:scale)
185
- @c=[11,22,30,40,50,65,78,79,99,100].to_vector(:scale)
186
- @y=[3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
187
- ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
188
- cor=Statsample::Bivariate.correlation_matrix(ds)
189
-
190
- 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})
177
+ @a = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7].to_vector(:scale)
178
+ @b = [3, 3, 4, 4, 5, 5, 6, 6, 4, 4].to_vector(:scale)
179
+ @c = [11, 22, 30, 40, 50, 65, 78, 79, 99, 100].to_vector(:scale)
180
+ @y = [3, 4, 5, 6, 7, 8, 9, 10, 20, 30].to_vector(:scale)
181
+ ds = { 'a' => @a, 'b' => @b, 'c' => @c, 'y' => @y }.to_dataset
182
+ cor = Statsample::Bivariate.correlation_matrix(ds)
183
+
184
+ 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 })
191
185
  assert_nil(lr.constant_se)
192
186
  assert_nil(lr.constant_t)
193
- model_test_matrix(lr, "correlation matrix")
187
+ model_test_matrix(lr, 'correlation matrix')
194
188
 
195
- covariance=Statsample::Bivariate.covariance_matrix(ds)
196
- 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)
197
- assert(lr.summary.size>0)
189
+ covariance = Statsample::Bivariate.covariance_matrix(ds)
190
+ 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)
191
+ assert(lr.summary.size > 0)
198
192
 
199
- model_test(lr , "covariance matrix")
193
+ model_test(lr, 'covariance matrix')
200
194
  end
195
+
201
196
  def test_regression_rubyengine
202
- @a=[nil,1,3,2,4,3,5,4,6,5,7].to_vector(:scale)
203
- @b=[nil,3,3,4,4,5,5,6,6,4,4].to_vector(:scale)
204
- @c=[nil,11,22,30,40,50,65,78,79,99,100].to_vector(:scale)
205
- @y=[nil,3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
206
- ds={'a'=>@a,'b'=>@b,'c'=>@c,'y'=>@y}.to_dataset
207
- lr=Statsample::Regression::Multiple::RubyEngine.new(ds,'y')
197
+ @a = [nil, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7].to_vector(:scale)
198
+ @b = [nil, 3, 3, 4, 4, 5, 5, 6, 6, 4, 4].to_vector(:scale)
199
+ @c = [nil, 11, 22, 30, 40, 50, 65, 78, 79, 99, 100].to_vector(:scale)
200
+ @y = [nil, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30].to_vector(:scale)
201
+ ds = { 'a' => @a, 'b' => @b, 'c' => @c, 'y' => @y }.to_dataset
202
+ lr = Statsample::Regression::Multiple::RubyEngine.new(ds, 'y')
208
203
  assert_equal(11, lr.total_cases)
209
204
  assert_equal(10, lr.valid_cases)
210
205
  model_test(lr, 'rubyengine with missing data')
211
206
 
212
- predicted=[nil,1.7857, 6.0989, 3.2433, 7.2908, 4.9667, 10.3428, 8.8158, 10.4717, 23.6639, 25.3198]
207
+ predicted = [nil, 1.7857, 6.0989, 3.2433, 7.2908, 4.9667, 10.3428, 8.8158, 10.4717, 23.6639, 25.3198]
213
208
  c_predicted = lr.predicted
214
209
  predicted.each_index do |i|
215
210
  if c_predicted[i].nil?
@@ -218,15 +213,14 @@ class StatsampleRegressionTestCase < MiniTest::Unit::TestCase
218
213
  assert_in_delta(predicted[i], c_predicted[i], 0.001)
219
214
  end
220
215
  end
221
- residuals=[nil,1.2142, -2.0989, 1.7566, -1.29085, 2.033, -2.3428, 0.18414, -0.47177, -3.66395, 4.6801]
222
- c_residuals=lr.residuals
216
+ residuals = [nil, 1.2142, -2.0989, 1.7566, -1.29085, 2.033, -2.3428, 0.18414, -0.47177, -3.66395, 4.6801]
217
+ c_residuals = lr.residuals
223
218
  residuals.each_index do |i|
224
219
  if c_residuals[i].nil?
225
220
  assert(residuals[i].nil?)
226
221
  else
227
- assert_in_delta(residuals[i],c_residuals[i],0.001)
222
+ assert_in_delta(residuals[i], c_residuals[i], 0.001)
228
223
  end
229
224
  end
230
-
231
225
  end
232
226
  end
@@ -1,229 +1,223 @@
1
- require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
2
- class StatsampleReliabilityTestCase < MiniTest::Unit::TestCase
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
+ class StatsampleReliabilityTestCase < Minitest::Test
3
3
  context Statsample::Reliability do
4
- should "return correct r according to Spearman-Brown prophecy" do
5
- r=0.6849
6
- n=62.quo(15)
7
- assert_in_delta(0.9, Statsample::Reliability.sbp(r,n), 0.001)
4
+ should 'return correct r according to Spearman-Brown prophecy' do
5
+ r = 0.6849
6
+ n = 62.quo(15)
7
+ assert_in_delta(0.9, Statsample::Reliability.sbp(r, n), 0.001)
8
8
  end
9
- should "return correct n for desired realiability" do
10
- r=0.6849
11
- r_d=0.9
12
- assert_in_delta(62, Statsample::Reliability.n_for_desired_reliability(r, r_d, 15),0.5)
13
- end
14
- context "Cronbach's alpha" do
9
+ should 'return correct n for desired realiability' do
10
+ r = 0.6849
11
+ r_d = 0.9
12
+ assert_in_delta(62, Statsample::Reliability.n_for_desired_reliability(r, r_d, 15), 0.5)
13
+ end
14
+ context "Cronbach's alpha" do
15
15
  setup do
16
- @samples=40
17
- @n_variables=rand(10)+2
18
- @ds=Statsample::Dataset.new()
19
- base=@samples.times.collect {|a| rand()}.to_scale
16
+ @samples = 40
17
+ @n_variables = rand(10) + 2
18
+ @ds = Statsample::Dataset.new
19
+ base = @samples.times.collect { |_a| rand }.to_scale
20
20
  @n_variables.times do |i|
21
- @ds[i]=base.collect {|v| v+rand()}.to_scale
21
+ @ds[i] = base.collect { |v| v + rand }.to_scale
22
22
  end
23
-
23
+
24
24
  @ds.update_valid_data
25
- @k=@ds.fields.size
26
- @cm=Statsample::Bivariate.covariance_matrix(@ds)
27
- @dse=@ds.dup
25
+ @k = @ds.fields.size
26
+ @cm = Statsample::Bivariate.covariance_matrix(@ds)
27
+ @dse = @ds.dup
28
28
  @dse.fields.each do |f|
29
- @dse[f]=@dse[f].standarized
29
+ @dse[f] = @dse[f].standarized
30
30
  end
31
- @cme=Statsample::Bivariate.covariance_matrix(@dse)
32
- @a=Statsample::Reliability.cronbach_alpha(@ds)
33
- @as=Statsample::Reliability.cronbach_alpha_standarized(@ds)
34
- end
35
- should "alpha will be equal to sum of matrix covariance less the individual variances" do
36
- total_sum=@cm.total_sum
37
- ind_var=@ds.fields.inject(0) {|ac,v| ac+@ds[v].variance}
38
- expected = @k.quo(@k-1) * (1-(ind_var.quo(total_sum)))
39
- assert_in_delta(expected, @a,1e-10)
40
- end
41
- should "method cronbach_alpha_from_n_s2_cov return correct values" do
42
- sa=Statsample::Reliability::ScaleAnalysis.new(@ds)
31
+ @cme = Statsample::Bivariate.covariance_matrix(@dse)
32
+ @a = Statsample::Reliability.cronbach_alpha(@ds)
33
+ @as = Statsample::Reliability.cronbach_alpha_standarized(@ds)
34
+ end
35
+ should 'alpha will be equal to sum of matrix covariance less the individual variances' do
36
+ total_sum = @cm.total_sum
37
+ ind_var = @ds.fields.inject(0) { |ac, v| ac + @ds[v].variance }
38
+ expected = @k.quo(@k - 1) * (1 - (ind_var.quo(total_sum)))
39
+ assert_in_delta(expected, @a, 1e-10)
40
+ end
41
+ should 'method cronbach_alpha_from_n_s2_cov return correct values' do
42
+ sa = Statsample::Reliability::ScaleAnalysis.new(@ds)
43
43
  vm, cm = sa.variances_mean, sa.covariances_mean
44
- assert_in_delta(sa.alpha, Statsample::Reliability.cronbach_alpha_from_n_s2_cov(@n_variables, vm,cm), 1e-10)
44
+ assert_in_delta(sa.alpha, Statsample::Reliability.cronbach_alpha_from_n_s2_cov(@n_variables, vm, cm), 1e-10)
45
45
  end
46
- should "method cronbach_alpha_from_covariance_matrix returns correct value" do
47
- cov=Statsample::Bivariate.covariance_matrix(@ds)
48
- assert_in_delta(@a, Statsample::Reliability.cronbach_alpha_from_covariance_matrix(cov),0.0000001)
46
+ should 'method cronbach_alpha_from_covariance_matrix returns correct value' do
47
+ cov = Statsample::Bivariate.covariance_matrix(@ds)
48
+ assert_in_delta(@a, Statsample::Reliability.cronbach_alpha_from_covariance_matrix(cov), 0.0000001)
49
49
  end
50
- should "return correct n for desired alpha, covariance and variance" do
51
- sa=Statsample::Reliability::ScaleAnalysis.new(@ds)
50
+ should 'return correct n for desired alpha, covariance and variance' do
51
+ sa = Statsample::Reliability::ScaleAnalysis.new(@ds)
52
52
  vm, cm = sa.variances_mean, sa.covariances_mean
53
- n_obtained=Statsample::Reliability.n_for_desired_alpha(@a, vm,cm)
54
- #p n_obtained
55
- assert_in_delta(Statsample::Reliability.cronbach_alpha_from_n_s2_cov(n_obtained, vm,cm) ,@a,0.001)
56
- end
57
-
58
- should "standarized alpha will be equal to sum of matrix covariance less the individual variances on standarized values" do
59
- total_sum=@cme.total_sum
60
- ind_var=@dse.fields.inject(0) {|ac,v| ac+@dse[v].variance}
61
- expected = @k.quo(@k-1) * (1-(ind_var.quo(total_sum)))
53
+ n_obtained = Statsample::Reliability.n_for_desired_alpha(@a, vm, cm)
54
+ # p n_obtained
55
+ assert_in_delta(Statsample::Reliability.cronbach_alpha_from_n_s2_cov(n_obtained, vm, cm), @a, 0.001)
56
+ end
57
+
58
+ should 'standarized alpha will be equal to sum of matrix covariance less the individual variances on standarized values' do
59
+ total_sum = @cme.total_sum
60
+ ind_var = @dse.fields.inject(0) { |ac, v| ac + @dse[v].variance }
61
+ expected = @k.quo(@k - 1) * (1 - (ind_var.quo(total_sum)))
62
62
  assert_in_delta(expected, @as, 1e-10)
63
63
  end
64
64
  end
65
65
  context Statsample::Reliability::ItemCharacteristicCurve do
66
66
  setup do
67
- @samples=100
68
- @points=rand(10)+3
69
- @max_point=(@points-1)*3
70
- @x1=@samples.times.map{rand(@points)}.to_scale
71
- @x2=@samples.times.map{rand(@points)}.to_scale
72
- @x3=@samples.times.map{rand(@points)}.to_scale
73
- @ds={'a'=>@x1,'b'=>@x2,'c'=>@x3}.to_dataset
74
- @icc=Statsample::Reliability::ItemCharacteristicCurve.new(@ds)
75
- end
76
- should "have a correct automatic vector_total" do
67
+ @samples = 100
68
+ @points = rand(10) + 3
69
+ @max_point = (@points - 1) * 3
70
+ @x1 = @samples.times.map { rand(@points) }.to_scale
71
+ @x2 = @samples.times.map { rand(@points) }.to_scale
72
+ @x3 = @samples.times.map { rand(@points) }.to_scale
73
+ @ds = { 'a' => @x1, 'b' => @x2, 'c' => @x3 }.to_dataset
74
+ @icc = Statsample::Reliability::ItemCharacteristicCurve.new(@ds)
75
+ end
76
+ should 'have a correct automatic vector_total' do
77
77
  assert_equal(@ds.vector_sum, @icc.vector_total)
78
78
  end
79
- should "have a correct different vector_total" do
80
- x2=@samples.times.map{rand(10)}.to_scale
81
- @icc=Statsample::Reliability::ItemCharacteristicCurve.new(@ds,x2)
79
+ should 'have a correct different vector_total' do
80
+ x2 = @samples.times.map { rand(10) }.to_scale
81
+ @icc = Statsample::Reliability::ItemCharacteristicCurve.new(@ds, x2)
82
82
  assert_equal(x2, @icc.vector_total)
83
83
  assert_raises(ArgumentError) do
84
- inc=(@samples+10).times.map{rand(10)}.to_scale
85
- @icc=Statsample::Reliability::ItemCharacteristicCurve.new(@ds,inc)
84
+ inc = (@samples + 10).times.map { rand(10) }.to_scale
85
+ @icc = Statsample::Reliability::ItemCharacteristicCurve.new(@ds, inc)
86
86
  end
87
87
  end
88
- should "have 0% for 0 points on maximum value values" do
89
- max=@icc.curve_field('a',0)[@max_point.to_f]
90
- max||=0
88
+ should 'have 0% for 0 points on maximum value values' do
89
+ max = @icc.curve_field('a', 0)[@max_point.to_f]
90
+ max ||= 0
91
91
  assert_in_delta(0, max)
92
92
  end
93
- should "have 0 for max value on minimum value" do
94
- max=@icc.curve_field('a',@max_point)[0.0]
95
- max||=0
93
+ should 'have 0 for max value on minimum value' do
94
+ max = @icc.curve_field('a', @max_point)[0.0]
95
+ max ||= 0
96
96
  assert_in_delta(0, max)
97
97
  end
98
- should "have correct values of % for any value" do
99
- sum=@icc.vector_total
100
- total={}
101
- total_g=sum.frequencies
102
- index=rand(@points)
103
- @x1.each_with_index do |v,i|
104
- total[sum[i]]||=0
105
- total[sum[i]]+=1 if v==index
98
+ should 'have correct values of % for any value' do
99
+ sum = @icc.vector_total
100
+ total = {}
101
+ total_g = sum.frequencies
102
+ index = rand(@points)
103
+ @x1.each_with_index do |v, i|
104
+ total[sum[i]] ||= 0
105
+ total[sum[i]] += 1 if v == index
106
106
  end
107
- expected=total.each {|k,v|
108
- total[k]=v.quo(total_g[k])
107
+ expected = total.each {|k, v|
108
+ total[k] = v.quo(total_g[k])
109
109
  }
110
- assert_equal(expected, @icc.curve_field('a',index))
111
-
110
+ assert_equal(expected, @icc.curve_field('a', index))
112
111
  end
113
-
114
112
  end
115
-
113
+
116
114
  context Statsample::Reliability::MultiScaleAnalysis do
117
-
118
115
  setup do
119
- size=100
120
- @scales=3
121
- @items_per_scale=10
122
- h={}
116
+ size = 100
117
+ @scales = 3
118
+ @items_per_scale = 10
119
+ h = {}
123
120
  @scales.times {|s|
124
121
  @items_per_scale.times {|i|
125
- h["#{s}_#{i}"] = (size.times.map {(s*2)+rand}).to_scale
122
+ h["#{s}_#{i}"] = (size.times.map { (s * 2) + rand }).to_scale
126
123
  }
127
124
  }
128
- @ds=h.to_dataset
129
- @msa=Statsample::Reliability::MultiScaleAnalysis.new(:name=>'Multiple Analysis') do |m|
130
- m.scale "complete", @ds
125
+ @ds = h.to_dataset
126
+ @msa = Statsample::Reliability::MultiScaleAnalysis.new(name: 'Multiple Analysis') do |m|
127
+ m.scale 'complete', @ds
131
128
  @scales.times {|s|
132
- m.scale "scale_#{s}", @ds.clone(@items_per_scale.times.map {|i| "#{s}_#{i}"}), {:name=>"Scale #{s}"}
129
+ m.scale "scale_#{s}", @ds.clone(@items_per_scale.times.map { |i| "#{s}_#{i}" }), name: "Scale #{s}"
133
130
  }
134
131
  end
135
132
  end
136
- should "Retrieve correct ScaleAnalysis for whole scale" do
137
- sa=Statsample::Reliability::ScaleAnalysis.new(@ds, :name=>"Scale complete")
138
- assert_equal(sa.variances_mean, @msa.scale("complete").variances_mean)
133
+ should 'Retrieve correct ScaleAnalysis for whole scale' do
134
+ sa = Statsample::Reliability::ScaleAnalysis.new(@ds, name: 'Scale complete')
135
+ assert_equal(sa.variances_mean, @msa.scale('complete').variances_mean)
139
136
  end
140
- should "Retrieve correct ScaleAnalysis for each scale" do
137
+ should 'Retrieve correct ScaleAnalysis for each scale' do
141
138
  @scales.times {|s|
142
- sa=Statsample::Reliability::ScaleAnalysis.new(@ds.dup(@items_per_scale.times.map {|i| "#{s}_#{i}"}), :name=>"Scale #{s}")
143
- assert_equal(sa.variances_mean,@msa.scale("scale_#{s}").variances_mean)
139
+ sa = Statsample::Reliability::ScaleAnalysis.new(@ds.dup(@items_per_scale.times.map { |i| "#{s}_#{i}" }), name: "Scale #{s}")
140
+ assert_equal(sa.variances_mean, @msa.scale("scale_#{s}").variances_mean)
144
141
  }
145
142
  end
146
- should "retrieve correct correlation matrix for each scale" do
147
- vectors={'complete' => @ds.vector_sum}
143
+ should 'retrieve correct correlation matrix for each scale' do
144
+ vectors = { 'complete' => @ds.vector_sum }
148
145
  @scales.times {|s|
149
- vectors["scale_#{s}"]=@ds.dup(@items_per_scale.times.map {|i| "#{s}_#{i}"}).vector_sum
146
+ vectors["scale_#{s}"] = @ds.dup(@items_per_scale.times.map { |i| "#{s}_#{i}" }).vector_sum
150
147
  }
151
- ds2=vectors.to_dataset
148
+ ds2 = vectors.to_dataset
152
149
  assert_equal(Statsample::Bivariate.correlation_matrix(ds2), @msa.correlation_matrix)
153
150
  end
154
- should "delete scale using delete_scale" do
155
- @msa.delete_scale("complete")
156
- assert_equal(@msa.scales.keys.sort, @scales.times.map {|s| "scale_#{s}"})
151
+ should 'delete scale using delete_scale' do
152
+ @msa.delete_scale('complete')
153
+ assert_equal(@msa.scales.keys.sort, @scales.times.map { |s| "scale_#{s}" })
157
154
  end
158
- should "retrieve pca for scales" do
159
- @msa.delete_scale("complete")
160
- vectors=Hash.new
155
+ should 'retrieve pca for scales' do
156
+ @msa.delete_scale('complete')
157
+ vectors = {}
161
158
  @scales.times {|s|
162
- vectors["scale_#{s}"]=@ds.dup(@items_per_scale.times.map {|i| "#{s}_#{i}"}).vector_sum
159
+ vectors["scale_#{s}"] = @ds.dup(@items_per_scale.times.map { |i| "#{s}_#{i}" }).vector_sum
163
160
  }
164
- ds2=vectors.to_dataset
165
- cor_matrix=Statsample::Bivariate.correlation_matrix(ds2)
166
- m=3
167
- pca=Statsample::Factor::PCA.new(cor_matrix, :m=>m)
168
- assert_equal(pca.component_matrix, @msa.pca(:m=>m).component_matrix)
169
- end
170
- should "retrieve acceptable summary" do
171
- @msa.delete_scale("scale_0")
172
- @msa.delete_scale("scale_1")
173
- @msa.delete_scale("scale_2")
174
-
175
-
176
- #@msa.summary_correlation_matrix=true
177
- #@msa.summary_pca=true
178
-
179
-
180
- assert(@msa.summary.size>0)
161
+ ds2 = vectors.to_dataset
162
+ cor_matrix = Statsample::Bivariate.correlation_matrix(ds2)
163
+ m = 3
164
+ pca = Statsample::Factor::PCA.new(cor_matrix, m: m)
165
+ assert_equal(pca.component_matrix, @msa.pca(m: m).component_matrix)
166
+ end
167
+ should 'retrieve acceptable summary' do
168
+ @msa.delete_scale('scale_0')
169
+ @msa.delete_scale('scale_1')
170
+ @msa.delete_scale('scale_2')
171
+
172
+ # @msa.summary_correlation_matrix=true
173
+ # @msa.summary_pca=true
174
+
175
+ assert(@msa.summary.size > 0)
181
176
  end
182
177
  end
183
178
  context Statsample::Reliability::ScaleAnalysis do
184
- setup do
185
- @x1=[1,1,1,1,2,2,2,2,3,3,3,30].to_scale
186
- @x2=[1,1,1,2,2,3,3,3,3,4,4,50].to_scale
187
- @x3=[2,2,1,1,1,2,2,2,3,4,5,40].to_scale
188
- @x4=[1,2,3,4,4,4,4,3,4,4,5,30].to_scale
189
- @ds={'x1'=>@x1,'x2'=>@x2,'x3'=>@x3,'x4'=>@x4}.to_dataset
190
- @ia=Statsample::Reliability::ScaleAnalysis.new(@ds)
191
- @cov_matrix=@ia.cov_m
192
- end
193
- should "return correct values for item analysis" do
194
- assert_in_delta(0.980,@ia.alpha,0.001)
195
- assert_in_delta(0.999,@ia.alpha_standarized,0.001)
196
- var_mean=4.times.map{|m| @cov_matrix[m,m]}.to_scale.mean
179
+ setup do
180
+ @x1 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 30].to_scale
181
+ @x2 = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 50].to_scale
182
+ @x3 = [2, 2, 1, 1, 1, 2, 2, 2, 3, 4, 5, 40].to_scale
183
+ @x4 = [1, 2, 3, 4, 4, 4, 4, 3, 4, 4, 5, 30].to_scale
184
+ @ds = { 'x1' => @x1, 'x2' => @x2, 'x3' => @x3, 'x4' => @x4 }.to_dataset
185
+ @ia = Statsample::Reliability::ScaleAnalysis.new(@ds)
186
+ @cov_matrix = @ia.cov_m
187
+ end
188
+ should 'return correct values for item analysis' do
189
+ assert_in_delta(0.980, @ia.alpha, 0.001)
190
+ assert_in_delta(0.999, @ia.alpha_standarized, 0.001)
191
+ var_mean = 4.times.map { |m| @cov_matrix[m, m] }.to_scale.mean
197
192
  assert_in_delta(var_mean, @ia.variances_mean)
198
193
  assert_equal(@x1.mean, @ia.item_statistics['x1'][:mean])
199
194
  assert_equal(@x4.mean, @ia.item_statistics['x4'][:mean])
200
- assert_in_delta(@x1.sds, @ia.item_statistics['x1'][:sds],1e-14)
201
- assert_in_delta(@x4.sds, @ia.item_statistics['x4'][:sds],1e-14)
202
- ds2=@ds.clone
195
+ assert_in_delta(@x1.sds, @ia.item_statistics['x1'][:sds], 1e-14)
196
+ assert_in_delta(@x4.sds, @ia.item_statistics['x4'][:sds], 1e-14)
197
+ ds2 = @ds.clone
203
198
  ds2.delete_vector('x1')
204
- vector_sum=ds2.vector_sum
199
+ vector_sum = ds2.vector_sum
205
200
  assert_equal(vector_sum.mean, @ia.stats_if_deleted['x1'][:mean])
206
201
  assert_equal(vector_sum.sds, @ia.stats_if_deleted['x1'][:sds])
207
- assert_in_delta(vector_sum.variance, @ia.stats_if_deleted['x1'][:variance_sample],1e-10)
202
+ assert_in_delta(vector_sum.variance, @ia.stats_if_deleted['x1'][:variance_sample], 1e-10)
208
203
 
209
204
  assert_equal(Statsample::Reliability.cronbach_alpha(ds2), @ia.stats_if_deleted['x1'][:alpha])
210
-
211
- covariances=[]
205
+
206
+ covariances = []
212
207
  4.times.each {|i|
213
208
  4.times.each {|j|
214
- if i!=j
215
- covariances.push(@cov_matrix[i,j])
209
+ if i != j
210
+ covariances.push(@cov_matrix[i, j])
216
211
  end
217
212
  }
218
213
  }
219
214
  assert_in_delta(covariances.to_scale.mean, @ia.covariances_mean)
220
- assert_in_delta(0.999,@ia.item_total_correlation()['x1'],0.001)
221
- assert_in_delta(1050.455,@ia.stats_if_deleted()['x1'][:variance_sample],0.001)
215
+ assert_in_delta(0.999, @ia.item_total_correlation['x1'], 0.001)
216
+ assert_in_delta(1050.455, @ia.stats_if_deleted['x1'][:variance_sample], 0.001)
222
217
  end
223
- should "return a summary" do
224
- assert(@ia.summary.size>0)
218
+ should 'return a summary' do
219
+ assert(@ia.summary.size > 0)
225
220
  end
226
-
227
221
  end
228
222
  end
229
223
  end