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
data/test/test_srs.rb CHANGED
@@ -1,9 +1,9 @@
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 StatsampleSrsTestCase < MiniTest::Unit::TestCase
3
+ class StatsampleSrsTestCase < Minitest::Test
4
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)
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
8
  end
9
9
  end
@@ -1,77 +1,79 @@
1
- require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
2
- class StatsampleStatisicsTestCase < MiniTest::Unit::TestCase
3
-
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
+ class StatsampleStatisicsTestCase < Minitest::Test
4
3
  def initialize(*args)
5
4
  super
6
5
  end
6
+
7
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
-
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)
15
14
  end
15
+
16
16
  def test_recode_repeated
17
- a=%w{a b c c d d d e}
18
- exp=["a","b","c_1","c_2","d_1","d_2","d_3","e"]
19
- assert_equal(exp,a.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, a.recode_repeated)
20
20
  end
21
- def test_is_number
22
- assert("10".is_number?)
23
- assert("-10".is_number?)
24
- assert("0.1".is_number?)
25
- assert("-0.1".is_number?)
26
- assert("10e3".is_number?)
27
- assert("10e-3".is_number?)
28
- assert(!"1212-1212-1".is_number?)
29
- assert(!"a10".is_number?)
30
- assert(!"".is_number?)
31
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
32
  end
33
+
33
34
  def test_estimation_mean
34
- v=([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]).to_vector(:scale)
35
- assert_equal(50,v.size)
36
- assert_equal(1471,v.sum())
37
- #limits=Statsample::SRS.mean_confidence_interval_z(v.mean(), v.sds(), v.size,676,0.80)
35
+ v = ([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]).to_vector(:scale)
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)
38
39
  end
40
+
39
41
  def test_estimation_proportion
40
42
  # total
41
- pop=3042
42
- sam=200
43
- prop=0.19
43
+ pop = 3042
44
+ sam = 200
45
+ prop = 0.19
44
46
  assert_in_delta(81.8, Statsample::SRS.proportion_total_sd_ep_wor(prop, sam, pop), 0.1)
45
47
 
46
48
  # confidence limits
47
- pop=500
48
- sam=100
49
- prop=0.37
50
- a=0.95
51
- l= Statsample::SRS.proportion_confidence_interval_z(prop, sam, pop, a)
52
- assert_in_delta(0.28,l[0],0.01)
53
- assert_in_delta(0.46,l[1],0.01)
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)
54
56
  end
57
+
55
58
  def test_ml
56
- if(true)
57
- #real=[1,1,1,1].to_vector(:scale)
59
+ if true
60
+ # real=[1,1,1,1].to_vector(:scale)
58
61
 
59
- #pred=[0.0001,0.0001,0.0001,0.0001].to_vector(:scale)
62
+ # pred=[0.0001,0.0001,0.0001,0.0001].to_vector(:scale)
60
63
  # puts Statsample::Bivariate.maximum_likehood_dichotomic(pred,real)
61
64
 
62
65
  end
63
66
  end
64
67
 
65
-
66
68
  def test_simple_linear_regression
67
- a=[1,2,3,4,5,6].to_vector(:scale)
68
- b=[6,2,4,10,12,8].to_vector(:scale)
69
- reg = Statsample::Regression::Simple.new_from_vectors(a,b)
70
- assert_in_delta((reg.ssr+reg.sse).to_f,reg.sst,0.001)
71
- assert_in_delta(Statsample::Bivariate.pearson(a,b),reg.r,0.001)
72
- assert_in_delta(2.4,reg.a,0.01)
73
- assert_in_delta(1.314,reg.b,0.001)
74
- assert_in_delta(0.657,reg.r,0.001)
75
- assert_in_delta(0.432,reg.r2,0.001)
69
+ a = [1, 2, 3, 4, 5, 6].to_vector(:scale)
70
+ b = [6, 2, 4, 10, 12, 8].to_vector(:scale)
71
+ reg = Statsample::Regression::Simple.new_from_vectors(a, b)
72
+ assert_in_delta((reg.ssr + reg.sse).to_f, reg.sst, 0.001)
73
+ assert_in_delta(Statsample::Bivariate.pearson(a, b), reg.r, 0.001)
74
+ assert_in_delta(2.4, reg.a, 0.01)
75
+ assert_in_delta(1.314, reg.b, 0.001)
76
+ assert_in_delta(0.657, reg.r, 0.001)
77
+ assert_in_delta(0.432, reg.r2, 0.001)
76
78
  end
