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 = Daru::Vector.new(1000.times.map {rand(100)})
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


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

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.reject_values(*Daru::MISSING_VALUES).size-1
  @t=nil
end

Instance Attribute Details

#dfObject (readonly)

Degress of freedom


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

def df
  @df
end

#nameObject

Name of test


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

def name
  @name
end

#optsObject

Options


143
144
145
# File 'lib/statsample/test/t.rb', line 143

def opts
  @opts
end

#tailsObject

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


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

def tails
  @tails
end

#uObject

Population mean to contrast


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

def u
  @u
end

Instance Method Details

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


182
183
184
# File 'lib/statsample/test/t.rb', line 182

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

#probabilityObject


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

def probability
  t_object.probability
end

#report_building(b) ⇒ Object

:nodoc:


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

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


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

def standard_error
  t_object.standard_error
end

#tObject


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

def t
  t_object.t
end

#t_objectObject


169
170
171
# File 'lib/statsample/test/t.rb', line 169

def t_object
  T.new(@vector.mean-u, @vector.se, @vector.reject_values(*Daru::MISSING_VALUES).size-1, opts)
end