Class: Statsample::Test::T::OneSample

Inherits:
Object
  • Object
show all
Includes:
Math, Summarizable, Statsample::Test
Defined in:
lib/statsample/test/t.rb

Overview

One Sample t-test

Usage

a=1000.times.map {rand(100)}.to_numeric
t_1=Statsample::Test::T::OneSample.new(a, {:u=>50})
t_1.summary

Output

= One Sample T Test
Sample mean: 48.954
Population mean:50
Tails: both
t = -1.1573, p=0.2474, d.f=999

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Summarizable

#summary

Methods included from Statsample::Test

chi_square, levene, #p_using_cdf, #t_critical, t_one_sample, t_two_samples_independent, u_mannwhitney, wilcoxon_signed_rank, #z_critical

Constructor Details

#initialize(vector, opts = Hash.new) ⇒ OneSample

Create a One Sample T Test Options:

  • :u = Mean to compare. Default= 0

  • :name = Name of the analysis

  • :tails = Tail for probability. Could be :both, :left, :right



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/statsample/test/t.rb', line 160

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]
  @confidence_level=@opts[:confidence_level] || 0.95
  @df= @vector.n_valid-1
  @t=nil
end

Instance Attribute Details

#dfObject (readonly)

Degress of freedom



151
152
153
# File 'lib/statsample/test/t.rb', line 151

def df
  @df
end

#nameObject

Name of test



147
148
149
# File 'lib/statsample/test/t.rb', line 147

def name
  @name
end

#optsObject

Options



145
146
147
# File 'lib/statsample/test/t.rb', line 145

def opts
  @opts
end

#tailsObject

Tails for probability (:both, :left or :right)



153
154
155
# File 'lib/statsample/test/t.rb', line 153

def tails
  @tails
end

#uObject

Population mean to contrast



149
150
151
# File 'lib/statsample/test/t.rb', line 149

def u
  @u
end

Instance Method Details

#confidence_interval(cl = nil) ⇒ Object Also known as: ci



184
185
186
# File 'lib/statsample/test/t.rb', line 184

def confidence_interval(cl=nil)
  t_object.confidence_interval(cl)
end

#probabilityObject



177
178
179
# File 'lib/statsample/test/t.rb', line 177

def probability
  t_object.probability
end

#report_building(b) ⇒ Object

:nodoc:



188
189
190
191
192
193
194
# File 'lib/statsample/test/t.rb', line 188

def report_building(b) # :nodoc:
  b.section(:name=>@name) {|s|
    s.text _("Sample mean: %0.4f | Sample sd: %0.4f | se : %0.4f") % [@vector.mean, @vector.sd, se]
    s.text _("Population mean: %0.4f") % u if u!=0
    t_object.report_building_t(s)
  }
end

#standard_errorObject Also known as: se



180
181
182
# File 'lib/statsample/test/t.rb', line 180

def standard_error
  t_object.standard_error
end

#tObject



174
175
176
# File 'lib/statsample/test/t.rb', line 174

def t
  t_object.t
end

#t_objectObject



171
172
173
# File 'lib/statsample/test/t.rb', line 171

def t_object
  T.new(@vector.mean-u, @vector.se, @vector.n_valid-1, opts)
end