Module: Statsample::Test
- Extended by:
- Test
- Included in:
- Test, T::OneSample, T::TwoSamplesIndependent
- Defined in:
- lib/statsample/test.rb,
lib/statsample/test/t.rb,
lib/statsample/test/levene.rb,
lib/statsample/test/umannwhitney.rb
Overview
Module for several statistical tests
Defined Under Namespace
Modules: T Classes: Levene, UMannWhitney
Class Method Summary collapse
- .chi_square(real, expected) ⇒ Object
-
.levene(input, opts = Hash.new) ⇒ Object
Shorthand for Statsample::Test::Levene.new.
-
.t_one_sample(vector, opts = Hash.new) ⇒ Object
Shorthand for Statsample::Test::T::OneSample.new.
-
.t_two_samples_independent(v1, v2, opts = Hash.new) ⇒ Object
Shorthand for Statsample::Test::T::TwoSamplesIndependent.new.
- .u_mannwhitney(v1p, v2p) ⇒ Object
Instance Method Summary collapse
-
#p_using_cdf(cdf, tails = :both) ⇒ Object
Returns probability of getting a value lower or higher than sample, using cdf and number of tails.
Class Method Details
.chi_square(real, expected) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/statsample/test.rb', line 31 def chi_square(real,expected) sum=0 (0...real.row_size).each {|row_i| (0...real.column_size).each {|col_i| val=((real[row_i,col_i].to_f - expected[row_i,col_i].to_f)**2) / expected[row_i,col_i].to_f # puts "Real: #{real[row_i,col_i].to_f} ; esperado: #{expected[row_i,col_i].to_f}" # puts "Diferencial al cuadrado: #{(real[row_i,col_i].to_f - expected[row_i,col_i].to_f)**2}" sum+=val } } sum end |
.levene(input, opts = Hash.new) ⇒ Object
Shorthand for Statsample::Test::Levene.new
56 57 58 |
# File 'lib/statsample/test.rb', line 56 def levene(input, opts=Hash.new) Statsample::Test::Levene.new(input,opts) end |
.t_one_sample(vector, opts = Hash.new) ⇒ Object
Shorthand for Statsample::Test::T::OneSample.new
47 48 49 |
# File 'lib/statsample/test.rb', line 47 def t_one_sample(vector, opts=Hash.new) Statsample::Test::T::OneSample.new(vector,opts) end |
.t_two_samples_independent(v1, v2, opts = Hash.new) ⇒ Object
Shorthand for Statsample::Test::T::TwoSamplesIndependent.new
51 52 53 |
# File 'lib/statsample/test.rb', line 51 def t_two_samples_independent(v1,v2, opts=Hash.new) Statsample::Test::T::TwoSamplesIndependent.new(v1,v2,opts) end |
.u_mannwhitney(v1p, v2p) ⇒ Object
43 44 45 |
# File 'lib/statsample/test.rb', line 43 def u_mannwhitney(v1p,v2p) Statsample::Test::UMannWhitney.new(v1p,v2p) end |
Instance Method Details
#p_using_cdf(cdf, tails = :both) ⇒ Object
Returns probability of getting a value lower or higher than sample, using cdf and number of tails.
-
For one tail left, return the cdf
-
For one tail right, return 1-cdf
-
For two tails, returns 2*right_tail(cdf.abs)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/statsample/test.rb', line 14 def p_using_cdf(cdf, tails=:both) tails=:both if tails==2 tails=:right if tails==1 or tails==:positive tails=:left if tails==:negative case tails when :left then cdf when :right then 1-cdf when :both if cdf>=0.5 cdf=1-cdf end 2*cdf end end |