Skip to content

T student distribution

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

Instance methods

Cumulative function

It returns the probability P(x <= X) for an specified function.

[75] pry(main)> Distribution::TStudent.new(4)
=> #<Statistics::Distribution::TStudent:0x0000000001a69d38 @degrees_of_freedom=4, @mode=0>
[76] pry(main)> Distribution::TStudent.new(4).cumulative_function(3)
=> 0.9800290159641406

Probability density function

It returns the density for the specified value according to the t-student distribution. It's not defined when the degrees of freedom specified at initialize time are less or equal than zero.

[70] pry(main)> t_student = Distribution::TStudent.new(3) # 3 Degrees of freedom
=> #<Statistics::Distribution::TStudent:0x007fdfcbc87320 @degrees_of_freedom=3, @mode=0>
[71] pry(main)> results = (-4..4).map do |number|
[71] pry(main)*   t_student.density_function(number)
[71] pry(main)* end  
=> [0.009163361142744466,
 0.022972037309241335,
 0.06750966066389291,
 0.20674833578317206,
 0.36755259694786135,
 0.20674833578317206,
 0.06750966066389291,
 0.022972037309241335,
 0.009163361142744466]

Mode

It's always zero.

pry(main)> t_student.mode
=> 0

Mean

It returns zero if the degrees of freedom are greater than one. In other cases is not defined.

[75] pry(main)> t_student.mean
=> 0
[76] pry(main)> Distribution::TStudent.new(1).mean
=> nil

Variance

There are three cases:

  1. When 1 < degrees_of_freedom <=2 it will return Float::Infinity.
  2. When degrees_of_freedom are greater than 2, it will perform the calculation.
  3. When the degrees_of_freedom are less or equal than one, it is not defined.
[77] pry(main)> t_student.variance # degrees of freedom: 3
=> 3.0
[78] pry(main)> Distribution::TStudent.new(1).variance # Degrees of freedom: 1
=> nil
[79] pry(main)> Distribution::TStudent.new(2).variance # Degrees of freedom: 2
=> Infinity