77
79
  end
data/test/test_stest.rb CHANGED
@@ -1,56 +1,55 @@
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 StatsampleTestTestCase < MiniTest::Unit::TestCase
3
+ class StatsampleTestTestCase < Minitest::Test
4
4
  def test_chi_square_matrix_with_expected
5
- real=Matrix[[95,95],[45,155]]
6
- expected=Matrix[[68,122],[72,128]]
5
+ real = Matrix[[95, 95], [45, 155]]
6
+ expected = Matrix[[68, 122], [72, 128]]
7
7
  assert_nothing_raised do
8
- Statsample::Test.chi_square(real,expected)
8
+ Statsample::Test.chi_square(real, expected)
9
9
  end
10
- chi=Statsample::Test.chi_square(real,expected).chi_square
11
- assert_in_delta(32.53,chi,0.1)
12
-
10
+ chi = Statsample::Test.chi_square(real, expected).chi_square
11
+ assert_in_delta(32.53, chi, 0.1)
13
12
  end
13
+
14
14
  def test_chi_square_matrix_only_observed
15
- observed=Matrix[[20,30,40],[30,40,50],[60,70,80],[10,20,40]]
15
+ observed = Matrix[[20, 30, 40], [30, 40, 50], [60, 70, 80], [10, 20, 40]]
16
16
  assert_nothing_raised do
17
17
  Statsample::Test.chi_square(observed)
18
18
  end
19
- chi=Statsample::Test.chi_square(observed)
19
+ chi = Statsample::Test.chi_square(observed)
20
20
  assert_in_delta(9.5602, chi.chi_square, 0.0001)
21
21
  assert_in_delta(0.1444, chi.probability, 0.0001)
22
22
 
23
23
  assert_equal(6, chi.df)
24
-
25
24
  end
26
-
25
+
27
26
  def test_u_mannwhitney
28
- a=[1,2,3,4,5,6].to_scale
29
- b=[0,5,7,9,10,11].to_scale
30
- assert_equal(7.5, Statsample::Test.u_mannwhitney(a,b).u)
31
- assert_equal(7.5, Statsample::Test.u_mannwhitney(b,a).u)
32
- a=[1, 7,8,9,10,11].to_scale
33
- b=[2,3,4,5,6,12].to_scale
34
- assert_equal(11, Statsample::Test.u_mannwhitney(a,b).u)
27
+ a = [1, 2, 3, 4, 5, 6].to_scale
28
+ b = [0, 5, 7, 9, 10, 11].to_scale
29
+ assert_equal(7.5, Statsample::Test.u_mannwhitney(a, b).u)
30
+ assert_equal(7.5, Statsample::Test.u_mannwhitney(b, a).u)
31
+ a = [1, 7, 8, 9, 10, 11].to_scale
32
+ b = [2, 3, 4, 5, 6, 12].to_scale
33
+ assert_equal(11, Statsample::Test.u_mannwhitney(a, b).u)
35
34
  end
36
35
 
37
-
38
36
  def test_levene
39
- a=[1,2,3,4,5,6,7,8,100,10].to_scale
40
- b=[30,40,50,60,70,80,90,100,110,120].to_scale
41
- levene=Statsample::Test::Levene.new([a,b])
37
+ a = [1, 2, 3, 4, 5, 6, 7, 8, 100, 10].to_scale
38
+ b = [30, 40, 50, 60, 70, 80, 90, 100, 110, 120].to_scale
39
+ levene = Statsample::Test::Levene.new([a, b])
42
40
  assert_levene(levene)
43
41
  end
42
+
44
43
  def test_levene_dataset
45
- a=[1,2,3,4,5,6,7,8,100,10].to_scale
46
- b=[30,40,50,60,70,80,90,100,110,120].to_scale
47
- ds={'a'=>a,'b'=>b}.to_dataset
48
- levene=Statsample::Test::Levene.new(ds)
44
+ a = [1, 2, 3, 4, 5, 6, 7, 8, 100, 10].to_scale
45
+ b = [30, 40, 50, 60, 70, 80, 90, 100, 110, 120].to_scale
46
+ ds = { 'a' => a, 'b' => b }.to_dataset
47
+ levene = Statsample::Test::Levene.new(ds)
49
48
  assert_levene(levene)
50
49
  end
50
+
51
51
  def assert_levene(levene)
52
52
  assert_in_delta(0.778, levene.f, 0.001)
