statsample-ekatena 2.0.2

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 (156) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.travis.yml +23 -0
  4. data/CONTRIBUTING.md +17 -0
  5. data/Gemfile +2 -0
  6. data/History.txt +457 -0
  7. data/LICENSE.txt +12 -0
  8. data/README.md +175 -0
  9. data/Rakefile +44 -0
  10. data/benchmarks/correlation_matrix_15_variables.rb +32 -0
  11. data/benchmarks/correlation_matrix_5_variables.rb +33 -0
  12. data/benchmarks/correlation_matrix_methods/correlation_matrix.ds +0 -0
  13. data/benchmarks/correlation_matrix_methods/correlation_matrix.html +93 -0
  14. data/benchmarks/correlation_matrix_methods/correlation_matrix.rb +71 -0
  15. data/benchmarks/correlation_matrix_methods/correlation_matrix.xls +0 -0
  16. data/benchmarks/correlation_matrix_methods/correlation_matrix_gsl_ruby.ods +0 -0
  17. data/benchmarks/correlation_matrix_methods/correlation_matrix_with_graphics.ods +0 -0
  18. data/benchmarks/correlation_matrix_methods/results.ds +0 -0
  19. data/benchmarks/factor_map.rb +37 -0
  20. data/benchmarks/helpers_benchmark.rb +5 -0
  21. data/data/locale/es/LC_MESSAGES/statsample.mo +0 -0
  22. data/doc_latex/manual/equations.tex +78 -0
  23. data/examples/boxplot.rb +28 -0
  24. data/examples/chisquare_test.rb +23 -0
  25. data/examples/correlation_matrix.rb +32 -0
  26. data/examples/dataset.rb +30 -0
  27. data/examples/dominance_analysis.rb +33 -0
  28. data/examples/dominance_analysis_bootstrap.rb +32 -0
  29. data/examples/histogram.rb +26 -0
  30. data/examples/icc.rb +24 -0
  31. data/examples/levene.rb +29 -0
  32. data/examples/multiple_regression.rb +20 -0
  33. data/examples/multivariate_correlation.rb +33 -0
  34. data/examples/parallel_analysis.rb +40 -0
  35. data/examples/polychoric.rb +40 -0
  36. data/examples/principal_axis.rb +26 -0
  37. data/examples/reliability.rb +31 -0
  38. data/examples/scatterplot.rb +25 -0
  39. data/examples/t_test.rb +27 -0
  40. data/examples/tetrachoric.rb +17 -0
  41. data/examples/u_test.rb +24 -0
  42. data/examples/vector.rb +20 -0
  43. data/examples/velicer_map_test.rb +46 -0
  44. data/grab_references.rb +29 -0
  45. data/lib/spss.rb +134 -0
  46. data/lib/statsample-ekatena/analysis.rb +100 -0
  47. data/lib/statsample-ekatena/analysis/suite.rb +89 -0
  48. data/lib/statsample-ekatena/analysis/suitereportbuilder.rb +44 -0
  49. data/lib/statsample-ekatena/anova.rb +24 -0
  50. data/lib/statsample-ekatena/anova/contrast.rb +79 -0
  51. data/lib/statsample-ekatena/anova/oneway.rb +187 -0
  52. data/lib/statsample-ekatena/anova/twoway.rb +207 -0
  53. data/lib/statsample-ekatena/bivariate.rb +406 -0
  54. data/lib/statsample-ekatena/bivariate/pearson.rb +54 -0
  55. data/lib/statsample-ekatena/codification.rb +182 -0
  56. data/lib/statsample-ekatena/converter/csv.rb +28 -0
  57. data/lib/statsample-ekatena/converter/spss.rb +48 -0
  58. data/lib/statsample-ekatena/converters.rb +211 -0
  59. data/lib/statsample-ekatena/crosstab.rb +188 -0
  60. data/lib/statsample-ekatena/daru.rb +115 -0
  61. data/lib/statsample-ekatena/dataset.rb +10 -0
  62. data/lib/statsample-ekatena/dominanceanalysis.rb +425 -0
  63. data/lib/statsample-ekatena/dominanceanalysis/bootstrap.rb +232 -0
  64. data/lib/statsample-ekatena/factor.rb +104 -0
  65. data/lib/statsample-ekatena/factor/map.rb +124 -0
  66. data/lib/statsample-ekatena/factor/parallelanalysis.rb +166 -0
  67. data/lib/statsample-ekatena/factor/pca.rb +242 -0
  68. data/lib/statsample-ekatena/factor/principalaxis.rb +243 -0
  69. data/lib/statsample-ekatena/factor/rotation.rb +198 -0
  70. data/lib/statsample-ekatena/formula/fit_model.rb +46 -0
  71. data/lib/statsample-ekatena/formula/formula.rb +306 -0
  72. data/lib/statsample-ekatena/graph.rb +11 -0
  73. data/lib/statsample-ekatena/graph/boxplot.rb +236 -0
  74. data/lib/statsample-ekatena/graph/histogram.rb +198 -0
  75. data/lib/statsample-ekatena/graph/scatterplot.rb +213 -0
  76. data/lib/statsample-ekatena/histogram.rb +180 -0
  77. data/lib/statsample-ekatena/matrix.rb +329 -0
  78. data/lib/statsample-ekatena/multiset.rb +310 -0
  79. data/lib/statsample-ekatena/regression.rb +65 -0
  80. data/lib/statsample-ekatena/regression/multiple.rb +89 -0
  81. data/lib/statsample-ekatena/regression/multiple/alglibengine.rb +128 -0
  82. data/lib/statsample-ekatena/regression/multiple/baseengine.rb +251 -0
  83. data/lib/statsample-ekatena/regression/multiple/gslengine.rb +129 -0
  84. data/lib/statsample-ekatena/regression/multiple/matrixengine.rb +205 -0
  85. data/lib/statsample-ekatena/regression/multiple/rubyengine.rb +86 -0
  86. data/lib/statsample-ekatena/regression/simple.rb +121 -0
  87. data/lib/statsample-ekatena/reliability.rb +150 -0
  88. data/lib/statsample-ekatena/reliability/icc.rb +415 -0
  89. data/lib/statsample-ekatena/reliability/multiscaleanalysis.rb +181 -0
  90. data/lib/statsample-ekatena/reliability/scaleanalysis.rb +233 -0
  91. data/lib/statsample-ekatena/reliability/skillscaleanalysis.rb +114 -0
  92. data/lib/statsample-ekatena/resample.rb +15 -0
  93. data/lib/statsample-ekatena/shorthand.rb +125 -0
  94. data/lib/statsample-ekatena/srs.rb +169 -0
  95. data/lib/statsample-ekatena/test.rb +82 -0
  96. data/lib/statsample-ekatena/test/bartlettsphericity.rb +45 -0
  97. data/lib/statsample-ekatena/test/chisquare.rb +73 -0
  98. data/lib/statsample-ekatena/test/f.rb +52 -0
  99. data/lib/statsample-ekatena/test/kolmogorovsmirnov.rb +63 -0
  100. data/lib/statsample-ekatena/test/levene.rb +88 -0
  101. data/lib/statsample-ekatena/test/t.rb +309 -0
  102. data/lib/statsample-ekatena/test/umannwhitney.rb +208 -0
  103. data/lib/statsample-ekatena/test/wilcoxonsignedrank.rb +90 -0
  104. data/lib/statsample-ekatena/vector.rb +19 -0
  105. data/lib/statsample-ekatena/version.rb +3 -0
  106. data/lib/statsample.rb +282 -0
  107. data/po/es/statsample.mo +0 -0
  108. data/po/es/statsample.po +959 -0
  109. data/po/statsample.pot +947 -0
  110. data/references.txt +24 -0
  111. data/statsample-ekatena.gemspec +49 -0
  112. data/test/fixtures/bank2.dat +200 -0
  113. data/test/fixtures/correlation_matrix.rb +17 -0
  114. data/test/fixtures/df.csv +15 -0
  115. data/test/fixtures/hartman_23.matrix +9 -0
  116. data/test/fixtures/stock_data.csv +500 -0
  117. data/test/fixtures/tetmat_matrix.txt +5 -0
  118. data/test/fixtures/tetmat_test.txt +1001 -0
  119. data/test/helpers_tests.rb +83 -0
  120. data/test/test_analysis.rb +176 -0
  121. data/test/test_anova_contrast.rb +36 -0
  122. data/test/test_anovaoneway.rb +26 -0
  123. data/test/test_anovatwoway.rb +37 -0
  124. data/test/test_anovatwowaywithdataset.rb +47 -0
  125. data/test/test_anovawithvectors.rb +102 -0
  126. data/test/test_awesome_print_bug.rb +16 -0
  127. data/test/test_bartlettsphericity.rb +25 -0
  128. data/test/test_bivariate.rb +164 -0
  129. data/test/test_codification.rb +78 -0
  130. data/test/test_crosstab.rb +67 -0
  131. data/test/test_dominance_analysis.rb +39 -0
  132. data/test/test_factor.rb +228 -0
  133. data/test/test_factor_map.rb +38 -0
  134. data/test/test_factor_pa.rb +56 -0
  135. data/test/test_fit_model.rb +88 -0
  136. data/test/test_ggobi.rb +35 -0
  137. data/test/test_gsl.rb +15 -0
  138. data/test/test_histogram.rb +109 -0
  139. data/test/test_matrix.rb +48 -0
  140. data/test/test_multiset.rb +176 -0
  141. data/test/test_regression.rb +231 -0
  142. data/test/test_reliability.rb +223 -0
  143. data/test/test_reliability_icc.rb +198 -0
  144. data/test/test_reliability_skillscale.rb +57 -0
  145. data/test/test_resample.rb +24 -0
  146. data/test/test_srs.rb +9 -0
  147. data/test/test_statistics.rb +69 -0
  148. data/test/test_stest.rb +69 -0
  149. data/test/test_stratified.rb +17 -0
  150. data/test/test_test_f.rb +33 -0
  151. data/test/test_test_kolmogorovsmirnov.rb +34 -0
  152. data/test/test_test_t.rb +62 -0
  153. data/test/test_umannwhitney.rb +27 -0
  154. data/test/test_vector.rb +12 -0
  155. data/test/test_wilcoxonsignedrank.rb +64 -0
  156. metadata +570 -0
