Class: ForChrisLib::PChiSquared
- Inherits:
-
Object
- Object
- ForChrisLib::PChiSquared
- Defined in:
- lib/chris_lib/for_chris_lib.rb
Overview
Wrapper around chi-squared tail probability helpers.
Instance Method Summary collapse
-
#call(dof, nu) ⇒ Float
Upper-tail probability.
-
#initialize(calculator: nil) ⇒ PChiSquared
constructor
A new instance of PChiSquared.
Constructor Details
#initialize(calculator: nil) ⇒ PChiSquared
Returns a new instance of PChiSquared.
74 75 76 |
# File 'lib/chris_lib/for_chris_lib.rb', line 74 def initialize(calculator: nil) @calculator = calculator end |
Instance Method Details
#call(dof, nu) ⇒ Float
Returns upper-tail probability.
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/chris_lib/for_chris_lib.rb', line 81 def call(dof, nu) raise ArgumentError, 'degrees of freedom must be positive' unless dof.is_a?(Numeric) && dof.positive? raise ArgumentError, 'chi-squared statistic must be non-negative' unless nu.is_a?(Numeric) && nu >= 0 if calculator return calculator.call(dof, nu) end # Use the complemented incomplete gamma to evaluate the survival function. s = dof.to_f / 2.0 x = nu.to_f / 2.0 regularized_gamma_q(s, x) end |