statsample 0.3.4 → 0.4.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/History.txt +8 -0
- data/Manifest.txt +20 -2
- data/data/crime.txt +47 -0
- data/data/test_binomial.csv +201 -0
- data/demo/distribution_t.rb +2 -2
- data/demo/regression.rb +2 -1
- data/lib/distribution.rb +8 -0
- data/lib/distribution/chisquare.rb +24 -0
- data/lib/distribution/f.rb +25 -0
- data/lib/distribution/normal.rb +25 -0
- data/lib/distribution/t.rb +22 -0
- data/lib/matrix_extension.rb +78 -0
- data/lib/statistics2.rb +531 -0
- data/lib/statsample.rb +12 -9
- data/lib/statsample/anova.rb +1 -5
- data/lib/statsample/bivariate.rb +24 -20
- data/lib/statsample/combination.rb +14 -4
- data/lib/statsample/converters.rb +17 -1
- data/lib/statsample/dataset.rb +66 -10
- data/lib/statsample/dominanceanalysis/bootstrap.rb +1 -3
- data/lib/statsample/graph/gdchart.rb +2 -3
- data/lib/statsample/graph/svggraph.rb +8 -4
- data/lib/statsample/mle.rb +137 -0
- data/lib/statsample/mle/logit.rb +95 -0
- data/lib/statsample/mle/normal.rb +83 -0
- data/lib/statsample/mle/probit.rb +93 -0
- data/lib/statsample/regression.rb +3 -1
- data/lib/statsample/regression/binomial.rb +65 -0
- data/lib/statsample/regression/binomial/logit.rb +13 -0
- data/lib/statsample/regression/binomial/probit.rb +13 -0
- data/lib/statsample/regression/multiple.rb +61 -58
- data/lib/statsample/regression/multiple/rubyengine.rb +1 -1
- data/lib/statsample/srs.rb +5 -5
- data/lib/statsample/vector.rb +129 -59
- data/test/test_anova.rb +0 -5
- data/test/test_dataset.rb +13 -1
- data/test/test_distribution.rb +57 -0
- data/test/test_gsl.rb +22 -0
- data/test/test_logit.rb +22 -0
- data/test/test_mle.rb +140 -0
- data/test/test_r.rb +9 -0
- data/test/test_regression.rb +12 -4
- data/test/test_srs.rb +0 -4
- data/test/test_stata.rb +11 -0
- data/test/test_statistics.rb +0 -15
- data/test/test_vector.rb +11 -0
- metadata +28 -4
- data/lib/statsample/chidistribution.rb +0 -39
- data/lib/statsample/regression/logit.rb +0 -35
data/test/test_anova.rb
CHANGED
@@ -21,12 +21,7 @@ class StatsampleAnovaTestCase < Test::Unit::TestCase
|
|
21
21
|
assert_in_delta(23.568,@anova.f,0.001)
|
22
22
|
anova2=Statsample::Anova::OneWay.new([@v1,@v1,@v1,@v1,@v2])
|
23
23
|
assert_in_delta(3.960, anova2.f,0.001)
|
24
|
-
|
25
|
-
if HAS_GSL
|
26
24
|
assert(@anova.significance<0.01)
|
27
25
|
assert_in_delta(0.016, anova2.significance,0.001)
|
28
|
-
else
|
29
|
-
puts "Skipped OneWay#significance (no GSL)"
|
30
|
-
end
|
31
26
|
end
|
32
27
|
end
|
data/test/test_dataset.rb
CHANGED
@@ -294,6 +294,18 @@ class StatsampleDatasetTestCase < Test::Unit::TestCase
|
|
294
294
|
assert_equal(exp1,res)
|
295
295
|
res=ds.verify('id',t1,t2,t3)
|
296
296
|
assert_equal(exp2,res)
|
297
|
-
|
297
|
+
end
|
298
|
+
def test_compute_operation
|
299
|
+
v1=[1,2,3,4].to_vector(:scale)
|
300
|
+
v2=[4,3,2,1].to_vector(:scale)
|
301
|
+
v3=[10,20,30,40].to_vector(:scale)
|
302
|
+
vscale=[1.quo(2),1,3.quo(2),2].to_vector(:scale)
|
303
|
+
vsum=[1+4+10.0,2+3+20.0,3+2+30.0,4+1+40.0].to_vector(:scale)
|
304
|
+
vmult=[1*4,2*3,3*2,4*1].to_vector(:scale)
|
305
|
+
ds={'v1'=>v1,'v2'=>v2,'v3'=>v3}.to_dataset
|
306
|
+
assert_equal(vscale,ds.compute("v1/2"))
|
307
|
+
assert_equal(vsum,ds.compute("v1+v2+v3"))
|
308
|
+
assert_equal(vmult,ds.compute("v1*v2"))
|
309
|
+
|
298
310
|
end
|
299
311
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)+'/../lib/')
|
2
|
+
require 'distribution'
|
3
|
+
require 'test/unit'
|
4
|
+
begin
|
5
|
+
require 'rbgsl'
|
6
|
+
NOT_GSL=false
|
7
|
+
rescue
|
8
|
+
NOT_GSL=true
|
9
|
+
end
|
10
|
+
class DistributionTestCase < Test::Unit::TestCase
|
11
|
+
def test_chi
|
12
|
+
if !NOT_GSL
|
13
|
+
[2,3,4,5].each{|k|
|
14
|
+
chis=rand()*10
|
15
|
+
area=Distribution::ChiSquare.cdf(chis, k)
|
16
|
+
assert_in_delta(area, GSL::Cdf.chisq_P(chis,k),0.0001)
|
17
|
+
assert_in_delta(chis, Distribution::ChiSquare.p_value(area,k),0.0001,"Error on prob #{area} and k #{k}")
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
def test_t
|
22
|
+
if !NOT_GSL
|
23
|
+
[-2,0.1,0.5,1,2].each{|t|
|
24
|
+
[2,5,10].each{|n|
|
25
|
+
area=Distribution::T.cdf(t,n)
|
26
|
+
assert_in_delta(area, GSL::Cdf.tdist_P(t,n),0.0001)
|
27
|
+
assert_in_delta(Distribution::T.p_value(area,n), GSL::Cdf.tdist_Pinv(area,n),0.0001)
|
28
|
+
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
def test_normal
|
34
|
+
if !NOT_GSL
|
35
|
+
[-2,0.1,0.5,1,2].each{|x|
|
36
|
+
area=Distribution::Normal.cdf(x)
|
37
|
+
assert_in_delta(area, GSL::Cdf.ugaussian_P(x),0.0001)
|
38
|
+
assert_in_delta(Distribution::Normal.p_value(area), GSL::Cdf.ugaussian_Pinv(area),0.0001)
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
def test_f
|
43
|
+
if !NOT_GSL
|
44
|
+
[0.1,0.5,1,2,10,20,30].each{|f|
|
45
|
+
[2,5,10].each{|n2|
|
46
|
+
[2,5,10].each{|n1|
|
47
|
+
area=Distribution::F.cdf(f,n1,n2)
|
48
|
+
assert_in_delta(area, GSL::Cdf.fdist_P(f,n1,n2),0.0001)
|
49
|
+
assert_in_delta(Distribution::F.p_value(area,n1,n2), GSL::Cdf.fdist_Pinv(area,n1,n2),0.0001)
|
50
|
+
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/test/test_gsl.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)+'/../lib/')
|
2
|
+
require 'statsample'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'matrix_extension'
|
5
|
+
class StatsampleGSLTestCase < Test::Unit::TestCase
|
6
|
+
def test_matrix_to_gsl
|
7
|
+
if HAS_GSL
|
8
|
+
a=[1,2,3,4,20].to_vector(:scale)
|
9
|
+
b=[3,2,3,4,50].to_vector(:scale)
|
10
|
+
c=[6,2,3,4,3].to_vector(:scale)
|
11
|
+
ds={'a'=>a,'b'=>b,'c'=>c}.to_dataset
|
12
|
+
gsl=ds.to_matrix.to_gsl
|
13
|
+
assert_equal(5,gsl.size1)
|
14
|
+
assert_equal(3,gsl.size2)
|
15
|
+
matrix=gsl.to_matrix
|
16
|
+
assert_equal(5,matrix.row_size)
|
17
|
+
assert_equal(3,matrix.column_size)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
data/test/test_logit.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)+'/../lib/')
|
2
|
+
require 'statsample'
|
3
|
+
require 'test/unit'
|
4
|
+
class StatsampleLogitTestCase < Test::Unit::TestCase
|
5
|
+
def test_logit_1
|
6
|
+
crime=File.dirname(__FILE__)+'/../data/test_binomial.csv'
|
7
|
+
ds=Statsample::CSV.read(crime)
|
8
|
+
lr=Statsample::Regression::Binomial::Logit.new(ds,'y')
|
9
|
+
assert_in_delta(-38.8669,lr.log_likehood,0.001)
|
10
|
+
assert_in_delta(-5.3658,lr.constant,0.001)
|
11
|
+
|
12
|
+
exp_coeffs={"a"=>0.3270,"b"=>0.8147, "c"=>-0.4031}
|
13
|
+
exp_coeffs.each{|k,v|
|
14
|
+
assert_in_delta(v,lr.coeffs[k],0.001)
|
15
|
+
}
|
16
|
+
exp_errors={'a'=>0.4390,'b'=>0.4270,'c'=>0.3819}
|
17
|
+
exp_errors.each{|k,v|
|
18
|
+
assert_in_delta(v,lr.coeffs_se[k],0.001)
|
19
|
+
}
|
20
|
+
assert_equal(7,lr.iterations)
|
21
|
+
end
|
22
|
+
end
|
data/test/test_mle.rb
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)+'/../lib/')
|
2
|
+
require 'statsample'
|
3
|
+
require 'test/unit'
|
4
|
+
class StatsampleMLETestCase < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@file_binomial=File.dirname(__FILE__)+'/../data/test_binomial.csv'
|
7
|
+
@crime=File.dirname(__FILE__)+'/../data/crime.txt'
|
8
|
+
@cases=100
|
9
|
+
a=Array.new()
|
10
|
+
b=Array.new()
|
11
|
+
c=Array.new()
|
12
|
+
y=Array.new()
|
13
|
+
|
14
|
+
@cases.times{|i|
|
15
|
+
a.push(2*rand()-i)
|
16
|
+
b.push(2*rand()-5+i)
|
17
|
+
c.push(2*rand()+i)
|
18
|
+
y_val=i+(rand()*@cases.quo(2) - @cases.quo(4))
|
19
|
+
y.push(y_val<(@cases/2.0) ? 0.0 : 1.0)
|
20
|
+
}
|
21
|
+
a=a.to_vector(:scale)
|
22
|
+
b=b.to_vector(:scale)
|
23
|
+
c=c.to_vector(:scale)
|
24
|
+
y=y.to_vector(:scale)
|
25
|
+
|
26
|
+
@ds_indep={'a'=>a,'b'=>b,'c'=>c}.to_dataset
|
27
|
+
constant=([1.0]*@cases).to_vector(:scale)
|
28
|
+
@ds_indep_2={'constant'=>constant,'a'=>a,'b'=>b,'c'=>c}.to_dataset
|
29
|
+
@ds_indep_2.fields=%w{constant a b c}
|
30
|
+
@mat_x=@ds_indep_2.to_matrix
|
31
|
+
@mat_y=y.to_matrix(:vertical)
|
32
|
+
@ds=@ds_indep.dup
|
33
|
+
@ds.add_vector('y',y)
|
34
|
+
end
|
35
|
+
def test_normal
|
36
|
+
y=Array.new()
|
37
|
+
y=@ds_indep.collect{|row|
|
38
|
+
row['a']*5+row['b']+row['c']+rand()*3
|
39
|
+
}
|
40
|
+
constant=([1]*@cases).to_vector(:scale)
|
41
|
+
ds_indep_2=@ds_indep.dup
|
42
|
+
ds_indep_2['constant']=constant
|
43
|
+
ds_indep_2.fields=%w{constant a b c}
|
44
|
+
mat_x=ds_indep_2.to_matrix
|
45
|
+
mat_y=y.to_matrix(:vertical)
|
46
|
+
mle=Statsample::MLE::Normal.new()
|
47
|
+
mle.verbose=false
|
48
|
+
coeffs_nr=mle.newton_raphson(mat_x,mat_y)
|
49
|
+
#p coeffs_nr
|
50
|
+
ds=@ds_indep.dup
|
51
|
+
ds.add_vector('y',y)
|
52
|
+
lr=Statsample::Regression::Multiple.listwise(ds,'y')
|
53
|
+
lr_constant = lr.constant
|
54
|
+
lr_coeffs = lr.coeffs
|
55
|
+
assert_in_delta(coeffs_nr[0,0], lr_constant,0.0000001)
|
56
|
+
assert_in_delta(coeffs_nr[1,0], lr_coeffs["a"],0.0000001)
|
57
|
+
assert_in_delta(coeffs_nr[2,0], lr_coeffs["b"],0.0000001)
|
58
|
+
assert_in_delta(coeffs_nr[3,0], lr_coeffs["c"],0.0000001)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_probit
|
62
|
+
ds=Statsample::CSV.read(@file_binomial)
|
63
|
+
constant=([1.0]*ds.cases).to_vector(:scale)
|
64
|
+
ds_indep={'constant'=>constant, 'a'=>ds['a'],'b'=>ds['b'], 'c'=>ds['c']}.to_dataset(%w{constant a b c})
|
65
|
+
mat_x=ds_indep.to_matrix
|
66
|
+
mat_y=ds['y'].to_matrix(:vertical)
|
67
|
+
mle=Statsample::MLE::Probit.new
|
68
|
+
b_probit=mle.newton_raphson(mat_x,mat_y)
|
69
|
+
ll=mle.log_likehood(mat_x,mat_y,b_probit)
|
70
|
+
|
71
|
+
b_exp=[-3.0670,0.1763,0.4483,-0.2240]
|
72
|
+
b_exp.each_index{|i|
|
73
|
+
assert_in_delta(b_exp[i], b_probit[i,0], 0.001)
|
74
|
+
}
|
75
|
+
assert_in_delta(-38.31559,ll,0.0001)
|
76
|
+
end
|
77
|
+
def test_logit_crime
|
78
|
+
ds=Statsample::PlainText.read(@crime, %w{crimerat maleteen south educ police60 police59 labor males pop nonwhite unemp1 unemp2 median belowmed})
|
79
|
+
constant=([1.0]*ds.cases).to_vector(:scale)
|
80
|
+
ds2=ds.dup(%w{maleteen south educ police59})
|
81
|
+
ds2['constant']=constant
|
82
|
+
ds2.fields=%w{constant maleteen south educ police59}
|
83
|
+
mat_x=ds2.to_matrix
|
84
|
+
mat_y=(ds.compute "(crimerat>=110) ? 1:0").to_matrix(:vertical)
|
85
|
+
mle=Statsample::MLE::Logit.new
|
86
|
+
b=mle.newton_raphson(mat_x,mat_y)
|
87
|
+
ll=mle.log_likehood(mat_x,mat_y,b)
|
88
|
+
assert_in_delta(-18.606959,ll,0.001)
|
89
|
+
exp=[-17.701, 0.0833,-1.117, 0.0229, 0.0581]
|
90
|
+
exp.each_index{|i|
|
91
|
+
assert_in_delta(exp[i],b[i,0],0.001)
|
92
|
+
}
|
93
|
+
assert_equal(5,mle.iterations)
|
94
|
+
end
|
95
|
+
def atest_logit_alglib
|
96
|
+
if(HAS_ALGIB)
|
97
|
+
ds=Statsample::CSV.read(@file_binomial)
|
98
|
+
constant=([1.0]*ds.cases).to_vector(:scale)
|
99
|
+
|
100
|
+
ds_indep={'constant'=>constant, 'a'=>ds['a'],'b'=>ds['b'], 'c'=>ds['c']}.to_dataset(%w{constant a b c} )
|
101
|
+
|
102
|
+
mat_x=ds_indep.to_matrix
|
103
|
+
mat_y=ds['y'].to_matrix(:vertical)
|
104
|
+
log=Alglib::Logit.build_from_matrix(ds.to_matrix)
|
105
|
+
coeffs=log.unpack[0]
|
106
|
+
b_alglib=Matrix.columns([[-coeffs[3], -coeffs[0], -coeffs[1], -coeffs[2]]])
|
107
|
+
mle=Statsample::MLE::Logit.new
|
108
|
+
ll_alglib=mle.log_likehood(mat_x,mat_y,b_alglib)
|
109
|
+
b_newton=mle.newton_raphson(mat_x,mat_y)
|
110
|
+
ll_pure_ruby=mle.log_likehood(mat_x,mat_y,b_newton)
|
111
|
+
#p b_alglib
|
112
|
+
#p b_newton
|
113
|
+
|
114
|
+
assert_in_delta(ll_alglib,ll_pure_ruby,1)
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
def atest_logit1
|
119
|
+
log=Alglib::Logit.build_from_matrix(@ds.to_matrix)
|
120
|
+
coeffs=log.unpack[0]
|
121
|
+
b=Matrix.columns([[-coeffs[3],-coeffs[0],-coeffs[1],-coeffs[2]]])
|
122
|
+
# puts "Coeficientes beta alglib:"
|
123
|
+
#p b
|
124
|
+
mle_alglib=Statsample::MLE::ln_mle(Statsample::MLE::Logit, @mat_x,@mat_y,b)
|
125
|
+
# puts "MLE Alglib:"
|
126
|
+
#p mle_alglib
|
127
|
+
# Statsample::CSV.write(ds,"test_binomial.csv")
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
# puts "iniciando newton"
|
132
|
+
coeffs_nr=Statsample::MLE.newton_raphson(@mat_x,@mat_y, Statsample::MLE::Logit)
|
133
|
+
#p coeffs_nr
|
134
|
+
mle_pure_ruby=Statsample::MLE::ln_mle(Statsample::MLE::Logit, @mat_x,@mat_y,coeffs_nr)
|
135
|
+
#p mle_pure_ruby
|
136
|
+
|
137
|
+
#puts "Malo: #{mle_malo} Bueno: #{mle_bueno} : #{mle_malo-mle_bueno}"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
data/test/test_r.rb
ADDED
data/test/test_regression.rb
CHANGED
@@ -95,11 +95,7 @@ class StatsampleRegressionTestCase < Test::Unit::TestCase
|
|
95
95
|
assert_in_delta(0.955,lr.r,0.001)
|
96
96
|
assert_in_delta(0.913,lr.r2,0.001)
|
97
97
|
assert_in_delta(20.908, lr.f,0.001)
|
98
|
-
if HAS_GSL
|
99
98
|
assert_in_delta(0.001, lr.significance, 0.001)
|
100
|
-
else
|
101
|
-
puts "#{lr.class}#significance not tested (not GSL)"
|
102
|
-
end
|
103
99
|
assert_in_delta(0.226,lr.tolerance("a"),0.001)
|
104
100
|
coeffs_se={"a"=>1.171,"b"=>1.129,"c"=>0.072}
|
105
101
|
ccoeffs_se=lr.coeffs_se
|
@@ -133,4 +129,16 @@ class StatsampleRegressionTestCase < Test::Unit::TestCase
|
|
133
129
|
assert_in_delta(residuals[i],c_residuals[i],0.001)
|
134
130
|
}
|
135
131
|
end
|
132
|
+
def test_ds_by_exp
|
133
|
+
@a= [1,3,2,4,3,5,4,6,5,7].to_vector(:scale)
|
134
|
+
@b= [3,3,4,4,5,5,6,6,4,4].to_vector(:scale)
|
135
|
+
@c= [11,22,30,40,50,65,78,79,99,100].to_vector(:scale)
|
136
|
+
@d=%w{a b c a a c a a c a}.to_vector(:nominal)
|
137
|
+
@y=[3,4,5,6,7,8,9,10,20,30].to_vector(:scale)
|
138
|
+
ds={'a'=>@a,'b'=>@b,'c'=>@c,'d'=>@d,'y'=>@y}.to_dataset
|
139
|
+
#puts Statsample::Regression::Multiple.ds_by_exp(ds,"a+b=y")
|
140
|
+
#puts Statsample::Regression::Multiple.ds_by_exp(ds,"a+b*d=y")
|
141
|
+
#puts Statsample::Regression::Multiple.ds_by_exp(ds,"c+d=y")
|
142
|
+
end
|
143
|
+
|
136
144
|
end
|
data/test/test_srs.rb
CHANGED
@@ -4,12 +4,8 @@ require 'test/unit'
|
|
4
4
|
|
5
5
|
class StatsampleSrsTestCase < Test::Unit::TestCase
|
6
6
|
def test_std_error
|
7
|
-
if HAS_GSL
|
8
7
|
assert_equal(384,Statsample::SRS.estimation_n0(0.05,0.5,0.95).to_i)
|
9
8
|
assert_equal(108,Statsample::SRS.estimation_n(0.05,0.5,150,0.95).to_i)
|
10
|
-
else
|
11
|
-
puts "Statsample::SRS.estimation_n0 not tested (needs ruby-gsl)"
|
12
|
-
end
|
13
9
|
assert_in_delta(0.0289,Statsample::SRS.proportion_sd_kp_wor(0.5,100,150),0.001)
|
14
10
|
end
|
15
11
|
end
|
data/test/test_stata.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)+'/../lib/')
|
2
|
+
#require 'stata'
|
3
|
+
require 'statsample'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class StatsampleStataTestCase < Test::Unit::TestCase
|
7
|
+
def test_basic
|
8
|
+
#datafile=File.dirname(__FILE__)+"/../data/logit.dta"
|
9
|
+
#p Stata.open(datafile)
|
10
|
+
end
|
11
|
+
end
|
data/test/test_statistics.rb
CHANGED
@@ -64,7 +64,6 @@ class StatsampleStatisicsTestCase < Test::Unit::TestCase
|
|
64
64
|
#assert_equal(expected,obt)
|
65
65
|
end
|
66
66
|
def test_prop_pearson
|
67
|
-
if HAS_GSL
|
68
67
|
assert_in_delta(0.42, Statsample::Bivariate.prop_pearson(Statsample::Bivariate.t_r(0.084,94), 94),0.01)
|
69
68
|
assert_in_delta(0.65, Statsample::Bivariate.prop_pearson(Statsample::Bivariate.t_r(0.046,95), 95),0.01)
|
70
69
|
r=0.9
|
@@ -80,11 +79,6 @@ class StatsampleStatisicsTestCase < Test::Unit::TestCase
|
|
80
79
|
assert(Statsample::Bivariate.prop_pearson(t,n,:both)<0.05)
|
81
80
|
assert(Statsample::Bivariate.prop_pearson(t,n,:right)>0.05)
|
82
81
|
assert(Statsample::Bivariate.prop_pearson(t,n,:left)<0.05)
|
83
|
-
|
84
|
-
|
85
|
-
else
|
86
|
-
puts "Bivariate.prop_pearson not tested (no ruby-gsl)"
|
87
|
-
end
|
88
82
|
end
|
89
83
|
def test_covariance
|
90
84
|
if HAS_GSL
|
@@ -130,11 +124,7 @@ class StatsampleStatisicsTestCase < Test::Unit::TestCase
|
|
130
124
|
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)
|
131
125
|
assert_equal(50,v.size)
|
132
126
|
assert_equal(1471,v.sum())
|
133
|
-
if HAS_GSL
|
134
127
|
limits=Statsample::SRS.mean_confidence_interval_z(v.mean(), v.sds(), v.size,676,0.80)
|
135
|
-
else
|
136
|
-
puts "SRS.mean_confidence_interval_z not tested (no ruby-gsl)"
|
137
|
-
end
|
138
128
|
end
|
139
129
|
def test_estimation_proportion
|
140
130
|
# total
|
@@ -148,14 +138,9 @@ class StatsampleStatisicsTestCase < Test::Unit::TestCase
|
|
148
138
|
sam=100
|
149
139
|
prop=0.37
|
150
140
|
a=0.95
|
151
|
-
if HAS_GSL
|
152
141
|
l= Statsample::SRS.proportion_confidence_interval_z(prop, sam, pop, a)
|
153
142
|
assert_in_delta(0.28,l[0],0.01)
|
154
143
|
assert_in_delta(0.46,l[1],0.01)
|
155
|
-
else
|
156
|
-
puts "SRS.proportion_confidence_interval_z not tested (no ruby-gsl)"
|
157
|
-
|
158
|
-
end
|
159
144
|
end
|
160
145
|
def test_ml
|
161
146
|
if(true)
|
data/test/test_vector.rb
CHANGED
@@ -16,6 +16,17 @@ class StatsampleVectorTestCase < Test::Unit::TestCase
|
|
16
16
|
def test_product
|
17
17
|
a=[1,2,3,4,5].to_vector(:scale)
|
18
18
|
assert_equal(120,a.product)
|
19
|
+
end
|
20
|
+
def test_matrix
|
21
|
+
a=[1,2,3,4,5].to_vector(:scale)
|
22
|
+
mh=Matrix[[1,2,3,4,5]]
|
23
|
+
mv=Matrix.columns([[1,2,3,4,5]])
|
24
|
+
assert_equal(mh,a.to_matrix)
|
25
|
+
assert_equal(mv,a.to_matrix(:vertical))
|
26
|
+
# 3*4 + 2*5 = 22
|
27
|
+
a=[3,2].to_vector(:scale)
|
28
|
+
b=[4,5].to_vector(:scale)
|
29
|
+
assert_equal(22,(a.to_matrix*b.to_matrix(:vertical))[0,0])
|
19
30
|
end
|
20
31
|
def test_missing_values
|
21
32
|
@c.missing_values=[10]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsample
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claudio Bustos
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-10 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -60,7 +60,9 @@ files:
|
|
60
60
|
- Manifest.txt
|
61
61
|
- README.txt
|
62
62
|
- bin/statsample
|
63
|
+
- data/crime.txt
|
63
64
|
- data/locale/es/LC_MESSAGES/statsample.mo
|
65
|
+
- data/test_binomial.csv
|
64
66
|
- demo/benchmark.rb
|
65
67
|
- demo/chi-square.rb
|
66
68
|
- demo/crosstab.rb
|
@@ -76,11 +78,17 @@ files:
|
|
76
78
|
- demo/strata_proportion.rb
|
77
79
|
- demo/stratum.rb
|
78
80
|
- demo/t-student.rb
|
81
|
+
- lib/distribution.rb
|
82
|
+
- lib/distribution/chisquare.rb
|
83
|
+
- lib/distribution/f.rb
|
84
|
+
- lib/distribution/normal.rb
|
85
|
+
- lib/distribution/t.rb
|
86
|
+
- lib/matrix_extension.rb
|
79
87
|
- lib/spss.rb
|
88
|
+
- lib/statistics2.rb
|
80
89
|
- lib/statsample.rb
|
81
90
|
- lib/statsample/anova.rb
|
82
91
|
- lib/statsample/bivariate.rb
|
83
|
-
- lib/statsample/chidistribution.rb
|
84
92
|
- lib/statsample/codification.rb
|
85
93
|
- lib/statsample/combination.rb
|
86
94
|
- lib/statsample/converters.rb
|
@@ -94,9 +102,15 @@ files:
|
|
94
102
|
- lib/statsample/graph/svghistogram.rb
|
95
103
|
- lib/statsample/graph/svgscatterplot.rb
|
96
104
|
- lib/statsample/htmlreport.rb
|
105
|
+
- lib/statsample/mle.rb
|
106
|
+
- lib/statsample/mle/logit.rb
|
107
|
+
- lib/statsample/mle/normal.rb
|
108
|
+
- lib/statsample/mle/probit.rb
|
97
109
|
- lib/statsample/multiset.rb
|
98
110
|
- lib/statsample/regression.rb
|
99
|
-
- lib/statsample/regression/
|
111
|
+
- lib/statsample/regression/binomial.rb
|
112
|
+
- lib/statsample/regression/binomial/logit.rb
|
113
|
+
- lib/statsample/regression/binomial/probit.rb
|
100
114
|
- lib/statsample/regression/multiple.rb
|
101
115
|
- lib/statsample/regression/multiple/alglibengine.rb
|
102
116
|
- lib/statsample/regression/multiple/gslengine.rb
|
@@ -118,7 +132,11 @@ files:
|
|
118
132
|
- test/test_csv.csv
|
119
133
|
- test/test_csv.rb
|
120
134
|
- test/test_dataset.rb
|
135
|
+
- test/test_distribution.rb
|
121
136
|
- test/test_ggobi.rb
|
137
|
+
- test/test_gsl.rb
|
138
|
+
- test/test_logit.rb
|
139
|
+
- test/test_mle.rb
|
122
140
|
- test/test_multiset.rb
|
123
141
|
- test/test_regression.rb
|
124
142
|
- test/test_reliability.rb
|
@@ -163,17 +181,23 @@ test_files:
|
|
163
181
|
- test/test_anova.rb
|
164
182
|
- test/test_codification.rb
|
165
183
|
- test/test_crosstab.rb
|
184
|
+
- test/test_distribution.rb
|
166
185
|
- test/test_svg_graph.rb
|
167
186
|
- test/test_csv.rb
|
187
|
+
- test/test_gsl.rb
|
168
188
|
- test/test_combination.rb
|
189
|
+
- test/test_mle.rb
|
169
190
|
- test/test_resample.rb
|
170
191
|
- test/test_stratified.rb
|
171
192
|
- test/test_vector.rb
|
172
193
|
- test/test_srs.rb
|
194
|
+
- test/test_stata.rb
|
173
195
|
- test/test_ggobi.rb
|
174
196
|
- test/test_xls.rb
|
197
|
+
- test/test_logit.rb
|
175
198
|
- test/test_statistics.rb
|
176
199
|
- test/test_reliability.rb
|
177
200
|
- test/test_dataset.rb
|
201
|
+
- test/test_r.rb
|
178
202
|
- test/test_regression.rb
|
179
203
|
- test/test_multiset.rb
|