53
53
  assert_in_delta(0.389, levene.probability, 0.001)
54
54
  end
55
-
56
55
  end
@@ -1,17 +1,17 @@
1
- require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
2
-
3
- class StatsampleStratifiedTestCase < MiniTest::Unit::TestCase
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
4
2
 
3
+ class StatsampleStratifiedTestCase < Minitest::Test
5
4
  def initialize(*args)
6
5
  super
7
6
  end
7
+
8
8
  def test_mean
9
- a=[10,20,30,40,50]
10
- b=[110,120,130,140]
11
- pop=a+b
12
- av=a.to_vector(:scale)
13
- bv=b.to_vector(:scale)
14
- popv=pop.to_vector(:scale)
15
- assert_equal(popv.mean,Statsample::StratifiedSample.mean(av,bv))
9
+ a = [10, 20, 30, 40, 50]
10
+ b = [110, 120, 130, 140]
11
+ pop = a + b
12
+ av = a.to_vector(:scale)
13
+ bv = b.to_vector(:scale)
14
+ popv = pop.to_vector(:scale)
15
+ assert_equal(popv.mean, Statsample::StratifiedSample.mean(av, bv))
16
16
  end
17
17
  end
data/test/test_test_f.rb CHANGED
@@ -1,32 +1,32 @@
1
- require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
2
- class StatsampleTestFTestCase < MiniTest::Unit::TestCase
3
- context(Statsample::Test::F) do
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
+ class StatsampleTestFTestCase < Minitest::Test
3
+ context(Statsample::Test::F) do
4
4
  setup do
5
- @ssb=84
6
- @ssw=68
7
- @df_num=2
8
- @df_den=15
9
- @f=Statsample::Test::F.new(@ssb.quo(@df_num),@ssw.quo(@df_den), @df_num, @df_den)
5
+ @ssb = 84
6
+ @ssw = 68
7
+ @df_num = 2
8
+ @df_den = 15
9
+ @f = Statsample::Test::F.new(@ssb.quo(@df_num), @ssw.quo(@df_den), @df_num, @df_den)
10
10
  end
11
- should "have #f equal to msb/msw" do
11
+ should 'have #f equal to msb/msw' do
12
12
  assert_equal((@ssb.quo(@df_num)).quo(@ssw.quo(@df_den)), @f.f)
13
13
  end
14
- should "have df total equal to df_num+df_den" do
14
+ should 'have df total equal to df_num+df_den' do
15
15
  assert_equal(@df_num + @df_den, @f.df_total)
16
16
  end
17
- should "have probability near 0.002" do
17
+ should 'have probability near 0.002' do
18
18
  assert_in_delta(0.002, @f.probability, 0.0005)
19
19
  end
20
- should "be coerced into float" do
20
+ should 'be coerced into float' do
21
21
  assert_equal(@f.to_f, @f.f)
22
22
  end
23
-
24
- context("method summary") do
23
+
24
+ context('method summary') do
25
25
  setup do
26
- @summary=@f.summary
26
+ @summary = @f.summary
27
27
  end
28
- should "have size > 0" do
29
- assert(@summary.size>0)
28
+ should 'have size > 0' do
29
+ assert(@summary.size > 0)
30
30
  end
31
31
  end
32
32
  end
@@ -1,28 +1,28 @@
1
- require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
2
- class StatsampleTestKolmogorovSmirnovTestCase < MiniTest::Unit::TestCase
3
- context(Statsample::Test::KolmogorovSmirnov) do
4
- should "calculate correctly D for two given samples" do
5
- a=[1.1,2.5,5.6,9]
6
- b=[1,2.3,5.8,10]
7
- ks=Statsample::Test::KolmogorovSmirnov.new(a,b)
8
- assert_equal(0.25,ks.d)
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
+ class StatsampleTestKolmogorovSmirnovTestCase < Minitest::Test
3
+ context(Statsample::Test::KolmogorovSmirnov) do
4
+ should 'calculate correctly D for two given samples' do
5
+ a = [1.1, 2.5, 5.6, 9]
6
+ b = [1, 2.3, 5.8, 10]
7
+ ks = Statsample::Test::KolmogorovSmirnov.new(a, b)
8
+ assert_equal(0.25, ks.d)
9
9
  end
