-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat.js
42 lines (40 loc) · 844 Bytes
/
stat.js
1
2
3
4
5
6
7
8
9
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
// Shamelessly stolen from http://statpages.org/pdfs.html
var Pi=Math.PI;
var PiD2=Pi/2;
function StatCom(q,i,j,b) {
var zz=1; var z=zz; var k=i; while(k<=j) { zz=zz*q*k/(k-b); z=z+zz; k=k+2 }
return z
}
function StudT(t,n) {
var fn=Math.floor(n);
var cn=Math.ceil(n)
if( fn!=n ) {
Tf = Math.log( StudT(t,fn) );
Tc = Math.log( StudT(t,cn) )
return Math.exp( (cn-n)*Tf + (n-fn)*Tc )
}
t=Math.abs(t);
var w=t/Math.sqrt(n);
var th=Math.atan(w)
if(n==1) { return 1-th/PiD2 }
var sth=Math.sin(th); var cth=Math.cos(th)
if((n%2)==1)
{ return 1-(th+sth*cth*StatCom(cth*cth,2,n-3,-1))/PiD2 }
else
{ return 1-sth*StatCom(cth*cth,1,n-3,-1) }
}
function AStudT(p,n) {
var v=0.5;
var dv=0.5;
var t=0
while(dv>1e-6) {
t=1/v-1;
dv=dv/2;
if(StudT(t,n)>p) {
v=v-dv
} else {
v=v+dv
}
}
return t
}