1 package JSci.maths.statistics; 2 3 import JSci.maths.SpecialMath; 4 5 10 public final class TDistribution extends ProbabilityDistribution { 11 private int dgrFreedom; 12 private double logPdfFreedom; 13 14 18 public TDistribution(int r) { 19 if(r<=0) 20 throw new OutOfRangeException("The degrees of freedom must be greater than zero."); 21 dgrFreedom=r; 22 logPdfFreedom=-SpecialMath.logBeta(0.5*dgrFreedom,0.5)-0.5*Math.log(dgrFreedom); 23 } 24 27 public int getDegreesOfFreedom() { 28 return dgrFreedom; 29 } 30 34 public double probability(double X) { 35 double logPdf=logPdfFreedom; 36 logPdf-=(0.5*(dgrFreedom+1))*Math.log(1.0+(X*X)/dgrFreedom); 37 return Math.exp(logPdf); 38 } 39 43 public double cumulative(double X) { 44 double A=0.5*SpecialMath.incompleteBeta((dgrFreedom)/(dgrFreedom+X*X),0.5*dgrFreedom,0.5); 45 return X>0 ? 1-A : A; 46 } 47 51 public double inverse(double probability) { 52 checkRange(probability); 53 if(probability==0.0) 54 return -Double.MAX_VALUE; 55 if(probability==1.0) 56 return Double.MAX_VALUE; 57 if(probability==0.5) 58 return 0.0; 59 return findRoot(probability, 0.0, -0.5*Double.MAX_VALUE, 0.5*Double.MAX_VALUE); 60 } 61 } 62 63 | Popular Tags |