Included Modules

Class/Module Index [+]

Quicksearch

Statsample::Test::T

Public Class Methods

df_equal_variance(n1,n2) click to toggle source

Degrees of freedom for equal variance on t test

# File lib/statsample/test/t.rb, line 35
def df_equal_variance(n1,n2)
  n1+n2-2
end
df_not_equal_variance(s1,s2,n1,n2) click to toggle source

Degrees of freedom for unequal variance

  • s1: sample 1 standard deviation

  • s2: sample 2 standard deviation

  • n1: sample 1 size

  • n2: sample 2 size

Reference

# File lib/statsample/test/t.rb, line 45
def df_not_equal_variance(s1,s2,n1,n2)
  s2_1=s1**2
  s2_2=s2**2
  num=(s2_1.quo(n1)+s2_2.quo(n2))**2
  den=(s2_1.quo(n1)**2).quo(n1-1) + (s2_2.quo(n2)**2).quo(n2-1)
  num.quo(den)
end
one_sample(x,u,s,n) click to toggle source

Test the null hypothesis that the population mean is equal to a specified value u, one uses the statistic. Is the same formula used on t-test for paired sample.

  • x: sample/differences mean

  • u: population mean

  • s: sample/differences standard deviation

  • n: sample size

# File lib/statsample/test/t.rb, line 12
def one_sample(x,u,s,n)
  (x-u).quo(s.quo(Math::sqrt(n)))
end
two_sample_independent(x1, x2, s1, s2, n1, n2, equal_variance = false) click to toggle source

Test if means of two samples are different.

  • x1: sample 1 mean

  • x2: sample 2 mean

  • s1: sample 1 standard deviation

  • s2: sample 2 standard deviation

  • n1: sample 1 size

  • n2: sample 2 size

  • equal_variance: true if equal_variance assumed

# File lib/statsample/test/t.rb, line 24
def two_sample_independent(x1, x2, s1, s2, n1, n2, equal_variance = false)
  num=x1-x2
  if equal_variance
    sx1x2 = sqrt(((n1-1)*s1**2 + (n2-1)*s2**2).quo(n1+n2-2))
    den   = sx1x2*sqrt(1.quo(n1)+1.quo(n2))
  else
    den=sqrt((s1**2).quo(n1) + (s2**2).quo(n2))
  end
  num.quo(den)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.