Class: Statsample::Test::ChiSquare::WithVector
- Includes:
- Shared
- Defined in:
- lib/statsample/test/chisquare.rb
Instance Attribute Summary
Attributes included from Shared
Instance Method Summary collapse
- #compute_chi ⇒ Object
-
#initialize(observed, expected) ⇒ WithVector
constructor
A new instance of WithVector.
Methods included from Shared
#chi_square, #probability, #to_f
Constructor Details
#initialize(observed, expected) ⇒ WithVector
Returns a new instance of WithVector.
55 56 57 58 59 60 61 |
# File 'lib/statsample/test/chisquare.rb', line 55 def initialize(observed, expected) @observed = observed @expected = expected raise "Observed size!=expected size" if @observed.size!=@expected.size @df = @observed.size - 1 @value = compute_chi end |
Instance Method Details
#compute_chi ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/statsample/test/chisquare.rb', line 63 def compute_chi sum=0 (0...@observed.size).each {|i| sum+=((@observed[i] - @expected[i])**2).quo(@expected[i]) } sum end |