Module: Statsample::Test

Extended by:
Test
Included in:
Bivariate::Pearson, Test, BartlettSphericity, F, KolmogorovSmirnov, Levene, T, T::OneSample, T::TwoSamplesIndependent, WilcoxonSignedRank
Defined in:
lib/statsample/test.rb,
lib/statsample/test/f.rb,
lib/statsample/test/t.rb,
lib/statsample/test/levene.rb,
lib/statsample/test/chisquare.rb,
lib/statsample/test/umannwhitney.rb,
lib/statsample/test/kolmogorovsmirnov.rb,
lib/statsample/test/bartlettsphericity.rb,
lib/statsample/test/wilcoxonsignedrank.rb

Overview

Module for several statistical tests

Defined Under Namespace

Modules: ChiSquare Classes: BartlettSphericity, F, KolmogorovSmirnov, Levene, T, UMannWhitney, WilcoxonSignedRank

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.chi_square(observed, expected = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/statsample/test.rb', line 47

def chi_square(observed, expected=nil)
  case observed
    when Vector
      ChiSquare::WithVector.new(observed,expected)
    when Matrix
      ChiSquare::WithMatrix.new(observed,expected)
    else
      raise "Not implemented for #{observed.class}"
  end
end

.levene(input, opts = Hash.new) ⇒ Object

Shorthand for Statsample::Test::Levene.new



76
77
78
# File 'lib/statsample/test.rb', line 76

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



64
65
66
# File 'lib/statsample/test.rb', line 64

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



68
69
70
# File 'lib/statsample/test.rb', line 68

def t_two_samples_independent(v1,v2, opts=Hash.new)
  Statsample::Test::T::TwoSamplesIndependent.new(v1,v2,opts)
end

.u_mannwhitney(v1, v2) ⇒ Object

Shorthand for Statsample::Test::UMannWhitney.new

  • v1 and v2 should be Statsample::Vector.



60
61
62
# File 'lib/statsample/test.rb', line 60

def u_mannwhitney(v1, v2)
  Statsample::Test::UMannWhitney.new(v1,v2)
end

.wilcoxon_signed_rank(v1, v2, opts = Hash.new) ⇒ Object

Shorthand for Statsample::Test::WilcoxonSignedRank.new



72
73
74
# File 'lib/statsample/test.rb', line 72

def wilcoxon_signed_rank(v1,v2,opts=Hash.new)
		Statsample::Test::WilcoxonSignedRank.new(v1,v2,opts)
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.

  • :left : For one tail left, return the cdf

  • :right : For one tail right, return 1-cdf

  • :both : For both tails, returns 2*right_tail(cdf.abs)



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/statsample/test.rb', line 21

def p_using_cdf(cdf, tails=:both)
  tails=:both if tails==2 or tails==:two
  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

#t_critical(confidence_level, df) ⇒ Object

Get critical t to create confidence interval



36
37
38
# File 'lib/statsample/test.rb', line 36

def t_critical(confidence_level, df)
  -Distribution::T.p_value((1-confidence_level) / 2.0, df)
end

#z_critical(confidence_level) ⇒ Object

Get critical z to create confidence interval



40
41
42
# File 'lib/statsample/test.rb', line 40

def z_critical(confidence_level)
  -Distribution::Z.p_value((1-confidence_level) / 2.0)
end