Skip to content

Chi squared Distribution

Esteban Zapata Rojas edited this page Oct 19, 2017 · 4 revisions

Instance methods

Cumulative function

It calculates the probability P(x <= X) for an specified X. This method uses the lower incomplete gamma function to do the expected calculation.

[47] pry(main)> Distribution::ChiSquared.new(4)
=> #<Statistics::Distribution::ChiSquared:0x00000000019e5e20 @degrees_of_freedom=4>
[48] pry(main)> Distribution::ChiSquared.new(4).cumulative_function(2)
=> 0.2642533819718204

Probability Density function

It calculates the density for the specified value, based the degrees of freedom specified at initialize time.

[58] pry(main)> chi_sq = Distribution::ChiSquared.new(3) # 3 Degrees of freedom
=> #<Statistics::Distribution::ChiSquared:0x007fdfcb9ffc88 @degrees_of_freedom=3>
[59] pry(main)> results = (0..8).map do |number|
[59] pry(main)*   chi_sq.density_function(number)
[59] pry(main)* end  
=> [0.0, 0.24197072451914334, 0.20755374871029736, 0.15418032980376925, 0.1079819330263761, 0.07322491280963243, 0.04865217332964145, 0.03187340045148122, 0.020666985354092053]

Mean

It is the same as the degrees of freedom specified at initialize time.

pry(main)> chi_sq.mean
=> 3

Mode

It is the maximum value between degrees_of_freedom - 2 and zero.

[61] pry(main)> chi_sq.mode
=> 1

Variance

It is two times degrees_of_freedom.

[62] pry(main)> chi_sq.variance # Degrees of freedom = 3
=> 6