statsample 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +1 -2
- data/History.txt +9 -0
- data/Manifest.txt +6 -2
- data/README.txt +6 -3
- data/Rakefile +4 -19
- data/examples/dominance_analysis.rb +0 -1
- data/examples/parallel_analysis.rb +2 -1
- data/examples/parallel_analysis_tetrachoric.rb +1 -1
- data/examples/reliability.rb +12 -0
- data/lib/statsample.rb +1 -2
- data/lib/statsample/anova.rb +9 -151
- data/lib/statsample/anova/oneway.rb +151 -0
- data/lib/statsample/anova/twoway.rb +211 -0
- data/lib/statsample/bivariate.rb +1 -0
- data/lib/statsample/dataset.rb +15 -1
- data/lib/statsample/dominanceanalysis.rb +10 -13
- data/lib/statsample/factor/parallelanalysis.rb +4 -2
- data/lib/statsample/multiset.rb +6 -0
- data/lib/statsample/regression/multiple/baseengine.rb +1 -1
- data/lib/statsample/reliability.rb +32 -5
- data/lib/statsample/vector.rb +6 -5
- data/test/{test_helpers.rb → helpers_tests.rb} +2 -0
- data/test/test_anovaoneway.rb +1 -2
- data/test/test_anovatwoway.rb +38 -0
- data/test/test_anovatwowaywithdataset.rb +49 -0
- data/test/test_anovawithvectors.rb +1 -1
- data/test/test_bivariate.rb +1 -1
- data/test/test_bivariate_polychoric.rb +1 -1
- data/test/test_codification.rb +1 -1
- data/test/test_combination.rb +1 -1
- data/test/test_crosstab.rb +1 -1
- data/test/test_csv.rb +1 -1
- data/test/test_dataset.rb +8 -1
- data/test/test_distribution.rb +1 -1
- data/test/test_dominance_analysis.rb +2 -1
- data/test/test_factor.rb +1 -1
- data/test/test_ggobi.rb +1 -1
- data/test/test_gsl.rb +1 -1
- data/test/test_histogram.rb +1 -1
- data/test/test_logit.rb +1 -1
- data/test/test_matrix.rb +1 -1
- data/test/test_mle.rb +1 -1
- data/test/test_multiset.rb +1 -1
- data/test/test_permutation.rb +1 -1
- data/test/test_regression.rb +3 -4
- data/test/test_reliability.rb +15 -2
- data/test/test_resample.rb +1 -1
- data/test/test_srs.rb +1 -1
- data/test/test_statistics.rb +1 -1
- data/test/test_stest.rb +1 -1
- data/test/test_stratified.rb +1 -1
- data/test/test_svg_graph.rb +1 -1
- data/test/test_test_f.rb +1 -1
- data/test/test_test_t.rb +1 -1
- data/test/test_umannwhitney.rb +1 -1
- data/test/test_vector.rb +1 -1
- data/test/test_xls.rb +1 -1
- metadata +92 -40
- metadata.gz.sig +0 -0
- data/lib/statistics2.rb +0 -531
data/lib/statsample/vector.rb
CHANGED
@@ -100,7 +100,7 @@ module Statsample
|
|
100
100
|
end
|
101
101
|
# Raises an exception if type of vector is inferior to t type
|
102
102
|
def check_type(t)
|
103
|
-
|
103
|
+
raise NoMethodError if (t==:scale and @type!=:scale) or (t==:ordinal and @type==:nominal) or (t==:date)
|
104
104
|
end
|
105
105
|
private :check_type
|
106
106
|
|
@@ -153,10 +153,11 @@ module Statsample
|
|
153
153
|
end
|
154
154
|
# Returns a new vector, with data modified by block.
|
155
155
|
# Equivalent to create a Vector after #collect on data
|
156
|
-
def recode
|
157
|
-
|
158
|
-
|
159
|
-
|
156
|
+
def recode(type=nil)
|
157
|
+
type||=@type
|
158
|
+
@data.collect{|x|
|
159
|
+
yield x
|
160
|
+
}.to_vector(type)
|
160
161
|
end
|
161
162
|
# Modifies current vector, with data modified by block.
|
162
163
|
# Equivalent to #collect! on @data
|
data/test/test_anovaoneway.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require(File.dirname(__FILE__)+'/helpers_tests.rb')
|
2
|
+
class StatsampleAnovaTwoWayTestCase < MiniTest::Unit::TestCase
|
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
|
+
|
21
|
+
end
|
22
|
+
should "return correct value for f " do
|
23
|
+
assert_in_delta(40.68, @anova.f_a, 0.01)
|
24
|
+
assert_in_delta(12.23, @anova.f_b, 0.01)
|
25
|
+
assert_in_delta(35.60, @anova.f_axb, 0.01)
|
26
|
+
end
|
27
|
+
should "return correct value for probability for f " do
|
28
|
+
assert(@anova.f_a_probability < 0.05)
|
29
|
+
assert(@anova.f_b_probability < 0.05)
|
30
|
+
assert(@anova.f_axb_probability < 0.05)
|
31
|
+
end
|
32
|
+
|
33
|
+
should "respond to summary" do
|
34
|
+
assert(@anova.respond_to? :summary)
|
35
|
+
assert(@anova.summary.size>0)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require(File.dirname(__FILE__)+'/helpers_tests.rb')
|
2
|
+
# Reference:
|
3
|
+
# * http://www.uwsp.edu/psych/Stat/13/anova-2w.htm#III
|
4
|
+
class StatsampleAnovaTwoWayWithVectorsTestCase < MiniTest::Unit::TestCase
|
5
|
+
context(Statsample::Anova::TwoWayWithVectors) do
|
6
|
+
setup do
|
7
|
+
@pa=[5,4,3,4,2,18,19,14,12,15,6,7,5,8,4,6,9,5,9,3].to_scale
|
8
|
+
@pa.name="Passive Avoidance"
|
9
|
+
@a=[0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1].to_vector
|
10
|
+
@a.labels={0=>'0%',1=>'35%'}
|
11
|
+
@a.name='Diet'
|
12
|
+
@b=[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1].to_vector
|
13
|
+
@b.labels={0=>'Young',1=>'Older'}
|
14
|
+
@b.name="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
|
+
|
29
|
+
end
|
30
|
+
should "return correct value for f " do
|
31
|
+
assert_in_delta(40.68, @anova.f_a, 0.01)
|
32
|
+
assert_in_delta(12.23, @anova.f_b, 0.01)
|
33
|
+
assert_in_delta(35.60, @anova.f_axb, 0.01)
|
34
|
+
end
|
35
|
+
should "return correct value for probability for f " do
|
36
|
+
assert(@anova.f_a_probability < 0.05)
|
37
|
+
assert(@anova.f_b_probability < 0.05)
|
38
|
+
assert(@anova.f_axb_probability < 0.05)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "respond to summary" do
|
42
|
+
|
43
|
+
@anova.summary_descriptives=true
|
44
|
+
@anova.summary_levene=true
|
45
|
+
assert(@anova.respond_to? :summary)
|
46
|
+
assert(@anova.summary.size>0)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/test/test_bivariate.rb
CHANGED
data/test/test_codification.rb
CHANGED
data/test/test_combination.rb
CHANGED
data/test/test_crosstab.rb
CHANGED
data/test/test_csv.rb
CHANGED
data/test/test_dataset.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require(File.dirname(__FILE__)+'/
|
1
|
+
require(File.dirname(__FILE__)+'/helpers_tests.rb')
|
2
2
|
|
3
3
|
class StatsampleDatasetTestCase < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
@@ -260,6 +260,7 @@ class StatsampleDatasetTestCase < MiniTest::Unit::TestCase
|
|
260
260
|
assert_same(ds1['v1'], ds2['v1'])
|
261
261
|
assert_equal(ds1.fields,ds2.fields)
|
262
262
|
assert_not_same(ds1.fields,ds2.fields)
|
263
|
+
assert_equal(ds1.cases,ds2.cases)
|
263
264
|
|
264
265
|
# partial clone
|
265
266
|
ds3=ds1.clone('v1')
|
@@ -269,6 +270,8 @@ class StatsampleDatasetTestCase < MiniTest::Unit::TestCase
|
|
269
270
|
assert_equal(ds3['v1'],ds_exp['v1'])
|
270
271
|
assert_same(ds3['v1'],ds_exp['v1'])
|
271
272
|
assert_equal(ds3.fields,ds_exp.fields)
|
273
|
+
assert_equal(ds3.cases,ds_exp.cases)
|
274
|
+
|
272
275
|
assert_not_same(ds3.fields,ds_exp.fields)
|
273
276
|
|
274
277
|
end
|
@@ -281,6 +284,8 @@ class StatsampleDatasetTestCase < MiniTest::Unit::TestCase
|
|
281
284
|
assert_not_same(ds1,ds2)
|
282
285
|
assert_equal(ds1['v1'],ds2['v1'])
|
283
286
|
assert_not_same(ds1['v1'],ds2['v1'])
|
287
|
+
assert_equal(ds1.cases,ds2.cases)
|
288
|
+
|
284
289
|
assert_equal(ds1.fields,ds2.fields)
|
285
290
|
assert_not_same(ds1.fields,ds2.fields)
|
286
291
|
ds1['v1'].type=:scale
|
@@ -292,6 +297,8 @@ class StatsampleDatasetTestCase < MiniTest::Unit::TestCase
|
|
292
297
|
assert_equal(ds3['v1'],ds_exp['v1'])
|
293
298
|
assert_not_same(ds3['v1'],ds_exp['v1'])
|
294
299
|
assert_equal(ds3.fields,ds_exp.fields)
|
300
|
+
assert_equal(ds3.cases,ds_exp.cases)
|
301
|
+
|
295
302
|
assert_not_same(ds3.fields,ds_exp.fields)
|
296
303
|
|
297
304
|
|
data/test/test_distribution.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require(File.dirname(__FILE__)+'/
|
1
|
+
require(File.dirname(__FILE__)+'/helpers_tests.rb')
|
2
2
|
|
3
3
|
class StatsampleDominanceAnalysisTestCase < MiniTest::Unit::TestCase
|
4
4
|
def test_dominance_univariate
|
@@ -21,6 +21,7 @@ class StatsampleDominanceAnalysisTestCase < MiniTest::Unit::TestCase
|
|
21
21
|
assert_equal(expected_dominances[i], da.conditional_dominance_pairwise(a[0],a[1]))
|
22
22
|
assert_equal(expected_g_dominances[i], da.general_dominance_pairwise(a[0],a[1]))
|
23
23
|
end
|
24
|
+
assert(da.summary.size>0)
|
24
25
|
end
|
25
26
|
def test_dominance_multivariate
|
26
27
|
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]]
|
data/test/test_factor.rb
CHANGED
data/test/test_ggobi.rb
CHANGED
data/test/test_gsl.rb
CHANGED
data/test/test_histogram.rb
CHANGED
data/test/test_logit.rb
CHANGED
data/test/test_matrix.rb
CHANGED
data/test/test_mle.rb
CHANGED
data/test/test_multiset.rb
CHANGED
data/test/test_permutation.rb
CHANGED
data/test/test_regression.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require(File.dirname(__FILE__)+'/
|
1
|
+
require(File.dirname(__FILE__)+'/helpers_tests.rb')
|
2
2
|
|
3
3
|
class StatsampleRegressionTestCase < MiniTest::Unit::TestCase
|
4
4
|
context "Example with missing data" do
|
@@ -19,7 +19,7 @@ class StatsampleRegressionTestCase < MiniTest::Unit::TestCase
|
|
19
19
|
assert_in_delta(0.132, @lr.constant,0.001,"constant")
|
20
20
|
assert_in_delta(0.195, @lr.coeffs_se['x'],0.001,"coeff x se")
|
21
21
|
assert_in_delta(0.064, @lr.constant_se,0.001,"constant se")
|
22
|
-
|
22
|
+
end
|
23
23
|
end
|
24
24
|
def test_parameters
|
25
25
|
@x=[13,20,10,33,15].to_vector(:scale)
|
@@ -45,7 +45,6 @@ class StatsampleRegressionTestCase < MiniTest::Unit::TestCase
|
|
45
45
|
ds={'a'=>a,'b'=>b,'y'=>y}.to_dataset
|
46
46
|
lr=Statsample::Regression::Multiple::RubyEngine.new(ds,'y')
|
47
47
|
assert(lr.summary.size>0)
|
48
|
-
|
49
48
|
end
|
50
49
|
def test_multiple_dependent
|
51
50
|
complete=Matrix[
|
@@ -152,7 +151,7 @@ class StatsampleRegressionTestCase < MiniTest::Unit::TestCase
|
|
152
151
|
assert_in_delta(639.6,lr.sst,0.001)
|
153
152
|
assert_in_delta(583.76,lr.ssr,0.001)
|
154
153
|
assert_in_delta(55.840,lr.sse,0.001)
|
155
|
-
|
154
|
+
assert(lr.summary.size>0, "#{name} without summary")
|
156
155
|
end
|
157
156
|
def model_test(lr,name='undefined')
|
158
157
|
model_test_matrix(lr,name)
|
data/test/test_reliability.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require(File.dirname(__FILE__)+'/
|
1
|
+
require(File.dirname(__FILE__)+'/helpers_tests.rb')
|
2
2
|
|
3
3
|
|
4
4
|
class StatsampleReliabilityTestCase < MiniTest::Unit::TestCase
|
@@ -12,6 +12,7 @@ class StatsampleReliabilityTestCase < MiniTest::Unit::TestCase
|
|
12
12
|
@n_variables.times do |i|
|
13
13
|
@ds[i]=base.collect {|v| v+rand()}.to_scale
|
14
14
|
end
|
15
|
+
|
15
16
|
@ds.update_valid_data
|
16
17
|
@k=@ds.fields.size
|
17
18
|
@cm=Statsample::Bivariate.covariance_matrix(@ds)
|
@@ -94,11 +95,23 @@ class StatsampleReliabilityTestCase < MiniTest::Unit::TestCase
|
|
94
95
|
@x4=[1,2,3,4,4,4,4,3,4,4,5,30].to_vector(:scale)
|
95
96
|
@ds={'x1'=>@x1,'x2'=>@x2,'x3'=>@x3,'x4'=>@x4}.to_dataset
|
96
97
|
@ia=Statsample::Reliability::ItemAnalysis.new(@ds)
|
97
|
-
|
98
|
+
@cov_matrix=Statsample::Bivariate.covariance_matrix(@ds)
|
98
99
|
end
|
99
100
|
should "return correct values for item analysis" do
|
100
101
|
assert_in_delta(0.980,@ia.alpha,0.001)
|
101
102
|
assert_in_delta(0.999,@ia.alpha_standarized,0.001)
|
103
|
+
var_mean=4.times.map{|m| @cov_matrix[m,m]}.to_scale.mean
|
104
|
+
assert_in_delta(var_mean, @ia.variances_mean)
|
105
|
+
|
106
|
+
covariances=[]
|
107
|
+
4.times.each {|i|
|
108
|
+
4.times.each {|j|
|
109
|
+
if i!=j
|
110
|
+
covariances.push(@cov_matrix[i,j])
|
111
|
+
end
|
112
|
+
}
|
113
|
+
}
|
114
|
+
assert_in_delta(covariances.to_scale.mean, @ia.covariances_mean)
|
102
115
|
assert_in_delta(0.999,@ia.item_total_correlation()['x1'],0.001)
|
103
116
|
assert_in_delta(1050.455,@ia.stats_if_deleted()['x1'][:variance_sample],0.001)
|
104
117
|
end
|
data/test/test_resample.rb
CHANGED
data/test/test_srs.rb
CHANGED
data/test/test_statistics.rb
CHANGED
data/test/test_stest.rb
CHANGED
data/test/test_stratified.rb
CHANGED
data/test/test_svg_graph.rb
CHANGED
data/test/test_test_f.rb
CHANGED
data/test/test_test_t.rb
CHANGED
data/test/test_umannwhitney.rb
CHANGED