module Statsample::Test

Module for several statistical tests

Module for several statistical tests

Public Instance Methods

chi_square(observed, expected=nil) click to toggle source
# 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) click to toggle source

Shorthand for Statsample::Test::Levene.new

# File lib/statsample/test.rb, line 76
def levene(input, opts=Hash.new)
  Statsample::Test::Levene.new(input,opts)
end
p_using_cdf(cdf, tails=:both) click to toggle source

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)

# 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) click to toggle source

Get critical t to create confidence interval

# File lib/statsample/test.rb, line 36
def t_critical(confidence_level, df)
  -Distribution::T.p_value((1-confidence_level) / 2.0, df)
end
t_one_sample(vector, opts=Hash.new) click to toggle source

Shorthand for Statsample::Test::T::OneSample.new

# 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) click to toggle source

Shorthand for Statsample::Test::T::TwoSamplesIndependent.new

# 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) click to toggle source

Shorthand for Statsample::Test::UMannWhitney.new

# 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) click to toggle source

Shorthand for Statsample::Test::WilcoxonSignedRank.new

# File lib/statsample/test.rb, line 72
def wilcoxon_signed_rank(v1,v2,opts=Hash.new)
      Statsample::Test::WilcoxonSignedRank.new(v1,v2,opts)
end
z_critical(confidence_level) click to toggle source

Get critical z to create confidence interval

# File lib/statsample/test.rb, line 40
def z_critical(confidence_level)
  -Distribution::Z.p_value((1-confidence_level) / 2.0)
end