10
- should "calculate correctly D for a normal sample and Normal Distribution" do
11
- a=[0.30022510,-0.36664035,0.08593404,1.29881130,-0.49878633,-0.63056010, 0.28397638, -0.04913700,0.03566644,-1.33414346]
12
- ks=Statsample::Test::KolmogorovSmirnov.new(a,Distribution::Normal)
13
- assert_in_delta(0.282, ks.d,0.001)
10
+ should 'calculate correctly D for a normal sample and Normal Distribution' do
11
+ a = [0.30022510, -0.36664035, 0.08593404, 1.29881130, -0.49878633, -0.63056010, 0.28397638, -0.04913700, 0.03566644, -1.33414346]
12
+ ks = Statsample::Test::KolmogorovSmirnov.new(a, Distribution::Normal)
13
+ assert_in_delta(0.282, ks.d, 0.001)
14
14
  end
15
- should "calculate correctly D for a variable normal and Normal Distribution" do
16
- rng=Distribution::Normal.rng
17
- a=100.times.map {rng.call}
18
- ks=Statsample::Test::KolmogorovSmirnov.new(a,Distribution::Normal)
19
- assert(ks.d<0.15)
15
+ should 'calculate correctly D for a variable normal and Normal Distribution' do
16
+ rng = Distribution::Normal.rng
17
+ a = 100.times.map { rng.call }
18
+ ks = Statsample::Test::KolmogorovSmirnov.new(a, Distribution::Normal)
19
+ assert(ks.d < 0.15)
20
20
  end
21
-
21
+
22
22
  context(Statsample::Test::KolmogorovSmirnov::EmpiricDistribution) do
23
- should "Create a correct empirical distribution for an array" do
24
- a=[10,9,8,7,6,5,4,3,2,1]
25
- ed=Statsample::Test::KolmogorovSmirnov::EmpiricDistribution.new(a)
23
+ should 'Create a correct empirical distribution for an array' do
24
+ a = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
25
+ ed = Statsample::Test::KolmogorovSmirnov::EmpiricDistribution.new(a)
26
26
  assert_equal(0, ed.cdf(-2))
27
27
  assert_equal(0.5, ed.cdf(5))
28
28
  assert_equal(0.5, ed.cdf(5.5))
data/test/test_test_t.rb CHANGED
@@ -1,62 +1,62 @@
1
- require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
2
- class StatsampleTestTTestCase < MiniTest::Unit::TestCase
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
+ class StatsampleTestTTestCase < Minitest::Test
3
3
  include Statsample::Test
4
4
  include Math
5
- context T do
5
+ context T do
6
6
  setup do
7
- @a=[30.02, 29.99, 30.11, 29.97, 30.01, 29.99].to_scale
8
- @b=[29.89, 29.93, 29.72, 29.98, 30.02, 29.98].to_scale
9
- @x1=@a.mean
10
- @x2=@b.mean
11
- @s1=@a.sd
12
- @s2=@b.sd
13
- @n1=@a.n
14
- @n2=@b.n
15
- end
16
- should "calculate correctly standard t" do
17
- t=Statsample::Test::T.new(@x1, @s1.quo(Math.sqrt(@a.n)), @a.n-1)
7
+ @a = [30.02, 29.99, 30.11, 29.97, 30.01, 29.99].to_scale
8
+ @b = [29.89, 29.93, 29.72, 29.98, 30.02, 29.98].to_scale
9
+ @x1 = @a.mean
10
+ @x2 = @b.mean
11
+ @s1 = @a.sd
12
+ @s2 = @b.sd
13
+ @n1 = @a.n
14
+ @n2 = @b.n
15
+ end
16
+ should 'calculate correctly standard t' do
17
+ t = Statsample::Test::T.new(@x1, @s1.quo(Math.sqrt(@a.n)), @a.n - 1)
18
18
  assert_equal((@x1).quo(@s1.quo(Math.sqrt(@a.n))), t.t)
19
- assert_equal(@a.n-1, t.df)
20
- assert(t.summary.size>0)
21
- end
22
- should "calculate correctly t for one sample" do
23
- t1=[6, 4, 6, 7, 4,5,5,12,6,1].to_scale
24
- t2=[9, 6, 5,10,10,8,7,10,6,5].to_scale
25
- d=t1-t2
26
- t=Statsample::Test::T::OneSample.new(d)
19
+ assert_equal(@a.n - 1, t.df)
20
+ assert(t.summary.size > 0)
21
+ end
22
+ should 'calculate correctly t for one sample' do
23
+ t1 = [6, 4, 6, 7, 4, 5, 5, 12, 6, 1].to_scale
24
+ t2 = [9, 6, 5, 10, 10, 8, 7, 10, 6, 5].to_scale
25
+ d = t1 - t2
26
+ t = Statsample::Test::T::OneSample.new(d)
27
27
  assert_in_delta(-2.631, t.t, 0.001)
