Class: Statsample::Test::Levene
- Inherits:
-
Object
- Object
- Statsample::Test::Levene
- Defined in:
- lib/statsample/test/levene.rb
Overview
Levene Test for Equality of Variances
From NIST/SEMATECH: <blockquote>Levene’s test ( Levene, 1960) is used to test if k samples have equal variances. Equal variances across samples is called homogeneity of variance. Some statistical tests, for example the analysis of variance, assume that variances are equal across groups or samples. The Levene test can be used to verify that assumption.</blockquote> Use:
require 'statsample'
a=[1,2,3,4,5,6,7,8,100,10].to_scale
b=[30,40,50,60,70,80,90,100,110,120].to_scale
levene=Statsample::Test::Levene.new([a,b])
puts levene.summary
Output:
Levene Test
F: 0.778121319848449
p: 0.389344552595791
Reference:
-
NIST/SEMATECH e-Handbook of Statistical Methods. Available on www.itl.nist.gov/div898/handbook/eda/section3/eda35a.htm
Instance Attribute Summary collapse
-
#d1 ⇒ Object
readonly
Degrees of freedom 1 (k-1).
-
#d2 ⇒ Object
readonly
Degrees of freedom 2 (n-k).
-
#name ⇒ Object
Name of test.
Instance Method Summary collapse
-
#f ⇒ Object
Value of the test.
-
#initialize(input, opts = Hash.new()) ⇒ Levene
constructor
Input could be an array of vectors or a dataset.
-
#probability ⇒ Object
Probability.
-
#report_building(g) ⇒ Object
:nodoc:.
-
#summary ⇒ Object
Summary of results.
Constructor Details
#initialize(input, opts = Hash.new()) ⇒ Levene
Input could be an array of vectors or a dataset
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/statsample/test/levene.rb', line 29 def initialize(input, opts=Hash.new()) if input.is_a? Statsample::Dataset @vectors=input.vectors.values else @vectors=input end @name="Levene Test" opts.each{|k,v| self.send("#{k}=",v) if self.respond_to? k } compute end |
Instance Attribute Details
#d1 ⇒ Object (readonly)
Degrees of freedom 1 (k-1)
23 24 25 |
# File 'lib/statsample/test/levene.rb', line 23 def d1 @d1 end |
#d2 ⇒ Object (readonly)
Degrees of freedom 2 (n-k)
25 26 27 |
# File 'lib/statsample/test/levene.rb', line 25 def d2 @d2 end |
#name ⇒ Object
Name of test
27 28 29 |
# File 'lib/statsample/test/levene.rb', line 27 def name @name end |
Instance Method Details
#f ⇒ Object
Value of the test
42 43 44 |
# File 'lib/statsample/test/levene.rb', line 42 def f @w end |
#probability ⇒ Object
Probability. With H_0 = Sum(s2)=0, probability of getting a value of the test upper or equal to the obtained on the sample
88 89 90 |
# File 'lib/statsample/test/levene.rb', line 88 def probability 1-Distribution::F.cdf(f, @d1, @d2) end |
#report_building(g) ⇒ Object
:nodoc:
46 47 48 49 50 51 |
# File 'lib/statsample/test/levene.rb', line 46 def report_building(g) # :nodoc: g.text @name g.text "F: #{"%0.4f" % f}" g.text "p: #{"%0.4f" % probability}" end |
#summary ⇒ Object
Summary of results
53 54 55 |
# File 'lib/statsample/test/levene.rb', line 53 def summary ReportBuilder.new(:no_title=>true).add(self).to_text end |