Class: Statsample::Anova::OneWay

Inherits:
Object
  • Object
show all
Includes:
Summarizable
Defined in:
lib/statsample/anova/oneway.rb

Overview

Generic Anova one-way.

You could enter the sum of squares or the mean squares. You should enter the degrees of freedom for numerator and denominator.

Usage

anova=Statsample::Anova::OneWay(:ss_num=>10,:ss_den=>20, :df_num=>2, :df_den=>10, @name=>"ANOVA for....")

Direct Known Subclasses

OneWayWithVectors

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Summarizable

#summary

Constructor Details

#initialize(opts = Hash.new) ⇒ OneWay

Returns a new instance of OneWay.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/statsample/anova/oneway.rb', line 15

def initialize(opts=Hash.new)
  @name=@name_numerator=@name_denominator=nil
  
  # First see if sum of squares or mean squares are entered
  raise ArgumentError, "You should set d.f." unless (opts.has_key? :df_num and opts.has_key? :df_den)
  @df_num=opts.delete :df_num
  @df_den=opts.delete :df_den
  @df_total=@df_num+@df_den
  if(opts.has_key? :ss_num and opts.has_key? :ss_den)
    @ss_num = opts.delete :ss_num
    @ss_den =opts.delete :ss_den
    @ms_num =@ss_num.quo(@df_num)
    @ms_den =@ss_den.quo(@df_den) 
  elsif (opts.has_key? :ms_num and opts.has_key? :ms_den)
    @ms_num =opts.delete :ms_num
    @ms_den =opts.delete :ms_den
    @ss_num =@ms_num * @df_num
    @ss_den =@ss_den * @df_den
  end
  @ss_total=@ss_num+@ss_den
  @ms_total=@ms_num+@ms_den
  opts_default={:name=>"ANOVA",
                :name_denominator=>_("Explained variance"),
                :name_numerator=>_("Unexplained variance")}
  @opts=opts_default.merge(opts)
  opts.keys.each {|k|
    send("#{k}=", @opts[k]) if self.respond_to? "#{k}="
  }
  @f_object=Statsample::Test::F.new(@ms_num, @ms_den, @df_num,@df_den)
end

Instance Attribute Details

#df_denObject (readonly)

Returns the value of attribute df_den.



10
11
12
# File 'lib/statsample/anova/oneway.rb', line 10

def df_den
  @df_den
end

#df_numObject (readonly)

Returns the value of attribute df_num.



10
11
12
# File 'lib/statsample/anova/oneway.rb', line 10

def df_num
  @df_num
end

#df_totalObject (readonly)

Returns the value of attribute df_total.



10
11
12
# File 'lib/statsample/anova/oneway.rb', line 10

def df_total
  @df_total
end

#ms_denObject (readonly)

Returns the value of attribute ms_den.



10
11
12
# File 'lib/statsample/anova/oneway.rb', line 10

def ms_den
  @ms_den
end

#ms_numObject (readonly)

Returns the value of attribute ms_num.



10
11
12
# File 'lib/statsample/anova/oneway.rb', line 10

def ms_num
  @ms_num
end

#ms_totalObject (readonly)

Returns the value of attribute ms_total.



10
11
12
# File 'lib/statsample/anova/oneway.rb', line 10

def ms_total
  @ms_total
end

#nameObject

Name of ANOVA Analisys



12
13
14
# File 'lib/statsample/anova/oneway.rb', line 12

def name
  @name
end

#name_denominatorObject

Returns the value of attribute name_denominator.



13
14
15
# File 'lib/statsample/anova/oneway.rb', line 13

def name_denominator
  @name_denominator
end

#name_numeratorObject

Returns the value of attribute name_numerator.



14
15
16
# File 'lib/statsample/anova/oneway.rb', line 14

def name_numerator
  @name_numerator
end

#ss_denObject (readonly)

Returns the value of attribute ss_den.



10
11
12
# File 'lib/statsample/anova/oneway.rb', line 10

def ss_den
  @ss_den
end

#ss_numObject (readonly)

Returns the value of attribute ss_num.



10
11
12
# File 'lib/statsample/anova/oneway.rb', line 10

def ss_num
  @ss_num
end

#ss_totalObject (readonly)

Returns the value of attribute ss_total.



10
11
12
# File 'lib/statsample/anova/oneway.rb', line 10

def ss_total
  @ss_total
end

Instance Method Details

#fObject

F value



46
47
48
# File 'lib/statsample/anova/oneway.rb', line 46

def f
  @f_object.f
end

#probabilityObject

P-value of F test



50
51
52
# File 'lib/statsample/anova/oneway.rb', line 50

def probability
  @f_object.probability
end

#report_building(builder) ⇒ Object

:nodoc:



53
54
55
56
57
# File 'lib/statsample/anova/oneway.rb', line 53

def report_building(builder) #:nodoc:
  builder.section(:name=>@name) do |b|
    report_building_table(b)
  end
end

#report_building_table(builder) ⇒ Object

:nodoc:



58
59
60
61
62
63
64
# File 'lib/statsample/anova/oneway.rb', line 58

def report_building_table(builder) #:nodoc:
  builder.table(:name=>_("%s Table") % @name, :header=>%w{source ss df ms f p}.map {|v| _(v)}) do |t|
    t.row([@name_numerator, sprintf("%0.3f",@ss_num),   @df_num, sprintf("%0.3f",@ms_num),  sprintf("%0.3f",f), sprintf("%0.3f", probability)])
    t.row([@name_denominator, sprintf("%0.3f",@ss_den),  @df_den, sprintf("%0.3f",@ms_den), "", ""])
    t.row([_("Total"), sprintf("%0.3f",@ss_total),  @df_total, sprintf("%0.3f",@ms_total),"",""])
  end
end