1 package JSci.maths.statistics; 2 3 import JSci.maths.SpecialMath; 4 5 10 public final class FDistribution extends ProbabilityDistribution { 11 private double p,q; 12 private BetaDistribution beta; 15 16 21 public FDistribution(double dgrP, double dgrQ) { 22 if(dgrP<=0.0 || dgrQ<=0.0) 23 throw new OutOfRangeException("The degrees of freedom must be greater than zero."); 24 p=dgrP; 25 q=dgrQ; 26 beta=new BetaDistribution(p/2.0, q/2.0); 27 } 28 31 public double getDegreesOfFreedomP() { 32 return p; 33 } 34 37 public double getDegreesOfFreedomQ() { 38 return q; 39 } 40 44 public double probability(double X) { 45 checkRange(X,0.0,Double.MAX_VALUE); 46 final double y = q/(q+(p*X)); 47 return beta.probability(1.0-y)*y*y*p/q; 48 } 49 53 public double cumulative(double X) { 54 checkRange(X,0.0,Double.MAX_VALUE); 55 return beta.cumulative((p*X)/(q+(p*X))); 56 } 57 61 public double inverse(double probability) { 62 checkRange(probability); 63 if(probability==0.0) 64 return 0.0; 65 if(probability==1.0) 66 return Double.MAX_VALUE; 67 final double y=beta.inverse(probability); 68 if(y<2.23e-308) return Double.MAX_VALUE; 70 else 71 return (q/p)*(y/(1.0-y)); 72 } 73 } 74 75 | Popular Tags |