class Statsample::Test::T
A t-test is any statistical hypothesis test in which the test statistic follows a Student's t distribution, if the null hypothesis is supported
A t-test is any statistical hypothesis test in which the test statistic follows a Student's t distribution, if the null hypothesis is supported
Attributes
Name of F analysis
Tails for p-value (:both, :left or :right). Default :both
Public Class Methods
Creates a generic t test. Use OneSample or TwoSamplesIndependent classes for better summaries. Parameters:
-
estimate: estimate
-
#standard_error: standard error of estimate
-
df: degrees of freedom
# File lib/statsample/test/t.rb, line 76 def initialize(estimate, standard_error, df, opts=Hash.new) @estimate=estimate @standard_error=standard_error @df=df @t = @estimate / @standard_error.to_f opts_default={ :tails=>:both, :name=>_("T Test"), :estimate_name=>_("Estimate"), :standard_error_name=>_("Std.Err.of Estimate"), :confidence_level=>0.95} @opts = opts_default.merge(opts) @opts.keys.each {|k| send("#{k}=", @opts[k]) if respond_to? k } end
Public Instance Methods
# File lib/statsample/test/t.rb, line 104 def confidence_interval(cl=nil) cl||=confidence_level t_crit = t_critical(cl, df) [estimate - se*t_crit, estimate + se*t_crit] end
Degrees of freedom for equal variance on t test
# File lib/statsample/test/t.rb, line 41 def df_equal_variance(n1,n2) n1+n2-2 end
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 51 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
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 18 def one_sample(x,u,s,n) (x-u)*Math::sqrt(n).quo(s) end
probability
# File lib/statsample/test/t.rb, line 100 def probability p_using_cdf(Distribution::T.cdf(t, df), tails) end
# File lib/statsample/test/t.rb, line 118 def report_building_t(s) df_f=@df.is_a?(Integer) ? "%d" : "%0.4f" s.text _("t(%d) = %0.4f, p=%0.4f (%s tails)") % [df, t,probability, tails] s.text _("CI(%d%%): %0.4f - %0.4f") % [confidence_level*100, ci[0],ci[1]] end
# File lib/statsample/test/t.rb, line 95 def to_f t end
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 30 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