Class: Statsample::Test::T::OneSample
- Inherits:
-
Object
- Object
- Statsample::Test::T::OneSample
- Includes:
- DirtyMemoize, Math, Statsample::Test
- Defined in:
- lib/statsample/test/t.rb
Overview
One Sample t-test
Usage
a=1000.times.map {rand(100)}.to_scale
t_1=Statsample::Test::T::OneSample.new(a, {:u=>50})
t_1.summary
Instance Attribute Summary collapse
-
#df ⇒ Object
readonly
Degress of freedom.
-
#name ⇒ Object
Name of test.
-
#opts ⇒ Object
Options.
-
#probability ⇒ Object
readonly
Probability.
-
#t ⇒ Object
readonly
Value of t.
-
#tails ⇒ Object
Tails for probability (:both, :left or :right).
-
#u ⇒ Object
Population mean to contrast.
Instance Method Summary collapse
-
#compute ⇒ Object
Set t and probability for given u.
-
#initialize(vector, opts = Hash.new) ⇒ OneSample
constructor
A new instance of OneSample.
-
#report_building(b) ⇒ Object
:nodoc:.
-
#summary ⇒ Object
Presents summary of analysis.
Methods included from Statsample::Test
chi_square, levene, #p_using_cdf, t_one_sample, t_two_samples_independent, u_mannwhitney
Constructor Details
#initialize(vector, opts = Hash.new) ⇒ OneSample
Returns a new instance of OneSample.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/statsample/test/t.rb', line 80 def initialize(vector, opts=Hash.new) @vector=vector default={:u=>0, :name=>"One Sample T Test", :tails=>:both} @opts=default.merge(opts) @name=@opts[:name] @u=@opts[:u] @tails=@opts[:tails] @df= @vector.n_valid-1 @t=nil end |
Instance Attribute Details
#df ⇒ Object (readonly)
Degress of freedom
69 70 71 |
# File 'lib/statsample/test/t.rb', line 69 def df @df end |
#name ⇒ Object
Name of test
65 66 67 |
# File 'lib/statsample/test/t.rb', line 65 def name @name end |
#opts ⇒ Object
Options
63 64 65 |
# File 'lib/statsample/test/t.rb', line 63 def opts @opts end |
#probability ⇒ Object (readonly)
Probability
73 74 75 |
# File 'lib/statsample/test/t.rb', line 73 def probability @probability end |
#t ⇒ Object (readonly)
Value of t
71 72 73 |
# File 'lib/statsample/test/t.rb', line 71 def t @t end |
#tails ⇒ Object
Tails for probability (:both, :left or :right)
75 76 77 |
# File 'lib/statsample/test/t.rb', line 75 def tails @tails end |
#u ⇒ Object
Population mean to contrast
67 68 69 |
# File 'lib/statsample/test/t.rb', line 67 def u @u end |
Instance Method Details
#compute ⇒ Object
Set t and probability for given u
93 94 95 96 |
# File 'lib/statsample/test/t.rb', line 93 def compute @t = T.one_sample(@vector.mean, @u, @vector.sd, @vector.n_valid) @probability = p_using_cdf(Distribution::T.cdf(@t, @df), tails) end |
#report_building(b) ⇒ Object
:nodoc:
102 103 104 105 106 107 108 109 |
# File 'lib/statsample/test/t.rb', line 102 def report_building(b) # :nodoc: b.section(:name=>@name) {|s| s.text "Sample mean: #{@vector.mean}" s.text "Population mean:#{u}" s.text "Tails: #{tails}" s.text sprintf("t = %0.4f, p=%0.4f, d.f=%d", t, probability, df) } end |
#summary ⇒ Object
Presents summary of analysis
99 100 101 |
# File 'lib/statsample/test/t.rb', line 99 def summary ReportBuilder.new(:no_title=>true).add(self).to_text end |