10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/eps/statistics.rb', line 10
def self.students_t_cdf(x, n)
start, sign = x < 0 ? [0, 1] : [1, -1]
z = 1.0
t = x * x
y = t / n.to_f
b = 1.0 + y
if n > n.floor || (n >= 20.0 && t < n) || n > 200.0
if y > 10e-6
y = Math.log(b)
end
a = n - 0.5
b = 48.0 * a * a
y *= a
y = (((((-0.4 * y - 3.3) * y - 24.0) * y - 85.5) / (0.8 * y * y + 100.0 + b) + y + 3.0) / b + 1.0) * Math.sqrt(y)
return start + sign * normal_cdf(-y, 0.0, 1.0)
end
if n < 20 && t < 4.0
y = Math.sqrt(y)
a = y
if n == 1
a = 0.0
end
if n > 1
n -= 2
while n > 1
a = (n - 1) / (b * n) * a + y
n -= 2
end
end
a = n == 0 ? a / Math.sqrt(b) : (Math.atan(y) + a / b) * (2.0 / Math::PI)
return start + sign * (z - a) / 2.0
end
a = Math.sqrt(b)
y = a * n
j = 0
while a != z
j += 2
z = a
y = y * (j - 1) / (b * j)
a += y / (n + j)
end
z = 0.0
y = 0.0
a = -a
while n > 1
a = (n - 1) / (b * n) * a + y
n -= 2
end
a = n == 0 ? a / Math.sqrt(b) : (Math.atan(y) + a / b) * (2.0 / Math::PI)
start + sign * (z - a) / 2.0
end
|