@@ -0,0 +1,198 @@
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
+
3
+ $reliability_icc = nil
4
+
5
+ class StatsampleReliabilityIccTestCase < Minitest::Test
6
+ context Statsample::Reliability::ICC do
7
+ setup do
8
+ a = Daru::Vector.new([9, 6, 8, 7, 10, 6])
9
+ b = Daru::Vector.new([2, 1, 4, 1, 5, 2])
10
+ c = Daru::Vector.new([5, 3, 6, 2, 6, 4])
11
+ d = Daru::Vector.new([8, 2, 8, 6, 9, 7])
12
+ @ds = Daru::DataFrame.new({ :a => a, :b => b, :c => c, :d => d })
13
+ @icc = Statsample::Reliability::ICC.new(@ds)
14
+ end
15
+ should 'basic method be correct' do
16
+ assert_equal(6, @icc.n)
17
+ assert_equal(4, @icc.k)
18
+ end
19
+ should 'total mean be correct' do
20
+ assert_in_delta(5.291, @icc.total_mean, 0.001)
21
+ end
22
+ should 'df methods be correct' do
23
+ assert_equal(5, @icc.df_bt)
24
+ assert_equal(18, @icc.df_wt)
25
+ assert_equal(3, @icc.df_bj)
26
+ assert_equal(15, @icc.df_residual)
27
+ end
28
+ should 'ms between targets be correct' do
29
+ assert_in_delta(11.24, @icc.ms_bt, 0.01)
30
+ end
31
+ should 'ms within targets be correct' do
32
+ assert_in_delta(6.26, @icc.ms_wt, 0.01)
33
+ end
34
+ should 'ms between judges be correct' do
35
+ assert_in_delta(32.49, @icc.ms_bj, 0.01)
36
+ end
37
+ should 'ms residual be correct' do
38
+ assert_in_delta(1.02, @icc.ms_residual, 0.01)
39
+ end
40
+ context 'with McGraw and Wong denominations,' do
41
+ end
42
+ context 'with Shrout & Fleiss denominations, ' do
43
+ should 'icc(1,1) method be correct' do
44
+ assert_in_delta(0.17, @icc.icc_1_1, 0.01)
45
+ end
46
+ # Verified on SPSS and R
47
+ should 'icc(2,1) method be correct' do
48
+ assert_in_delta(0.29, @icc.icc_2_1, 0.01)
49
+ end
50
+ should 'icc(3,1) method be correct' do
51
+ assert_in_delta(0.71, @icc.icc_3_1, 0.01)
52
+ end
53
+ should 'icc(1,k) method be correct' do
54
+ assert_in_delta(0.44, @icc.icc_1_k, 0.01)
55
+ end
56
+ # Verified on SPSS and R
57
+ should 'icc(2,k) method be correct' do
58
+ assert_in_delta(0.62, @icc.icc_2_k, 0.01)
59
+ end
60
+ should 'icc(3,k) method be correct' do
61
+ assert_in_delta(0.91, @icc.icc_3_k, 0.01)
62
+ end
63
+
64
+ should 'icc(1,1) F be correct' do
65
+ assert_in_delta(1.795, @icc.icc_1_f.f)
66
+ end
67
+ should 'icc(1,1) confidence interval should be correct' do
68
+ assert_in_delta(-0.133, @icc.icc_1_1_ci[0], 0.001)
69
+ assert_in_delta(0.723, @icc.icc_1_1_ci[1], 0.001)
70
+ end
71
+ should 'icc(1,k) confidence interval should be correct' do
72
+ assert_in_delta(-0.884, @icc.icc_1_k_ci[0], 0.001)
73
+ assert_in_delta(0.912, @icc.icc_1_k_ci[1], 0.001)
74
+ end
75
+
76
+ should 'icc(2,1) F be correct' do
77
+ assert_in_delta(11.027, @icc.icc_2_f.f)
78
+ end
79
+ should 'icc(2,1) confidence interval should be correct' do
80
+ # skip("Not yet operational")
81
+ assert_in_delta(0.019, @icc.icc_2_1_ci[0], 0.001)
82
+ assert_in_delta(0.761, @icc.icc_2_1_ci[1], 0.001)
83
+ end
84
+
85
+ # Verified on SPSS and R
86
+ should 'icc(2,k) confidence interval should be correct' do
87
+ # skip("Not yet operational")
88
+ # p @icc.icc_2_k_ci
89
+ assert_in_delta(0.039, @icc.icc_2_k_ci[0], 0.001)
90
+ assert_in_delta(0.929, @icc.icc_2_k_ci[1], 0.001)
91
+ end
92
+ # should "Shrout icc(2,k) and McGraw icc(a,k) ci be equal" do
93
+ # assert_in_delta(@icc.icc_2_k_ci_shrout[0], @icc.icc_2_k_ci_mcgraw[0], 10e-5)
94
+ # end
95
+
96
+ should 'icc(3,1) F be correct' do
97
+ assert_in_delta(11.027, @icc.icc_3_f.f)
98
+ end
99
+
100
+ should 'icc(3,1) confidence interval should be correct' do
101
+ assert_in_delta(0.342, @icc.icc_3_1_ci[0], 0.001)
102
+ assert_in_delta(0.946, @icc.icc_3_1_ci[1], 0.001)
103
+ end
104
+ should 'icc(3,k) confidence interval should be correct' do
105
+ assert_in_delta(0.676, @icc.icc_3_k_ci[0], 0.001)
106
+ assert_in_delta(0.986, @icc.icc_3_k_ci[1], 0.001)
107
+ end
108
+ should 'incorrect type raises an error' do
109
+ assert_raise(::RuntimeError) do
110
+ @icc.type = :nonexistant_type
111
+ end
112
+ end
113
+ end
114
+
115
+ begin
116
+ require 'rserve'
117
+ require 'daru/extensions/rserve'
118
+ context 'McGraw and Wong' do
119
+ teardown do
120
+ @r = $reliability_icc[:r].close unless $reliability_icc[:r].nil?
121
+ end
122
+ setup do
123
+ if $reliability_icc.nil?
124
+ size = 100
125
+ a = Daru::Vector.new(size.times.map { rand(10) })
126
+ b = a.recode { |i| i + rand(4) - 2 }
127
+ c = a.recode { |i| i + rand(4) - 2 }
128
+ d = a.recode { |i| i + rand(4) - 2 }
129
+ @ds = Daru::DataFrame.new({ :a => a, :b => b, :c => c, :d => d })
130
+
131
+ @icc = Statsample::Reliability::ICC.new(@ds)
132
+ @r = Rserve::Connection.new
133
+
134
+ @r.assign('ds', @ds)
135
+
136
+ @r.void_eval("library(irr);
137
+ iccs=list(
138
+ icc_1=icc(ds,'o','c','s'),
139
+ icc_k=icc(ds,'o','c','a'),
140
+ icc_c_1=icc(ds,'t','c','s'),
141
+ icc_c_k=icc(ds,'t','c','a'),
142
+ icc_a_1=icc(ds,'t','a','s'),
143
+ icc_a_k=icc(ds,'t','a','a'))
144
+ ")
145
+ @iccs = @r.eval('iccs').to_ruby
146
+ $reliability_icc = { icc: @icc, iccs: @iccs, r: @r
147
+ }
148
+
149
+ end
150
+ @icc = $reliability_icc[:icc]
151
+ @iccs = $reliability_icc[:iccs]
152
+ @r = $reliability_icc[:r]
153
+ end
154
+ [:icc_1, :icc_k, :icc_c_1, :icc_c_k, :icc_a_1, :icc_a_k].each do |t|
155
+ context "ICC Type #{t} " do
156
+ should 'value be correct' do
157
+ @icc.type = t
158
+ @r_icc = @iccs[t.to_s]
159
+ assert_in_delta(@r_icc['value'], @icc.r)
160
+ end
161
+ should 'fvalue be correct' do
162
+ @icc.type = t
163
+ @r_icc = @iccs[t.to_s]
164
+ assert_in_delta(@r_icc['Fvalue'], @icc.f.f)
165
+ end
166
+ should 'num df be correct' do
167
+ @icc.type = t
168
+ @r_icc = @iccs[t.to_s]
169
+ assert_in_delta(@r_icc['df1'], @icc.f.df_num)
170
+ end
171
+ should 'den df be correct' do
172
+ @icc.type = t
173
+ @r_icc = @iccs[t.to_s]
174
+ assert_in_delta(@r_icc['df2'], @icc.f.df_den)
175
+ end
176
+
177
+ should 'f probability be correct' do
178
+ @icc.type = t
179
+ @r_icc = @iccs[t.to_s]
180
+ assert_in_delta(@r_icc['p.value'], @icc.f.probability)
181
+ end
182
+ should 'bounds be equal' do
183
+ @icc.type = t
184
+ @r_icc = @iccs[t.to_s]
185
+ assert_in_delta(@r_icc['lbound'], @icc.lbound, 0.1)
186
+ assert_in_delta(@r_icc['ubound'], @icc.ubound, 0.1)
187
+ end
188
+ should 'summary generated' do
189
+ assert(@icc.summary.size > 0)
190
+ end
191
+ end
192
+ end
193
+ end
194
+ rescue
195
+ puts 'requires rserve'
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,57 @@
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
+
3
+ class StatsampleReliabilitySkillScaleTestCase < Minitest::Test
4
+ context Statsample::Reliability::SkillScaleAnalysis do
5
+ setup do
6
+ options = %w(a b c d e)
7
+ cases = 20
8
+ @id = Daru::Vector.new(cases.times.map { |v| v })
9
+ @a = Daru::Vector.new(cases.times.map { options[rand(5)] })
10
+ @b = Daru::Vector.new(cases.times.map { options[rand(5)] })
11
+ @c = Daru::Vector.new(cases.times.map { options[rand(5)] })
12
+ @d = Daru::Vector.new(cases.times.map { options[rand(5)] })
13
+ @e = Daru::Vector.new(
14
+ cases.times.map do |i|
15
+ i == 0 ? options[rand(0)] :
16
+ rand > 0.8 ? nil : options[rand(5)]
17
+ end
18
+ )
19
+ @ds = Daru::DataFrame.new({ :id => @id, :a => @a, :b => @b, :c => @c, :d => @d, :e => @e })
20
+ @key = { :a => 'a', :b => options[rand(5)], :c => options[rand(5)], :d => options[rand(5)], :e => options[rand(5)] }
21
+ @ssa = Statsample::Reliability::SkillScaleAnalysis.new(@ds, @key)
22
+ @ac = Daru::Vector.new(@a.map { |v| v == @key[:a] ? 1 : 0 })
23
+ @bc = Daru::Vector.new(@b.map { |v| v == @key[:b] ? 1 : 0 })
24
+ @cc = Daru::Vector.new(@c.map { |v| v == @key[:c] ? 1 : 0 })
25
+ @dc = Daru::Vector.new(@d.map { |v| v == @key[:d] ? 1 : 0 })
26
+ @ec = Daru::Vector.new(@e.map { |v| v.nil? ? nil : (v == @key[:e] ? 1 : 0) })
27
+ end
28
+ should 'return proper corrected dataset' do
29
+ cds = Daru::DataFrame.new({ :id => @id, :a => @ac, :b => @bc, :c => @cc, :d => @dc, :e => @ec })
30
+ assert_equal(cds, @ssa.corrected_dataset)
31
+ end
32
+ should 'return proper corrected minimal dataset' do
33
+ cdsm = Daru::DataFrame.new({ :a => @ac, :b => @bc, :c => @cc, :d => @dc, :e => @ec })
34
+ assert_equal(cdsm, @ssa.corrected_dataset_minimal)
35
+ end
36
+ should 'return correct vector_sum and vector_sum' do
37
+ cdsm = @ssa.corrected_dataset_minimal
38
+ assert_equal(cdsm.vector_sum, @ssa.vector_sum)
39
+ assert_equal(cdsm.vector_mean, @ssa.vector_mean)
40
+ end
41
+ should 'not crash on rare case' do
42
+ a = Daru::Vector.new(['c', 'c', 'a', 'a', 'c', 'a', 'b', 'c', 'c', 'b', 'a', 'd', 'a', 'd', 'a', 'a', 'd', 'e', 'c', 'd'])
43
+ b = Daru::Vector.new(['e', 'b', 'e', 'b', 'c', 'd', 'a', 'e', 'e', 'c', 'b', 'e', 'e', 'b', 'd', 'c', 'e', 'b', 'b', 'd'])
44
+ c = Daru::Vector.new(['e', 'b', 'e', 'c', 'e', 'c', 'b', 'd', 'e', 'c', 'a', 'a', 'b', 'd', 'e', 'c', 'b', 'a', 'a', 'e'])
45
+ d = Daru::Vector.new(['a', 'b', 'd', 'd', 'e', 'b', 'e', 'b', 'd', 'c', 'e', 'a', 'c', 'd', 'c', 'c', 'e', 'd', 'd', 'b'])
46
+ e = Daru::Vector.new(['a', 'b', nil, 'd', 'c', 'c', 'd', nil, 'd', 'd', 'e', 'e', nil, nil, nil, 'd', 'c', nil, 'e', 'd'])
47
+ key = { :a => 'a', :b => 'e', :c => 'd', :d => 'c', :e => 'd' }
48
+ ds = Daru::DataFrame.new({:a => a, :b => b, :c => c, :d => d, :e => e})
49
+ ssa = Statsample::Reliability::SkillScaleAnalysis.new(ds, key)
50
+ assert(ssa.summary)
51
+ end
52
+
53
+ should 'return valid summary' do
54
+ assert(@ssa.summary.size > 0)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,24 @@
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
+
3
+ class StatsampleResampleTestCase < Minitest::Test
4
+ def initialize(*args)
5
+ super
6
+ end
7
+
8
+ def test_basic
9
+ r = Statsample::Resample.generate(20, 1, 10)
10
+ assert_equal(20, r.size)
11
+ assert(r.min >= 1)
12
+ assert(r.max <= 10)
13
+ end
14
+
15
+ def test_repeat_and_save
16
+ r = Statsample::Resample.repeat_and_save(400) {
17
+ Statsample::Resample.generate(20, 1, 10).count(1)
18
+ }
19
+ assert_equal(400, r.size)
20
+ v = Daru::Vector.new(r)
21
+ a = v.count { |x| x > 3 }
22
+ assert(a >= 30 && a <= 70)
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
+
3
+ class StatsampleSrsTestCase < Minitest::Test
4
+ def test_std_error
5
+ assert_equal(384, Statsample::SRS.estimation_n0(0.05, 0.5, 0.95).to_i)
6
+ assert_equal(108, Statsample::SRS.estimation_n(0.05, 0.5, 150, 0.95).to_i)
7
+ assert_in_delta(0.0289, Statsample::SRS.proportion_sd_kp_wor(0.5, 100, 150), 0.001)
8
+ end
9
+ end
@@ -0,0 +1,69 @@
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
+ class StatsampleStatisicsTestCase < Minitest::Test
3
+ def initialize(*args)
4
+ super
5
+ end
6
+
7
+ def test_p_using_cdf
8
+ assert_equal(0.25, Statsample::Test.p_using_cdf(0.25, tails = :left))
9
+ assert_equal(0.75, Statsample::Test.p_using_cdf(0.25, tails = :right))
10
+ assert_equal(0.50, Statsample::Test.p_using_cdf(0.25, tails = :both))
11
+ assert_equal(1, Statsample::Test.p_using_cdf(0.50, tails = :both))
12
+ assert_equal(0.05, Statsample::Test.p_using_cdf(0.025, tails = :both))
13
+ assert_in_delta(0.05, Statsample::Test.p_using_cdf(0.975, tails = :both), 0.0001)
14
+ end
15
+
16
+ def test_recode_repeated
17
+ a = %w(a b c c d d d e)
18
+ exp = %w(a b c_1 c_2 d_1 d_2 d_3 e)
19
+ assert_equal(exp, Daru::ArrayHelper.recode_repeated(a))
20
+ end
21
+
22
+ def test_is_number
23
+ assert('10'.is_number?)
24
+ assert('-10'.is_number?)
25
+ assert('0.1'.is_number?)
26
+ assert('-0.1'.is_number?)
27
+ assert('10e3'.is_number?)
28
+ assert('10e-3'.is_number?)
29
+ assert(!'1212-1212-1'.is_number?)
30
+ assert(!'a10'.is_number?)
31
+ assert(!''.is_number?)
32
+ end
33
+
34
+ def test_estimation_mean
35
+ v = Daru::Vector.new([42] * 23 + [41] * 4 + [36] * 1 + [32] * 1 + [29] * 1 + [27] * 2 + [23] * 1 + [19] * 1 + [16] * 2 + [15] * 2 + [14, 11, 10, 9, 7] + [6] * 3 + [5] * 2 + [4, 3])
36
+ assert_equal(50, v.size)
37
+ assert_equal(1471, v.sum)
38
+ # limits=Statsample::SRS.mean_confidence_interval_z(v.mean(), v.sds(), v.size,676,0.80)
39
+ end
40
+
41
+ def test_estimation_proportion
42
+ # total
43
+ pop = 3042
44
+ sam = 200
45
+ prop = 0.19
46
+ assert_in_delta(81.8, Statsample::SRS.proportion_total_sd_ep_wor(prop, sam, pop), 0.1)
47
+
48
+ # confidence limits
49
+ pop = 500
50
+ sam = 100
51
+ prop = 0.37
52
+ a = 0.95
53
+ l = Statsample::SRS.proportion_confidence_interval_z(prop, sam, pop, a)
54
+ assert_in_delta(0.28, l[0], 0.01)
55
+ assert_in_delta(0.46, l[1], 0.01)
56
+ end
57
+
58
+ def test_simple_linear_regression
59
+ a = Daru::Vector.new([1, 2, 3, 4, 5, 6])
60
+ b = Daru::Vector.new([6, 2, 4, 10, 12, 8])
61
+ reg = Statsample::Regression::Simple.new_from_vectors(a, b)
62
+ assert_in_delta((reg.ssr + reg.sse).to_f, reg.sst, 0.001)
63
+ assert_in_delta(Statsample::Bivariate.pearson(a, b), reg.r, 0.001)
64
+ assert_in_delta(2.4, reg.a, 0.01)
65
+ assert_in_delta(1.314, reg.b, 0.001)
66
+ assert_in_delta(0.657, reg.r, 0.001)
67
+ assert_in_delta(0.432, reg.r2, 0.001)
68
+ end
69
+ end
@@ -0,0 +1,69 @@
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
+
3
+ class StatsampleTestTestCase < Minitest::Test
4
+ def test_chi_square_matrix_with_expected
5
+ real = Matrix[[95, 95], [45, 155]]
6
+ expected = Matrix[[68, 122], [72, 128]]
7
+ assert_nothing_raised do
8
+ Statsample::Test.chi_square(real, expected)
9
+ end
10
+ chi = Statsample::Test.chi_square(real, expected).chi_square
11
+ assert_in_delta(32.53, chi, 0.1)
12
+ end
13
+
14
+ def test_chi_square_matrix_only_observed
15
+ observed = Matrix[[20, 30, 40], [30, 40, 50], [60, 70, 80], [10, 20, 40]]
16
+ assert_nothing_raised do
17
+ Statsample::Test.chi_square(observed)
18
+ end
19
+ chi = Statsample::Test.chi_square(observed)
20
+ assert_in_delta(9.5602, chi.chi_square, 0.0001)
21
+ assert_in_delta(0.1444, chi.probability, 0.0001)
22
+
23
+ assert_equal(6, chi.df)
24
+ end
25
+
26
+ def test_chi_square_vector
27
+ observed = Vector[20,30,15]
28
+ expected = Vector[20,20,20]
29
+ assert_nothing_raised do
30
+ Statsample::Test.chi_square(observed, expected)
31
+ end
32
+ chi = Statsample::Test.chi_square(observed, expected)
33
+
34
+ assert_in_delta(6.25, chi.chi_square, 0.0001)
35
+ assert_in_delta(0.04393, chi.probability, 0.00001)
36
+
37
+ assert_equal(2, chi.df)
38
+ end
39
+
40
+ def test_u_mannwhitney
41
+ a = Daru::Vector.new([1, 2, 3, 4, 5, 6])
42
+ b = Daru::Vector.new([0, 5, 7, 9, 10, 11])
43
+ assert_equal(7.5, Statsample::Test.u_mannwhitney(a, b).u)
44
+ assert_equal(7.5, Statsample::Test.u_mannwhitney(b, a).u)
45
+ a = Daru::Vector.new([1, 7, 8, 9, 10, 11])
46
+ b = Daru::Vector.new([2, 3, 4, 5, 6, 12])
47
+ assert_equal(11, Statsample::Test.u_mannwhitney(a, b).u)
48
+ end
49
+
50
+ def test_levene
51
+ a = Daru::Vector.new([1, 2, 3, 4, 5, 6, 7, 8, 100, 10])
52
+ b = Daru::Vector.new([30, 40, 50, 60, 70, 80, 90, 100, 110, 120])
53
+ levene = Statsample::Test::Levene.new([a, b])
54
+ assert_levene(levene)
55
+ end
56
+
57
+ def test_levene_dataset
58
+ a = Daru::Vector.new([1, 2, 3, 4, 5, 6, 7, 8, 100, 10])
59
+ b = Daru::Vector.new([30, 40, 50, 60, 70, 80, 90, 100, 110, 120])
60
+ ds = Daru::DataFrame.new({ :a => a, :b => b })
61
+ levene = Statsample::Test::Levene.new(ds)
62
+ assert_levene(levene)
63
+ end
64
+
65
+ def assert_levene(levene)
66
+ assert_in_delta(0.778, levene.f, 0.001)
67
+ assert_in_delta(0.389, levene.probability, 0.001)
68
+ end
69
+ end
@@ -0,0 +1,17 @@
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
+
3
+ class StatsampleStratifiedTestCase < Minitest::Test
4
+ def initialize(*args)
5
+ super
6
+ end
7
+
8
+ def test_mean
9
+ a = [10, 20, 30, 40, 50]
10
+ b = [110, 120, 130, 140]
11
+ pop = a + b
12
+ av = Daru::Vector.new(a)
13
+ bv = Daru::Vector.new(b)
14
+ popv = Daru::Vector.new(pop)
15
+ assert_equal(popv.mean, Statsample::StratifiedSample.mean(av, bv))
16
+ end
17
+ end