statsample 0.16.0 → 0.17.0
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.
- data.tar.gz.sig +0 -0
- data/History.txt +7 -0
- data/Manifest.txt +6 -4
- data/README.txt +5 -1
- data/Rakefile +1 -1
- data/examples/boxplot.rb +17 -0
- data/examples/dominance_analysis_bootstrap.rb +5 -0
- data/examples/histogram.rb +14 -0
- data/examples/scatterplot.rb +4 -3
- data/lib/distribution/normalbivariate.rb +1 -1
- data/lib/statsample.rb +16 -3
- data/lib/statsample/bivariate.rb +4 -2
- data/lib/statsample/converter/csv.rb +0 -2
- data/lib/statsample/converters.rb +13 -1
- data/lib/statsample/dataset.rb +23 -15
- data/lib/statsample/dominanceanalysis.rb +3 -2
- data/lib/statsample/dominanceanalysis/bootstrap.rb +2 -1
- data/lib/statsample/factor/parallelanalysis.rb +1 -1
- data/lib/statsample/factor/principalaxis.rb +1 -1
- data/lib/statsample/graph.rb +2 -0
- data/lib/statsample/graph/boxplot.rb +234 -0
- data/lib/statsample/graph/histogram.rb +133 -0
- data/lib/statsample/graph/scatterplot.rb +1 -9
- data/lib/statsample/histogram.rb +47 -11
- data/lib/statsample/mle.rb +4 -4
- data/lib/statsample/mle/normal.rb +3 -3
- data/lib/statsample/regression/multiple/baseengine.rb +1 -1
- data/lib/statsample/regression/multiple/gslengine.rb +0 -1
- data/lib/statsample/regression/multiple/matrixengine.rb +1 -1
- data/lib/statsample/reliability.rb +1 -0
- data/lib/statsample/reliability/scaleanalysis.rb +3 -51
- data/lib/statsample/reliability/skillscaleanalysis.rb +93 -0
- data/lib/statsample/srs.rb +1 -1
- data/lib/statsample/test/umannwhitney.rb +1 -1
- data/lib/statsample/vector.rb +13 -36
- data/test/test_factor.rb +1 -1
- data/test/test_ggobi.rb +0 -5
- data/test/test_histogram.rb +75 -18
- data/test/test_mle.rb +0 -44
- data/test/test_reliability_skillscale.rb +41 -0
- data/test/test_statistics.rb +3 -3
- data/test/test_stest.rb +2 -2
- data/test/test_vector.rb +13 -8
- metadata +36 -18
- metadata.gz.sig +0 -0
- data/lib/statsample/combination.rb +0 -114
- data/lib/statsample/permutation.rb +0 -98
- data/test/test_combination.rb +0 -37
- data/test/test_permutation.rb +0 -42
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,114 +0,0 @@
|
|
1
|
-
module Statsample
|
2
|
-
# Combination class systematically generates all combinations of n elements, taken r at a time.
|
3
|
-
# With rbgsl, GSL::Combination is available for extra speed
|
4
|
-
# == Use:
|
5
|
-
# comb=Statsample::Combination.new(3,5)
|
6
|
-
# => #<Statsample::Combination:0x7f6323804e08 @n=5, @d=#<Statsample::Combination::CombinationGsl:0x7f63237ff7f0 @n=5, @k=3, @c=GSL::Combination>, @k=3>
|
7
|
-
# comb.each{|c| p c }
|
8
|
-
# [0, 1, 2]
|
9
|
-
# [0, 1, 3]
|
10
|
-
# [0, 1, 4]
|
11
|
-
# [0, 2, 3]
|
12
|
-
# [0, 2, 4]
|
13
|
-
# [0, 3, 4]
|
14
|
-
# [1, 2, 3]
|
15
|
-
# [1, 2, 4]
|
16
|
-
# [1, 3, 4]
|
17
|
-
# [2, 3, 4]
|
18
|
-
# == Reference:
|
19
|
-
# * http://snippets.dzone.com/posts/show/4666
|
20
|
-
#
|
21
|
-
class Combination
|
22
|
-
attr_reader :d
|
23
|
-
def initialize(k,n,only_ruby=false)
|
24
|
-
@k=k
|
25
|
-
@n=n
|
26
|
-
if Statsample.has_gsl? and !only_ruby
|
27
|
-
@d=CombinationGsl.new(@k,@n)
|
28
|
-
else
|
29
|
-
@d=CombinationRuby.new(@k,@n)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
def each
|
33
|
-
reset
|
34
|
-
while a=next_value
|
35
|
-
yield a
|
36
|
-
end
|
37
|
-
end
|
38
|
-
def reset
|
39
|
-
@d.reset
|
40
|
-
end
|
41
|
-
def next_value
|
42
|
-
@d.next_value
|
43
|
-
end
|
44
|
-
class CombinationRuby # :nodoc:
|
45
|
-
attr_reader :data
|
46
|
-
def initialize(k,n)
|
47
|
-
raise "k<=n" if k>n
|
48
|
-
@k=k
|
49
|
-
@n=n
|
50
|
-
reset
|
51
|
-
end
|
52
|
-
def reset
|
53
|
-
@data=[]
|
54
|
-
(0...@k).each {|i| @data[i] = i }
|
55
|
-
end
|
56
|
-
def each
|
57
|
-
reset
|
58
|
-
while a=next_value
|
59
|
-
yield a
|
60
|
-
end
|
61
|
-
end
|
62
|
-
def next_value
|
63
|
-
return false if !@data
|
64
|
-
old_comb=@data.dup
|
65
|
-
i = @k - 1;
|
66
|
-
@data[i]+=1
|
67
|
-
while ((i >= 0) and (@data[i] >= @n - @k + 1 + i)) do
|
68
|
-
i-=1;
|
69
|
-
@data[i]+=1;
|
70
|
-
end
|
71
|
-
|
72
|
-
if (@data[0] > @n - @k) # Combination (n-k, n-k+1, ..., n) reached */
|
73
|
-
@data=false # No more combinations can be generated
|
74
|
-
else
|
75
|
-
# comb now looks like (..., x, n, n, n, ..., n).
|
76
|
-
# Turn it into (..., x, x + 1, x + 2, ...)
|
77
|
-
i = i+1
|
78
|
-
(i...@k).each{ |i1|
|
79
|
-
@data[i1] = @data[i1 - 1] + 1
|
80
|
-
}
|
81
|
-
end
|
82
|
-
return old_comb
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# rb-gsl engine for Combinations
|
87
|
-
class CombinationGsl # :nodoc:
|
88
|
-
def initialize(k,n)
|
89
|
-
require 'gsl'
|
90
|
-
raise "k<=n" if k>n
|
91
|
-
@k=k
|
92
|
-
@n=n
|
93
|
-
reset
|
94
|
-
end
|
95
|
-
def reset
|
96
|
-
@c= ::GSL::Combination.calloc(@n, @k);
|
97
|
-
end
|
98
|
-
def next_value
|
99
|
-
return false if !@c
|
100
|
-
data=@c.data.to_a
|
101
|
-
if @c.next != GSL::SUCCESS
|
102
|
-
@c=false
|
103
|
-
end
|
104
|
-
return data
|
105
|
-
end
|
106
|
-
def each
|
107
|
-
reset
|
108
|
-
begin
|
109
|
-
yield @c.data.to_a
|
110
|
-
end while @c.next == GSL::SUCCESS
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
module Statsample
|
2
|
-
# Permutation class systematically generates all permutations
|
3
|
-
# of elements on an array, using Dijkstra algorithm (1997).
|
4
|
-
#
|
5
|
-
# As argument, you could use
|
6
|
-
# * Number of elements: an array with numbers from 0 to n-1 will be used
|
7
|
-
# * Array: if ordered, you obtain permutations on lexicographic order
|
8
|
-
# you can repeat elements, if you will.
|
9
|
-
#
|
10
|
-
# Use:
|
11
|
-
# perm=Statsample::Permutation.new(3)
|
12
|
-
# perm.permutations
|
13
|
-
# => [[0,1,2],[0,2,1],[1,0,2],[1,2,0],[2,0,1],[2,1,0]]
|
14
|
-
# perm=Statsample::Permutation.new([0,0,1,1])
|
15
|
-
# => [[0,0,1,1],[0,1,0,1],[0,1,1,0],[1,0,0,1],[1,0,1,0],[1,1,0,0]]
|
16
|
-
#
|
17
|
-
# == Reference:
|
18
|
-
# * http://www.cut-the-knot.org/do_you_know/AllPerm.shtml
|
19
|
-
class Permutation
|
20
|
-
attr_reader :permutation_number
|
21
|
-
def initialize(v)
|
22
|
-
if v.is_a? Numeric
|
23
|
-
@original=(0...v.to_i).to_a
|
24
|
-
@permutation_number=factorial(v)
|
25
|
-
else
|
26
|
-
@original=v
|
27
|
-
calculate_max_iterations_from_array
|
28
|
-
end
|
29
|
-
@n=@original.size
|
30
|
-
reset
|
31
|
-
end
|
32
|
-
def calculate_max_iterations_from_array
|
33
|
-
if @original.respond_to? :frequencies
|
34
|
-
freq=@original.frequencies
|
35
|
-
else
|
36
|
-
freq=@original.to_vector.frequencies
|
37
|
-
end
|
38
|
-
if freq.length==@original.size
|
39
|
-
@permutation_number=factorial(@original.size)
|
40
|
-
else
|
41
|
-
numerator=factorial(@original.size)
|
42
|
-
denominator=freq.inject(1) {|a,v|
|
43
|
-
a*factorial(v[1])
|
44
|
-
}
|
45
|
-
@permutation_number=numerator/denominator
|
46
|
-
end
|
47
|
-
end
|
48
|
-
def factorial (n)
|
49
|
-
(1..n).inject(1){|a,v| a*v}
|
50
|
-
end
|
51
|
-
def reset
|
52
|
-
@iterations=0
|
53
|
-
@data=@original.to_a.dup
|
54
|
-
end
|
55
|
-
def each
|
56
|
-
reset
|
57
|
-
@permutation_number.times do
|
58
|
-
yield next_value
|
59
|
-
end
|
60
|
-
end
|
61
|
-
# Returns permutations
|
62
|
-
def permutations
|
63
|
-
a=Array.new
|
64
|
-
each {|c| a.push(c)}
|
65
|
-
a
|
66
|
-
end
|
67
|
-
def next_value
|
68
|
-
prev=@data.dup
|
69
|
-
i = @n-1
|
70
|
-
while @data[i-1] >= @data[i]
|
71
|
-
#return false if i<0
|
72
|
-
i=i-1
|
73
|
-
end
|
74
|
-
j=@n
|
75
|
-
while @data[j-1] <= @data[i-1]
|
76
|
-
j=j-1
|
77
|
-
end
|
78
|
-
# swap values at positions (i-1) and (j-1)
|
79
|
-
swap(i-1, j-1);
|
80
|
-
|
81
|
-
i+=1
|
82
|
-
j = @n
|
83
|
-
|
84
|
-
while (i < j)
|
85
|
-
swap(i-1, j-1);
|
86
|
-
i+=1;
|
87
|
-
j-=1;
|
88
|
-
sprintf("%d %d",i,j)
|
89
|
-
end
|
90
|
-
prev
|
91
|
-
end
|
92
|
-
def swap(i,j)
|
93
|
-
tmp=@data[i]
|
94
|
-
@data[i]=@data[j]
|
95
|
-
@data[j]=tmp
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
data/test/test_combination.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require(File.dirname(__FILE__)+'/helpers_tests.rb')
|
2
|
-
|
3
|
-
class StatsampleCombinationTestCase < MiniTest::Unit::TestCase
|
4
|
-
def test_basic
|
5
|
-
k=3
|
6
|
-
n=5
|
7
|
-
expected=[[0,1,2],[0,1,3],[0,1,4],[0,2,3],[0,2,4],[0,3,4],[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
|
8
|
-
comb=Statsample::Combination.new(k,n)
|
9
|
-
a=[]
|
10
|
-
comb.each{|y|
|
11
|
-
a.push(y)
|
12
|
-
}
|
13
|
-
assert_equal(expected,a)
|
14
|
-
end
|
15
|
-
def test_gsl_versus_ruby
|
16
|
-
if Statsample.has_gsl?
|
17
|
-
k=3
|
18
|
-
n=10
|
19
|
-
gsl=Statsample::Combination.new(k,n,false)
|
20
|
-
gsl_array=[]
|
21
|
-
gsl.each{|y|
|
22
|
-
gsl_array.push(y)
|
23
|
-
}
|
24
|
-
rb=Statsample::Combination.new(k,n,true)
|
25
|
-
rb_array=[]
|
26
|
-
rb.each{|y|
|
27
|
-
rb_array.push(y)
|
28
|
-
}
|
29
|
-
assert(gsl.d.is_a?(Statsample::Combination::CombinationGsl))
|
30
|
-
assert(rb.d.is_a?(Statsample::Combination::CombinationRuby))
|
31
|
-
|
32
|
-
assert_equal(rb_array,gsl_array)
|
33
|
-
else
|
34
|
-
skip "Not CombinationRuby vs CombinationGSL (no gsl)"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/test/test_permutation.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require(File.dirname(__FILE__)+'/helpers_tests.rb')
|
2
|
-
|
3
|
-
|
4
|
-
class StatsamplePermutationTestCase < MiniTest::Unit::TestCase
|
5
|
-
context Statsample::Permutation do
|
6
|
-
should "initialize with number" do
|
7
|
-
per1=Statsample::Permutation.new(2)
|
8
|
-
exp1=[[0,1],[1,0]]
|
9
|
-
assert_equal(exp1,per1.permutations)
|
10
|
-
per2=Statsample::Permutation.new(3)
|
11
|
-
exp2=[[0,1,2],[0,2,1],[1,0,2],[1,2,0],[2,0,1],[2,1,0]]
|
12
|
-
assert_equal(exp2,per2.permutations)
|
13
|
-
end
|
14
|
-
should "initialize with simple array" do
|
15
|
-
per1=Statsample::Permutation.new(%w{a b})
|
16
|
-
exp1=[['a','b'],['b','a']]
|
17
|
-
assert_equal(exp1,per1.permutations)
|
18
|
-
per2=Statsample::Permutation.new(%w{a b c})
|
19
|
-
exp2=[%w{a b c},%w{a c b},%w{b a c} ,%w{b c a},%w{c a b},%w{c b a}]
|
20
|
-
assert_equal(exp2,per2.permutations)
|
21
|
-
end
|
22
|
-
should "initialize with Statsample::Vector" do
|
23
|
-
per2=Statsample::Permutation.new(%w{a b c}.to_vector)
|
24
|
-
exp2=[%w{a b c},%w{a c b},%w{b a c} ,%w{b c a},%w{c a b},%w{c b a}]
|
25
|
-
assert_equal(exp2, per2.permutations)
|
26
|
-
end
|
27
|
-
|
28
|
-
should "calculate correct number of total permutations without repetitions" do
|
29
|
-
per1=Statsample::Permutation.new(4)
|
30
|
-
assert_equal(24,per1.permutation_number)
|
31
|
-
end
|
32
|
-
should "calculate correct number of total permutations with repetitions" do
|
33
|
-
per2=Statsample::Permutation.new([1,1,1,0,0,0])
|
34
|
-
assert_equal(20,per2.permutation_number)
|
35
|
-
end
|
36
|
-
should "initialize with array repeated" do
|
37
|
-
per1=Statsample::Permutation.new([0,0,1,1])
|
38
|
-
exp1=[[0,0,1,1],[0,1,0,1],[0,1,1,0],[1,0,0,1],[1,0,1,0],[1,1,0,0]]
|
39
|
-
assert_equal(exp1,per1.permutations)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|