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.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +23 -0
- data/CONTRIBUTING.md +17 -0
- data/Gemfile +2 -0
- data/History.txt +457 -0
- data/LICENSE.txt +12 -0
- data/README.md +175 -0
- data/Rakefile +44 -0
- data/benchmarks/correlation_matrix_15_variables.rb +32 -0
- data/benchmarks/correlation_matrix_5_variables.rb +33 -0
- data/benchmarks/correlation_matrix_methods/correlation_matrix.ds +0 -0
- data/benchmarks/correlation_matrix_methods/correlation_matrix.html +93 -0
- data/benchmarks/correlation_matrix_methods/correlation_matrix.rb +71 -0
- data/benchmarks/correlation_matrix_methods/correlation_matrix.xls +0 -0
- data/benchmarks/correlation_matrix_methods/correlation_matrix_gsl_ruby.ods +0 -0
- data/benchmarks/correlation_matrix_methods/correlation_matrix_with_graphics.ods +0 -0
- data/benchmarks/correlation_matrix_methods/results.ds +0 -0
- data/benchmarks/factor_map.rb +37 -0
- data/benchmarks/helpers_benchmark.rb +5 -0
- data/data/locale/es/LC_MESSAGES/statsample.mo +0 -0
- data/doc_latex/manual/equations.tex +78 -0
- data/examples/boxplot.rb +28 -0
- data/examples/chisquare_test.rb +23 -0
- data/examples/correlation_matrix.rb +32 -0
- data/examples/dataset.rb +30 -0
- data/examples/dominance_analysis.rb +33 -0
- data/examples/dominance_analysis_bootstrap.rb +32 -0
- data/examples/histogram.rb +26 -0
- data/examples/icc.rb +24 -0
- data/examples/levene.rb +29 -0
- data/examples/multiple_regression.rb +20 -0
- data/examples/multivariate_correlation.rb +33 -0
- data/examples/parallel_analysis.rb +40 -0
- data/examples/polychoric.rb +40 -0
- data/examples/principal_axis.rb +26 -0
- data/examples/reliability.rb +31 -0
- data/examples/scatterplot.rb +25 -0
- data/examples/t_test.rb +27 -0
- data/examples/tetrachoric.rb +17 -0
- data/examples/u_test.rb +24 -0
- data/examples/vector.rb +20 -0
- data/examples/velicer_map_test.rb +46 -0
- data/grab_references.rb +29 -0
- data/lib/spss.rb +134 -0
- data/lib/statsample-ekatena/analysis.rb +100 -0
- data/lib/statsample-ekatena/analysis/suite.rb +89 -0
- data/lib/statsample-ekatena/analysis/suitereportbuilder.rb +44 -0
- data/lib/statsample-ekatena/anova.rb +24 -0
- data/lib/statsample-ekatena/anova/contrast.rb +79 -0
- data/lib/statsample-ekatena/anova/oneway.rb +187 -0
- data/lib/statsample-ekatena/anova/twoway.rb +207 -0
- data/lib/statsample-ekatena/bivariate.rb +406 -0
- data/lib/statsample-ekatena/bivariate/pearson.rb +54 -0
- data/lib/statsample-ekatena/codification.rb +182 -0
- data/lib/statsample-ekatena/converter/csv.rb +28 -0
- data/lib/statsample-ekatena/converter/spss.rb +48 -0
- data/lib/statsample-ekatena/converters.rb +211 -0
- data/lib/statsample-ekatena/crosstab.rb +188 -0
- data/lib/statsample-ekatena/daru.rb +115 -0
- data/lib/statsample-ekatena/dataset.rb +10 -0
- data/lib/statsample-ekatena/dominanceanalysis.rb +425 -0
- data/lib/statsample-ekatena/dominanceanalysis/bootstrap.rb +232 -0
- data/lib/statsample-ekatena/factor.rb +104 -0
- data/lib/statsample-ekatena/factor/map.rb +124 -0
- data/lib/statsample-ekatena/factor/parallelanalysis.rb +166 -0
- data/lib/statsample-ekatena/factor/pca.rb +242 -0
- data/lib/statsample-ekatena/factor/principalaxis.rb +243 -0
- data/lib/statsample-ekatena/factor/rotation.rb +198 -0
- data/lib/statsample-ekatena/formula/fit_model.rb +46 -0
- data/lib/statsample-ekatena/formula/formula.rb +306 -0
- data/lib/statsample-ekatena/graph.rb +11 -0
- data/lib/statsample-ekatena/graph/boxplot.rb +236 -0
- data/lib/statsample-ekatena/graph/histogram.rb +198 -0
- data/lib/statsample-ekatena/graph/scatterplot.rb +213 -0
- data/lib/statsample-ekatena/histogram.rb +180 -0
- data/lib/statsample-ekatena/matrix.rb +329 -0
- data/lib/statsample-ekatena/multiset.rb +310 -0
- data/lib/statsample-ekatena/regression.rb +65 -0
- data/lib/statsample-ekatena/regression/multiple.rb +89 -0
- data/lib/statsample-ekatena/regression/multiple/alglibengine.rb +128 -0
- data/lib/statsample-ekatena/regression/multiple/baseengine.rb +251 -0
- data/lib/statsample-ekatena/regression/multiple/gslengine.rb +129 -0
- data/lib/statsample-ekatena/regression/multiple/matrixengine.rb +205 -0
- data/lib/statsample-ekatena/regression/multiple/rubyengine.rb +86 -0
- data/lib/statsample-ekatena/regression/simple.rb +121 -0
- data/lib/statsample-ekatena/reliability.rb +150 -0
- data/lib/statsample-ekatena/reliability/icc.rb +415 -0
- data/lib/statsample-ekatena/reliability/multiscaleanalysis.rb +181 -0
- data/lib/statsample-ekatena/reliability/scaleanalysis.rb +233 -0
- data/lib/statsample-ekatena/reliability/skillscaleanalysis.rb +114 -0
- data/lib/statsample-ekatena/resample.rb +15 -0
- data/lib/statsample-ekatena/shorthand.rb +125 -0
- data/lib/statsample-ekatena/srs.rb +169 -0
- data/lib/statsample-ekatena/test.rb +82 -0
- data/lib/statsample-ekatena/test/bartlettsphericity.rb +45 -0
- data/lib/statsample-ekatena/test/chisquare.rb +73 -0
- data/lib/statsample-ekatena/test/f.rb +52 -0
- data/lib/statsample-ekatena/test/kolmogorovsmirnov.rb +63 -0
- data/lib/statsample-ekatena/test/levene.rb +88 -0
- data/lib/statsample-ekatena/test/t.rb +309 -0
- data/lib/statsample-ekatena/test/umannwhitney.rb +208 -0
- data/lib/statsample-ekatena/test/wilcoxonsignedrank.rb +90 -0
- data/lib/statsample-ekatena/vector.rb +19 -0
- data/lib/statsample-ekatena/version.rb +3 -0
- data/lib/statsample.rb +282 -0
- data/po/es/statsample.mo +0 -0
- data/po/es/statsample.po +959 -0
- data/po/statsample.pot +947 -0
- data/references.txt +24 -0
- data/statsample-ekatena.gemspec +49 -0
- data/test/fixtures/bank2.dat +200 -0
- data/test/fixtures/correlation_matrix.rb +17 -0
- data/test/fixtures/df.csv +15 -0
- data/test/fixtures/hartman_23.matrix +9 -0
- data/test/fixtures/stock_data.csv +500 -0
- data/test/fixtures/tetmat_matrix.txt +5 -0
- data/test/fixtures/tetmat_test.txt +1001 -0
- data/test/helpers_tests.rb +83 -0
- data/test/test_analysis.rb +176 -0
- data/test/test_anova_contrast.rb +36 -0
- data/test/test_anovaoneway.rb +26 -0
- data/test/test_anovatwoway.rb +37 -0
- data/test/test_anovatwowaywithdataset.rb +47 -0
- data/test/test_anovawithvectors.rb +102 -0
- data/test/test_awesome_print_bug.rb +16 -0
- data/test/test_bartlettsphericity.rb +25 -0
- data/test/test_bivariate.rb +164 -0
- data/test/test_codification.rb +78 -0
- data/test/test_crosstab.rb +67 -0
- data/test/test_dominance_analysis.rb +39 -0
- data/test/test_factor.rb +228 -0
- data/test/test_factor_map.rb +38 -0
- data/test/test_factor_pa.rb +56 -0
- data/test/test_fit_model.rb +88 -0
- data/test/test_ggobi.rb +35 -0
- data/test/test_gsl.rb +15 -0
- data/test/test_histogram.rb +109 -0
- data/test/test_matrix.rb +48 -0
- data/test/test_multiset.rb +176 -0
- data/test/test_regression.rb +231 -0
- data/test/test_reliability.rb +223 -0
- data/test/test_reliability_icc.rb +198 -0
- data/test/test_reliability_skillscale.rb +57 -0
- data/test/test_resample.rb +24 -0
- data/test/test_srs.rb +9 -0
- data/test/test_statistics.rb +69 -0
- data/test/test_stest.rb +69 -0
- data/test/test_stratified.rb +17 -0
- data/test/test_test_f.rb +33 -0
- data/test/test_test_kolmogorovsmirnov.rb +34 -0
- data/test/test_test_t.rb +62 -0
- data/test/test_umannwhitney.rb +27 -0
- data/test/test_vector.rb +12 -0
- data/test/test_wilcoxonsignedrank.rb +64 -0
- metadata +570 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib/'))
|
|
2
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/'))
|
|
3
|
+
|
|
4
|
+
require 'minitest'
|
|
5
|
+
require 'minitest/unit'
|
|
6
|
+
require 'mocha/setup'
|
|
7
|
+
require 'tempfile'
|
|
8
|
+
require 'tmpdir'
|
|
9
|
+
require 'shoulda'
|
|
10
|
+
require 'shoulda-context'
|
|
11
|
+
require 'fixtures/correlation_matrix'
|
|
12
|
+
|
|
13
|
+
require 'statsample'
|
|
14
|
+
|
|
15
|
+
module Minitest
|
|
16
|
+
class Test
|
|
17
|
+
include Shoulda::Context::Assertions
|
|
18
|
+
include Shoulda::Context::InstanceMethods
|
|
19
|
+
extend Shoulda::Context::ClassMethods
|
|
20
|
+
|
|
21
|
+
def self.should_with_gsl(name, &block)
|
|
22
|
+
should(name) do
|
|
23
|
+
if Statsample.has_gsl?
|
|
24
|
+
instance_eval(&block)
|
|
25
|
+
else
|
|
26
|
+
skip('Requires GSL')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
module Assertions
|
|
33
|
+
def assert_vectors_from_formula(formula, names)
|
|
34
|
+
model = Statsample::FitModel.new formula, @df
|
|
35
|
+
|
|
36
|
+
model.df_for_regression.vectors.to_a.sort
|
|
37
|
+
.must_equal names.sort
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def assert_similar_vector(exp, obs, delta = 1e-10, msg = nil)
|
|
41
|
+
msg ||= "Different vectors #{exp} - #{obs}"
|
|
42
|
+
assert_equal(exp.size, obs.size)
|
|
43
|
+
exp.to_a.each_with_index {|v, i|
|
|
44
|
+
assert_in_delta(v, obs[i], delta)
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def assert_equal_vector(exp, obs, delta = 1e-10, msg = nil)
|
|
49
|
+
assert_equal(exp.size, obs.size, "Different size.#{msg}")
|
|
50
|
+
exp.size.times {|i|
|
|
51
|
+
assert_in_delta(exp[i], obs[i], delta, "Different element #{i}. \nExpected:\n#{exp}\nObserved:\n#{obs}.#{msg}")
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def assert_equal_matrix(exp, obs, delta = 1e-10, msg = nil)
|
|
56
|
+
assert_equal(exp.row_size, obs.row_size, "Different row size.#{msg}")
|
|
57
|
+
assert_equal(exp.column_size, obs.column_size, "Different column size.#{msg}")
|
|
58
|
+
exp.row_size.times {|i|
|
|
59
|
+
exp.column_size.times {|j|
|
|
60
|
+
assert_in_delta(exp[i, j], obs[i, j], delta, "Different element #{i},#{j}\nExpected:\n#{exp}\nObserved:\n#{obs}.#{msg}")
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
alias_method :assert_raise, :assert_raises unless method_defined? :assert_raise
|
|
65
|
+
alias_method :assert_not_equal, :refute_equal unless method_defined? :assert_not_equal
|
|
66
|
+
alias_method :assert_not_same, :refute_same unless method_defined? :assert_not_same
|
|
67
|
+
unless method_defined? :assert_nothing_raised
|
|
68
|
+
def assert_nothing_raised(msg = nil)
|
|
69
|
+
msg ||= 'Nothing should be raised, but raised %s'
|
|
70
|
+
begin
|
|
71
|
+
yield
|
|
72
|
+
not_raised = true
|
|
73
|
+
rescue Exception => e
|
|
74
|
+
not_raised = false
|
|
75
|
+
msg = sprintf(msg, e)
|
|
76
|
+
end
|
|
77
|
+
assert(not_raised, msg)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
MiniTest.autorun
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
|
|
2
|
+
|
|
3
|
+
class StatsampleAnalysisTestCase < Minitest::Test
|
|
4
|
+
context(Statsample::Analysis) do
|
|
5
|
+
setup do
|
|
6
|
+
Statsample::Analysis.clear_analysis
|
|
7
|
+
end
|
|
8
|
+
should 'store() should create and store Statsample::Analysis::Suite' do
|
|
9
|
+
Statsample::Analysis.store(:first) do
|
|
10
|
+
a = 1
|
|
11
|
+
end
|
|
12
|
+
assert(Statsample::Analysis.stored_analysis[:first])
|
|
13
|
+
assert(Statsample::Analysis.stored_analysis[:first].is_a? Statsample::Analysis::Suite)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
should 'ss_analysis should create an Statsample::Analysis' do
|
|
17
|
+
ss_analysis(:first) { a = 1 }
|
|
18
|
+
end
|
|
19
|
+
should 'store last created analysis' do
|
|
20
|
+
an = Statsample::Analysis.store(:first) do
|
|
21
|
+
a = 1
|
|
22
|
+
end
|
|
23
|
+
assert_equal(an, Statsample::Analysis.last)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
should 'add_to_reportbuilder() add sections to reportbuilder object' do
|
|
27
|
+
rb = mock
|
|
28
|
+
rb.expects(:add).with { |value| value.is_a? ReportBuilder::Section and value.name == :first }
|
|
29
|
+
rb.expects(:add).with { |value| value.is_a? ReportBuilder::Section and value.name == :second }
|
|
30
|
+
|
|
31
|
+
Statsample::Analysis.store(:first) do
|
|
32
|
+
echo 'first', 'second'
|
|
33
|
+
end
|
|
34
|
+
Statsample::Analysis.store(:second) do
|
|
35
|
+
echo 'third'
|
|
36
|
+
end
|
|
37
|
+
Statsample::Analysis.add_to_reportbuilder(rb, :first, :second)
|
|
38
|
+
end
|
|
39
|
+
should 'to_text returns the same as a normal ReportBuilder object' do
|
|
40
|
+
rb = ReportBuilder.new(name: :test)
|
|
41
|
+
section = ReportBuilder::Section.new(name: 'first')
|
|
42
|
+
a = Daru::Vector.new([1, 2, 3])
|
|
43
|
+
section.add('first')
|
|
44
|
+
section.add(a)
|
|
45
|
+
rb.add(section)
|
|
46
|
+
exp = rb.to_text
|
|
47
|
+
an = ss_analysis(:first) {
|
|
48
|
+
echo 'first'
|
|
49
|
+
summary(a)
|
|
50
|
+
}
|
|
51
|
+
obs = Statsample::Analysis.to_text(:first)
|
|
52
|
+
|
|
53
|
+
assert_equal(exp.split("\n")[1, exp.size], obs.split("\n")[1, obs.size])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
should 'run() execute all analysis by default' do
|
|
57
|
+
m1 = mock
|
|
58
|
+
m1.expects(:run).once
|
|
59
|
+
m1.expects(:hide).once
|
|
60
|
+
|
|
61
|
+
Statsample::Analysis.store(:first) do
|
|
62
|
+
m1.run
|
|
63
|
+
end
|
|
64
|
+
Statsample::Analysis.store(:second) do
|
|
65
|
+
m1.hide
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Should run all test
|
|
69
|
+
Statsample::Analysis.run
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
should 'run() execute blocks specificed on parameters' do
|
|
73
|
+
m1 = mock
|
|
74
|
+
m1.expects(:run).once
|
|
75
|
+
m1.expects(:hide).never
|
|
76
|
+
Statsample::Analysis.store(:first) do
|
|
77
|
+
m1.run
|
|
78
|
+
end
|
|
79
|
+
Statsample::Analysis.store(:second) do
|
|
80
|
+
m1.hide
|
|
81
|
+
end
|
|
82
|
+
# Should run all test
|
|
83
|
+
Statsample::Analysis.run(:first)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context(Statsample::Analysis::Suite) do
|
|
87
|
+
should 'echo() uses output#puts with same arguments' do
|
|
88
|
+
an = Statsample::Analysis::Suite.new(:output)
|
|
89
|
+
obj = mock
|
|
90
|
+
obj.expects(:puts).with(:first, :second).once
|
|
91
|
+
an.output = obj
|
|
92
|
+
an.echo(:first, :second)
|
|
93
|
+
end
|
|
94
|
+
should 'summary() should call object.summary' do
|
|
95
|
+
an = Statsample::Analysis::Suite.new(:summary)
|
|
96
|
+
obj = stub('summarizable', summary: 'summary')
|
|
97
|
+
assert_equal(obj.summary, an.summary(obj))
|
|
98
|
+
end
|
|
99
|
+
should 'attach() allows to call objects on objects which respond to fields' do
|
|
100
|
+
an = Statsample::Analysis::Suite.new(:summary)
|
|
101
|
+
ds = { :x => stub(mean: 10), :y => stub(mean: 12) }
|
|
102
|
+
ds.expects(:vectors).returns([:x, :y]).at_least_once
|
|
103
|
+
an.attach(ds)
|
|
104
|
+
assert_equal(10, an.x.mean)
|
|
105
|
+
assert_equal(12, an.y.mean)
|
|
106
|
+
assert_raise(RuntimeError) {
|
|
107
|
+
an.z
|
|
108
|
+
}
|
|
109
|
+
end
|
|
110
|
+
should 'attached objects should be called LIFO' do
|
|
111
|
+
an = Statsample::Analysis::Suite.new(:summary)
|
|
112
|
+
ds1 = { :x => stub(mean: 100), :y => stub(mean: 120), :z => stub(mean: 13) }
|
|
113
|
+
ds1.expects(:vectors).returns([:x, :y, :z]).at_least_once
|
|
114
|
+
ds2 = { :x => stub(mean: 10), :y => stub(mean: 12) }
|
|
115
|
+
ds2.expects(:vectors).returns([:x, :y]).at_least_once
|
|
116
|
+
an.attach(ds1)
|
|
117
|
+
an.attach(ds2)
|
|
118
|
+
assert_equal(10, an.x.mean)
|
|
119
|
+
assert_equal(12, an.y.mean)
|
|
120
|
+
assert_equal(13, an.z.mean)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
should 'detach() without arguments drop latest object' do
|
|
124
|
+
an = Statsample::Analysis::Suite.new(:summary)
|
|
125
|
+
ds1 = { :x => stub(mean: 100), :y => stub(mean: 120), :z => stub(mean: 13) }
|
|
126
|
+
ds1.expects(:vectors).returns([:x, :y, :z]).at_least_once
|
|
127
|
+
ds2 = { :x => stub(mean: 10), :y => stub(mean: 12) }
|
|
128
|
+
ds2.expects(:vectors).returns([:x, :y]).at_least_once
|
|
129
|
+
an.attach(ds1)
|
|
130
|
+
an.attach(ds2)
|
|
131
|
+
assert_equal(10, an.x.mean)
|
|
132
|
+
an.detach
|
|
133
|
+
assert_equal(100, an.x.mean)
|
|
134
|
+
end
|
|
135
|
+
should 'detach() with argument drop select object' do
|
|
136
|
+
an = Statsample::Analysis::Suite.new(:summary)
|
|
137
|
+
ds1 = { :x => 1 }
|
|
138
|
+
ds1.expects(:vectors).returns([:x]).at_least_once
|
|
139
|
+
ds2 = { :x => 2, :y => 3 }
|
|
140
|
+
ds2.expects(:vectors).returns([:x, :y]).at_least_once
|
|
141
|
+
ds3 = { :y => 4 }
|
|
142
|
+
ds3.expects(:vectors).returns([:y]).at_least_once
|
|
143
|
+
|
|
144
|
+
an.attach(ds3)
|
|
145
|
+
an.attach(ds2)
|
|
146
|
+
an.attach(ds1)
|
|
147
|
+
assert_equal(1, an.x)
|
|
148
|
+
assert_equal(3, an.y)
|
|
149
|
+
an.detach(ds2)
|
|
150
|
+
assert_equal(4, an.y)
|
|
151
|
+
end
|
|
152
|
+
should 'perform a simple analysis' do
|
|
153
|
+
output = mock
|
|
154
|
+
output.expects(:puts).with(5.5)
|
|
155
|
+
an = Statsample::Analysis.store(:simple, output: output) do
|
|
156
|
+
ds = data_frame(x: vector(1..10), y: vector(1..10))
|
|
157
|
+
attach(ds)
|
|
158
|
+
echo x.mean
|
|
159
|
+
end
|
|
160
|
+
an.run
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
context(Statsample::Analysis::SuiteReportBuilder) do
|
|
164
|
+
should 'echo() use add on rb object' do
|
|
165
|
+
an = Statsample::Analysis::SuiteReportBuilder.new(:puts_to_add)
|
|
166
|
+
an.rb.expects(:add).with(:first).twice
|
|
167
|
+
an.echo(:first, :first)
|
|
168
|
+
end
|
|
169
|
+
should 'summary() uses add on rb object' do
|
|
170
|
+
an = Statsample::Analysis::SuiteReportBuilder.new(:summary_to_add)
|
|
171
|
+
an.rb.expects(:add).with(:first).once
|
|
172
|
+
an.summary(:first)
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
|
|
2
|
+
class StatsampleAnovaContrastTestCase < Minitest::Test
|
|
3
|
+
context(Statsample::Anova::Contrast) do
|
|
4
|
+
setup do
|
|
5
|
+
constant = Daru::Vector.new([12, 13, 11, 12, 12])
|
|
6
|
+
frequent = Daru::Vector.new([9, 10, 9, 13, 14])
|
|
7
|
+
infrequent = Daru::Vector.new([15, 16, 17, 16, 16])
|
|
8
|
+
never = Daru::Vector.new([17, 18, 12, 18, 20])
|
|
9
|
+
@vectors = [constant, frequent, infrequent, never]
|
|
10
|
+
@c = Statsample::Anova::Contrast.new(vectors: @vectors)
|
|
11
|
+
end
|
|
12
|
+
should 'return correct value using c' do
|
|
13
|
+
@c.c([1, -1.quo(3), -1.quo(3), -1.quo(3)])
|
|
14
|
+
# @c.c([1,-0.333,-0.333,-0.333])
|
|
15
|
+
assert_in_delta(-2.6667, @c.psi, 0.0001)
|
|
16
|
+
assert_in_delta(1.0165, @c.se, 0.0001)
|
|
17
|
+
assert_in_delta(-2.623, @c.t, 0.001)
|
|
18
|
+
assert_in_delta(-4.82, @c.confidence_interval[0], 0.01)
|
|
19
|
+
assert_in_delta(-0.51, @c.confidence_interval[1], 0.01)
|
|
20
|
+
assert(@c.summary.size > 0)
|
|
21
|
+
end
|
|
22
|
+
should 'return correct values using c_by_index' do
|
|
23
|
+
@c.c_by_index([0], [1, 2, 3])
|
|
24
|
+
assert_in_delta(-2.6667, @c.psi, 0.0001)
|
|
25
|
+
assert_in_delta(1.0165, @c.se, 0.0001)
|
|
26
|
+
assert_in_delta(-2.623, @c.t, 0.001)
|
|
27
|
+
end
|
|
28
|
+
should 'return correct values using incomplete c_by_index' do
|
|
29
|
+
c1 = Statsample::Anova::Contrast.new(vectors: @vectors, c: [0.5, 0.5, -1, 0])
|
|
30
|
+
c2 = Statsample::Anova::Contrast.new(vectors: @vectors, c1: [0, 1], c2: [2])
|
|
31
|
+
assert_equal(c1.psi, c2.psi)
|
|
32
|
+
assert_equal(c1.se, c2.se)
|
|
33
|
+
assert_equal(c1.t, c2.t)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
|
|
2
|
+
class StatsampleAnovaOneWayTestCase < Minitest::Test
|
|
3
|
+
context(Statsample::Anova::OneWay) do
|
|
4
|
+
setup do
|
|
5
|
+
@ss_num = 30.08
|
|
6
|
+
@ss_den = 87.88
|
|
7
|
+
@df_num = 2
|
|
8
|
+
@df_den = 21
|
|
9
|
+
@anova = Statsample::Anova::OneWay.new(ss_num: @ss_num, ss_den: @ss_den, df_num: @df_num, df_den: @df_den)
|
|
10
|
+
end
|
|
11
|
+
should 'Statsample::Anova.oneway respond to #oneway' do
|
|
12
|
+
assert(Statsample::Anova.respond_to? :oneway)
|
|
13
|
+
end
|
|
14
|
+
should 'return correct value for ms_num and ms_den' do
|
|
15
|
+
assert_in_delta(15.04, @anova.ms_num, 0.01)
|
|
16
|
+
assert_in_delta(4.18, @anova.ms_den, 0.01)
|
|
17
|
+
end
|
|
18
|
+
should 'return correct value for f' do
|
|
19
|
+
assert_in_delta(3.59, @anova.f, 0.01)
|
|
20
|
+
end
|
|
21
|
+
should 'respond to summary' do
|
|
22
|
+
assert(@anova.respond_to? :summary)
|
|
23
|
+
assert(@anova.summary.size > 0)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
|
|
2
|
+
class StatsampleAnovaTwoWayTestCase < Minitest::Test
|
|
3
|
+
context(Statsample::Anova::TwoWay) do
|
|
4
|
+
setup do
|
|
5
|
+
@ss_a = 192.2
|
|
6
|
+
@ss_b = 57.8
|
|
7
|
+
@ss_axb = 168.2
|
|
8
|
+
@ss_within = 75.6
|
|
9
|
+
@df_a = @df_b = 1
|
|
10
|
+
@df_within = 16
|
|
11
|
+
@anova = Statsample::Anova::TwoWay.new(ss_a: @ss_a, ss_b: @ss_b, ss_axb: @ss_axb, ss_within: @ss_within, df_a: @df_a, df_b: @df_b, df_within: @df_within)
|
|
12
|
+
end
|
|
13
|
+
should 'Statsample::Anova.twoway respond to #twoway' do
|
|
14
|
+
assert(Statsample::Anova.respond_to? :twoway)
|
|
15
|
+
end
|
|
16
|
+
should 'return correct value for ms_a, ms_b and ms_axb' do
|
|
17
|
+
assert_in_delta(192.2, @anova.ms_a, 0.01)
|
|
18
|
+
assert_in_delta(57.8, @anova.ms_b, 0.01)
|
|
19
|
+
assert_in_delta(168.2, @anova.ms_axb, 0.01)
|
|
20
|
+
end
|
|
21
|
+
should 'return correct value for f ' do
|
|
22
|
+
assert_in_delta(40.68, @anova.f_a, 0.01)
|
|
23
|
+
assert_in_delta(12.23, @anova.f_b, 0.01)
|
|
24
|
+
assert_in_delta(35.60, @anova.f_axb, 0.01)
|
|
25
|
+
end
|
|
26
|
+
should 'return correct value for probability for f ' do
|
|
27
|
+
assert(@anova.f_a_probability < 0.05)
|
|
28
|
+
assert(@anova.f_b_probability < 0.05)
|
|
29
|
+
assert(@anova.f_axb_probability < 0.05)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
should 'respond to summary' do
|
|
33
|
+
assert(@anova.respond_to? :summary)
|
|
34
|
+
assert(@anova.summary.size > 0)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
|
|
2
|
+
# Reference:
|
|
3
|
+
# * http://www.uwsp.edu/psych/Stat/13/anova-2w.htm#III
|
|
4
|
+
class StatsampleAnovaTwoWayWithVectorsTestCase < Minitest::Test
|
|
5
|
+
context(Statsample::Anova::TwoWayWithVectors) do
|
|
6
|
+
setup do
|
|
7
|
+
@pa = Daru::Vector.new [5, 4, 3, 4, 2, 18, 19, 14, 12, 15, 6, 7, 5, 8, 4, 6, 9, 5, 9, 3]
|
|
8
|
+
@pa.rename 'Passive Avoidance'
|
|
9
|
+
@a = Daru::Vector.new [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]
|
|
10
|
+
# @a.labels = { 0 => '0%', 1 => '35%' }
|
|
11
|
+
@a.rename 'Diet'
|
|
12
|
+
@b = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
|
|
13
|
+
# @b.labels = { 0 => 'Young', 1 => 'Older' }
|
|
14
|
+
@b.rename 'Age'
|
|
15
|
+
@anova = Statsample::Anova::TwoWayWithVectors.new(a: @a, b: @b, dependent: @pa)
|
|
16
|
+
end
|
|
17
|
+
should 'Statsample::Anova respond to #twoway_with_vectors' do
|
|
18
|
+
assert(Statsample::Anova.respond_to? :twoway_with_vectors)
|
|
19
|
+
end
|
|
20
|
+
should '#new returns the same as Statsample::Anova.twoway_with_vectors' do
|
|
21
|
+
@anova2 = Statsample::Anova.twoway_with_vectors(a: @a, b: @b, dependent: @pa)
|
|
22
|
+
assert_equal(@anova.summary, @anova2.summary)
|
|
23
|
+
end
|
|
24
|
+
should 'return correct value for ms_a, ms_b and ms_axb' do
|
|
25
|
+
assert_in_delta(192.2, @anova.ms_a, 0.01)
|
|
26
|
+
assert_in_delta(57.8, @anova.ms_b, 0.01)
|
|
27
|
+
assert_in_delta(168.2, @anova.ms_axb, 0.01)
|
|
28
|
+
end
|
|
29
|
+
should 'return correct value for f ' do
|
|
30
|
+
assert_in_delta(40.68, @anova.f_a, 0.01)
|
|
31
|
+
assert_in_delta(12.23, @anova.f_b, 0.01)
|
|
32
|
+
assert_in_delta(35.60, @anova.f_axb, 0.01)
|
|
33
|
+
end
|
|
34
|
+
should 'return correct value for probability for f ' do
|
|
35
|
+
assert(@anova.f_a_probability < 0.05)
|
|
36
|
+
assert(@anova.f_b_probability < 0.05)
|
|
37
|
+
assert(@anova.f_axb_probability < 0.05)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
should 'respond to summary' do
|
|
41
|
+
@anova.summary_descriptives = true
|
|
42
|
+
@anova.summary_levene = true
|
|
43
|
+
assert(@anova.respond_to? :summary)
|
|
44
|
+
assert(@anova.summary.size > 0)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
|
|
2
|
+
class StatsampleAnovaOneWayWithVectorsTestCase < Minitest::Test
|
|
3
|
+
context(Statsample::Anova::OneWayWithVectors) do
|
|
4
|
+
context('when initializing') do
|
|
5
|
+
setup do
|
|
6
|
+
@v1 = Daru::Vector.new(10.times.map { rand(100) })
|
|
7
|
+
@v2 = Daru::Vector.new(10.times.map { rand(100) })
|
|
8
|
+
@v3 = Daru::Vector.new(10.times.map { rand(100) })
|
|
9
|
+
end
|
|
10
|
+
should 'be the same using [] or args*' do
|
|
11
|
+
a1 = Statsample::Anova::OneWayWithVectors.new(@v1, @v2, @v3)
|
|
12
|
+
a2 = Statsample::Anova::OneWayWithVectors.new([@v1, @v2, @v3])
|
|
13
|
+
assert_equal(a1.f, a2.f)
|
|
14
|
+
end
|
|
15
|
+
should 'be the same using module method or object instantiation' do
|
|
16
|
+
a1 = Statsample::Anova::OneWayWithVectors.new(@v1, @v2, @v3)
|
|
17
|
+
a2 = Statsample::Anova.oneway_with_vectors(@v1, @v2, @v3)
|
|
18
|
+
assert_equal(a1.f, a2.f)
|
|
19
|
+
end
|
|
20
|
+
should 'detect optional hash' do
|
|
21
|
+
a1 = Statsample::Anova::OneWayWithVectors.new(@v1, @v2, @v3, name: 'aaa')
|
|
22
|
+
assert_equal('aaa', a1.name)
|
|
23
|
+
end
|
|
24
|
+
should 'omit incorrect arguments' do
|
|
25
|
+
a1 = Statsample::Anova::OneWayWithVectors.new(@v1, @v2, @v3, name: 'aaa')
|
|
26
|
+
a2 = Statsample::Anova::OneWayWithVectors.new(@v1, nil, nil, @v2, @v3, name: 'aaa')
|
|
27
|
+
assert_equal(a1.f, a2.f)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
setup do
|
|
31
|
+
@v1 = Daru::Vector.new([3, 3, 2, 3, 6])
|
|
32
|
+
@v2 = Daru::Vector.new([7, 6, 5, 6, 7])
|
|
33
|
+
@v3 = Daru::Vector.new([9, 8, 9, 7, 8])
|
|
34
|
+
@name = 'Anova testing'
|
|
35
|
+
@anova = Statsample::Anova::OneWayWithVectors.new(@v1, @v2, @v3, name: @name)
|
|
36
|
+
end
|
|
37
|
+
should 'store correctly contrasts' do
|
|
38
|
+
c1 = Statsample::Anova::Contrast.new(vectors: [@v1, @v2, @v3], c: [1, -0.5, -0.5])
|
|
39
|
+
|
|
40
|
+
c2 = @anova.contrast(c: [1, -0.5, -0.5])
|
|
41
|
+
assert_equal(c1.t, c2.t)
|
|
42
|
+
end
|
|
43
|
+
should 'respond to #summary' do
|
|
44
|
+
assert(@anova.respond_to? :summary)
|
|
45
|
+
end
|
|
46
|
+
should 'have correct name of analysis on #summary' do
|
|
47
|
+
assert_match(/#{@name}/, @anova.summary)
|
|
48
|
+
end
|
|
49
|
+
should 'returns same levene values as direct Levene creation' do
|
|
50
|
+
assert_equal(@anova.levene.f, Statsample::Test.levene([@v1, @v2, @v3]).f)
|
|
51
|
+
end
|
|
52
|
+
should 'have correct value for levene' do
|
|
53
|
+
assert_in_delta(0.604, @anova.levene.f, 0.001)
|
|
54
|
+
assert_in_delta(0.562, @anova.levene.probability, 0.001)
|
|
55
|
+
end
|
|
56
|
+
should 'have correct value for sst' do
|
|
57
|
+
assert_in_delta(72.933, @anova.sst, 0.001)
|
|
58
|
+
end
|
|
59
|
+
should 'have correct value for sswg' do
|
|
60
|
+
assert_in_delta(14.8, @anova.sswg, 0.001)
|
|
61
|
+
end
|
|
62
|
+
should 'have correct value for ssb' do
|
|
63
|
+
assert_in_delta(58.133, @anova.ssbg, 0.001)
|
|
64
|
+
end
|
|
65
|
+
should 'sst=sswg+ssbg' do
|
|
66
|
+
assert_in_delta(@anova.sst, @anova.sswg + @anova.ssbg, 0.00001)
|
|
67
|
+
end
|
|
68
|
+
should 'df total equal to number of n-1' do
|
|
69
|
+
assert_equal(@v1.size + @v2.size + @v3.size - 1, @anova.df_total)
|
|
70
|
+
end
|
|
71
|
+
should 'df wg equal to number of n-k' do
|
|
72
|
+
assert_equal(@v1.size + @v2.size + @v3.size - 3, @anova.df_wg)
|
|
73
|
+
end
|
|
74
|
+
should 'df bg equal to number of k-1' do
|
|
75
|
+
assert_equal(2, @anova.df_bg)
|
|
76
|
+
end
|
|
77
|
+
should 'f=(ssbg/df_bg)/(sswt/df_wt)' do
|
|
78
|
+
assert_in_delta((@anova.ssbg.quo(@anova.df_bg)).quo(@anova.sswg.quo(@anova.df_wg)), @anova.f, 0.001)
|
|
79
|
+
end
|
|
80
|
+
should 'p be correct' do
|
|
81
|
+
assert(@anova.probability < 0.01)
|
|
82
|
+
end
|
|
83
|
+
should 'be correct using different test values' do
|
|
84
|
+
anova2 = Statsample::Anova::OneWayWithVectors.new([@v1, @v1, @v1, @v1, @v2])
|
|
85
|
+
assert_in_delta(3.960, anova2.f, 0.001)
|
|
86
|
+
assert_in_delta(0.016, anova2.probability, 0.001)
|
|
87
|
+
end
|
|
88
|
+
context 'with extra information on summary' do
|
|
89
|
+
setup do
|
|
90
|
+
@anova.summary_descriptives = true
|
|
91
|
+
@anova.summary_levene = true
|
|
92
|
+
@summary = @anova.summary
|
|
93
|
+
end
|
|
94
|
+
should 'have section with levene statistics' do
|
|
95
|
+
assert_match(/Levene/, @summary)
|
|
96
|
+
end
|
|
97
|
+
should 'have section with descriptives' do
|
|
98
|
+
assert_match(/Min/, @summary)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|