28
- assert_in_delta( 0.027, t.probability, 0.001)
29
- assert_in_delta( 0.76012, t.se, 0.0001)
30
- assert(t.summary.size>0)
31
- end
32
- should "calculate correctly t for two samples" do
33
- assert_in_delta(1.959, T.two_sample_independent(@x1, @x2, @s1, @s2, @n1, @n2),0.001)
34
- assert_in_delta(1.959, T.two_sample_independent(@x1, @x2, @s1, @s2, @n1, @n2,true),0.001)
35
- end
36
- should "calculate correctly df for equal and unequal variance" do
37
- assert_equal(10, T.df_equal_variance(@n1,@n2))
38
- assert_in_delta(7.03, T.df_not_equal_variance(@s1,@s2,@n1,@n2),0.001)
39
- end
40
- should "calculate all values for T object" do
41
- t=Statsample::Test.t_two_samples_independent(@a,@b)
42
- assert(t.summary.size>0)
43
- assert_in_delta(1.959, t.t_equal_variance,0.001)
44
- assert_in_delta(1.959, t.t_not_equal_variance,0.001)
45
- assert_in_delta(10, t.df_equal_variance,0.001)
46
- assert_in_delta(7.03, t.df_not_equal_variance,0.001)
47
- assert_in_delta(0.07856, t.probability_equal_variance,0.001)
48
- assert_in_delta(0.09095, t.probability_not_equal_variance,0.001)
49
- end
50
- should "be the same using shorthand" do
51
- v=100.times.map {rand(100)}.to_scale
28
+ assert_in_delta(0.027, t.probability, 0.001)
29
+ assert_in_delta(0.76012, t.se, 0.0001)
30
+ assert(t.summary.size > 0)
31
+ end
32
+ should 'calculate correctly t for two samples' do
33
+ assert_in_delta(1.959, T.two_sample_independent(@x1, @x2, @s1, @s2, @n1, @n2), 0.001)
34
+ assert_in_delta(1.959, T.two_sample_independent(@x1, @x2, @s1, @s2, @n1, @n2, true), 0.001)
35
+ end
36
+ should 'calculate correctly df for equal and unequal variance' do
37
+ assert_equal(10, T.df_equal_variance(@n1, @n2))
38
+ assert_in_delta(7.03, T.df_not_equal_variance(@s1, @s2, @n1, @n2), 0.001)
39
+ end
40
+ should 'calculate all values for T object' do
41
+ t = Statsample::Test.t_two_samples_independent(@a, @b)
42
+ assert(t.summary.size > 0)
43
+ assert_in_delta(1.959, t.t_equal_variance, 0.001)
44
+ assert_in_delta(1.959, t.t_not_equal_variance, 0.001)
45
+ assert_in_delta(10, t.df_equal_variance, 0.001)
46
+ assert_in_delta(7.03, t.df_not_equal_variance, 0.001)
47
+ assert_in_delta(0.07856, t.probability_equal_variance, 0.001)
48
+ assert_in_delta(0.09095, t.probability_not_equal_variance, 0.001)
49
+ end
50
+ should 'be the same using shorthand' do
51
+ v = 100.times.map { rand(100) }.to_scale
52
52
  assert_equal(Statsample::Test.t_one_sample(v).t, T::OneSample.new(v).t)
53
53
  end
54
- should "calculate all values for one sample T test" do
55
- u=@a.mean+(1-rand*2)
56
- tos=T::OneSample.new(@a,{:u=>u})
57
- assert_equal((@a.mean-u).quo(@a.sd.quo(sqrt(@a.n))), tos.t)
58
- assert_equal(@a.n-1, tos.df)
59
- assert(tos.summary.size>0)
54
+ should 'calculate all values for one sample T test' do
55
+ u = @a.mean + (1 - rand * 2)
56
+ tos = T::OneSample.new(@a, u: u)
57
+ assert_equal((@a.mean - u).quo(@a.sd.quo(sqrt(@a.n))), tos.t)
58
+ assert_equal(@a.n - 1, tos.df)
59
+ assert(tos.summary.size > 0)
60
60
  end
61
61
  end
62
62
  end