lib/distribution/t/ruby.rb in distribution-0.4.0 vs lib/distribution/t/ruby.rb in distribution-0.5.0
- old
+ new
@@ -12,19 +12,24 @@
end
# t-distribution ([1])
# (-\infty, x]
def p_t(df, t)
+ if df.to_i!=df
+ raise "Can't calculate not integer df"
+ end
+ df=df.to_i
c2 = df.to_f / (df + t * t);
s = Math.sqrt(1.0 - c2)
s = -s if t < 0.0
p = 0.0;
i = df % 2 + 2
while i <= df
p += s
s *= (i - 1) * c2 / i
i += 2
end
+
if df.is_a? Float or df & 1 != 0
0.5+(p*Math.sqrt(c2)+Math.atan(t/Math.sqrt(df))) / Math::PI
else
(1.0 + p) / 2.0
end
\ No newline at end of file