Module: Math::Statistics
- Defined in:
- lib/math/statistics/chi_square.rb
Overview
Methods for Chi-Sqaure testing.
Currently reads the chi square values from the html file
table_chi_square_probabilities.html
which was downloaded from
http://www.richland.edu/james/lecture/m170/tbl-chi.html
Longer-term we would like to add a method that calculates the chi square probability exactly. We have found such code implemented in Javascript but porting it to Ruby is not straightforward since there are roundoff problems.
Class Method Summary collapse
-
.critical_chi_square_value(degreesOfFreedom, alpha) ⇒ Object
Critical value for the confidence level_alpha_ for a Chi-square distribution with with degreesOfFreedom degrees of freedom.
-
.valid_degrees_of_freedom ⇒ Object
Returns the degrees of freedom for which we can currently supply critical values for the Chi-Square distribution.
Class Method Details
.critical_chi_square_value(degreesOfFreedom, alpha) ⇒ Object
Critical value for the confidence level_alpha_ for a Chi-square distribution with with degreesOfFreedom degrees of freedom.
17 18 19 20 21 22 23 |
# File 'lib/math/statistics/chi_square.rb', line 17 def self.critical_chi_square_value(degreesOfFreedom, alpha) dft = chi_square_probabilities_table[degreesOfFreedom] unless dft raise "Cannot calc chi square probability for #{degreesOfFreedom} degrees of freedom" end dft[alpha] end |
.valid_degrees_of_freedom ⇒ Object
Returns the degrees of freedom for which we can currently supply critical values for the Chi-Square distribution.
27 28 29 30 31 |
# File 'lib/math/statistics/chi_square.rb', line 27 def self.valid_degrees_of_freedom return @valid_degrees_of_freedom if @valid_degrees_of_freedom parse_chi_square_probabilities_into_hash @valid_degrees_of_freedom end |