Class: Statsample::Anova::Contrast

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Summarizable

#summary

Constructor Details

#initialize(opts = Hash.new) ⇒ Contrast

Returns a new instance of Contrast.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/statsample/anova/contrast.rb', line 8

def initialize(opts=Hash.new)
  raise "Should set at least vectors options" if opts[:vectors].nil?
  @vectors=opts[:vectors]
  @c=opts[:c]
  @c1,@c2=opts[:c1], opts[:c2]
  @t_options=opts[:t_options] || {:estimate_name=>_("Psi estimate")}
  @name=opts[:name] || _("Contrast")
  @psi=nil
  @anova=Statsample::Anova::OneWayWithVectors.new(@vectors)
  @msw=@anova.msw
end

Instance Attribute Details

#mswObject (readonly)

Returns the value of attribute msw.



6
7
8
# File 'lib/statsample/anova/contrast.rb', line 6

def msw
  @msw
end

#psiObject (readonly)

Returns the value of attribute psi.



4
5
6
# File 'lib/statsample/anova/contrast.rb', line 4

def psi
  @psi
end

Instance Method Details

#c(args = nil) ⇒ Object

Hypothesis contrast, using custom values Every parameter is a contrast value. You should use the same number of contrast as vectors on class and the sum of constrast should be 0.



44
45
46
47
48
49
50
51
# File 'lib/statsample/anova/contrast.rb', line 44

def c(args=nil)
  
  return @c if args.nil?
  @c=args
  raise "contrast number!=vector number" if args.size!=@vectors.size
  #raise "Sum should be 0" if args.inject(0) {|ac,v| ac+v}!=0
  @psi=args.size.times.inject(0) {|ac,i| ac+(args[i]*@vectors[i].mean)}
end

#c_by_index(c1, c2) ⇒ Object

Hypothesis contrast, selecting index for each constrast For example, if you want to contrast x_0 against x_1 and x_2 you should use c.contrast(,[1,2])



23
24
25
26
27
28
29
# File 'lib/statsample/anova/contrast.rb', line 23

def c_by_index(c1,c2)
  contrast=[0]*@vectors.size
  c1.each {|i| contrast[i]=1.quo(c1.size)}
  c2.each {|i| contrast[i]=-1.quo(c2.size)}
  @c=contrast
  c(contrast)
end

#confidence_interval(cl = nil) ⇒ Object



37
38
39
# File 'lib/statsample/anova/contrast.rb', line 37

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

#dfObject



59
60
61
# File 'lib/statsample/anova/contrast.rb', line 59

def df
  @vectors.inject(0) {|ac,v| ac+v.size}-@vectors.size
end

#probabilityObject



68
69
70
# File 'lib/statsample/anova/contrast.rb', line 68

def probability
  t_object.probability
end

#report_building(builder) ⇒ Object



71
72
73
74
75
76
# File 'lib/statsample/anova/contrast.rb', line 71

def report_building(builder)
   builder.section(:name=>@name) do |s|
     s.text _("Contrast:%s") % c.join(",")
     s.parse_element(t_object)
   end
end

#standard_errorObject Also known as: se



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

def standard_error
  sum=@vectors.size.times.inject(0) {|ac,i|
    ac+((@c[i].rationalize**2).quo(@vectors[i].size))
  } 
  Math.sqrt(@msw*sum)
end

#tObject



65
66
67
# File 'lib/statsample/anova/contrast.rb', line 65

def t
  t_object.t
end

#t_objectObject



62
63
64
# File 'lib/statsample/anova/contrast.rb', line 62

def t_object
  Statsample::Test::T.new(psi, se, df, @t_options)
end