class Statsample::Anova::OneWayWithVectors
One Way Anova with vectors Example:
v1=[2,3,4,5,6].to_scale v2=[3,3,4,5,6].to_scale v3=[5,3,1,5,6].to_scale anova=Statsample::Anova::OneWayWithVectors.new([v1,v2,v3]) anova.f => 0.0243902439024391 anova.probability => 0.975953044203438 anova.sst => 32.9333333333333
One Way Anova with vectors Example:
v1=[2,3,4,5,6].to_scale v2=[3,3,4,5,6].to_scale v3=[5,3,1,5,6].to_scale anova=Statsample::Anova::OneWayWithVectors.new([v1,v2,v3]) anova.f => 0.0243902439024391 anova.probability => 0.975953044203438 anova.sst => 32.9333333333333
Attributes
contrasts[R]
Array with stored contrasts
summary_contrasts[RW]
Show on summary of contrasts
summary_descriptives[RW]
Show on summary descriptives for vectors
summary_levene[RW]
Show on summary Levene test
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Statsample::Anova::OneWay.new
# File lib/statsample/anova/oneway.rb, line 91 def initialize(*args) if args[0].is_a? Array @vectors=args.shift else @vectors=args.find_all {|v| v.is_a? Statsample::Vector} opts=args.find {|v| v.is_a? Hash} end opts||=Hash.new opts_default={:name=>_("Anova One-Way"), :name_numerator=>_("Between Groups"), :name_denominator=>_("Within Groups"), :summary_descriptives=>false, :summary_levene=>true, :summary_contrasts=>true } @opts=opts_default.merge(opts).merge(:ss_num=>ssbg, :ss_den=>sswg, :df_num=>df_bg, :df_den=>df_wg) @contrasts=[] super(@opts) end
Public Instance Methods
contrast(opts=Hash.new)
click to toggle source
Generates and store a contrast. Options should be provided as a hash [:c]=>contrast vector [:c1 - :c2]=>index for automatic construction of contrast [:name]=>contrast name
# File lib/statsample/anova/oneway.rb, line 120 def contrast(opts=Hash.new) name=opts[:name] || _("Contrast for %s") % @name opts=opts.merge({:vectors=>@vectors, :name=>name}) c=Statsample::Anova::Contrast.new(opts) @contrasts.push(c) c end
df_bg()
click to toggle source
Degrees of freedom between groups
# File lib/statsample/anova/oneway.rb, line 155 def df_bg k-1 end
df_wg()
click to toggle source
Degrees of freedom within groups
# File lib/statsample/anova/oneway.rb, line 148 def df_wg @dk_wg||=n-k end
k()
click to toggle source
# File lib/statsample/anova/oneway.rb, line 151 def k @k||=@vectors.size end
levene()
click to toggle source
# File lib/statsample/anova/oneway.rb, line 128 def levene Statsample::Test.levene(@vectors, :name=>_("Test of Homogeneity of variances (Levene)")) end
n()
click to toggle source
Total number of cases
# File lib/statsample/anova/oneway.rb, line 159 def n @vectors.inject(0){|a,v| a+v.size} end
ssbg()
click to toggle source
Sum of squares between groups
# File lib/statsample/anova/oneway.rb, line 141 def ssbg m=total_mean @vectors.inject(0) do |total,vector| total + (vector.mean-m).square * vector.size end end
sswg()
click to toggle source
Sum of squares within groups
# File lib/statsample/anova/oneway.rb, line 137 def sswg @sswg||=@vectors.inject(0) {|total,vector| total+vector.ss } end
total_mean()
click to toggle source
Total mean
# File lib/statsample/anova/oneway.rb, line 132 def total_mean sum=@vectors.inject(0){|a,v| a+v.sum} sum.quo(n) end