Using Apache Commons Math to determine confidence intervals

前端 未结 2 1346
暖寄归人
暖寄归人 2021-02-07 13:30

I have a set of benchmark data for which I compute summary statistics using Apache Math Commons. Now I want to use the package to compute confidence intervals for the arithmetic

相关标签:
2条回答
  • 2021-02-07 14:03

    Apache Commons Math does not have direct support for constructing confidence intervals. However, it does have everything needed to compute them.

    First, use SummaryStatistics, or some other StatisticalSummary implementation to summarize your data into sample statistics.

    Next, use TDistribution to compute critical values for your desired confidence level. The degrees of freedom can be inferred from the summary statistics' n property.

    Last, use the mean, variance, and n property values from the summary statistics and the t critical value from the distribution to compute your lower and upper confidence limits.

    0 讨论(0)
  • 2021-02-07 14:12

    If you still want to calculate binomial in java by using only standard edition You can use below class like below.

    calling sample BinomialConfidenceCalc.calcBin(13, 100,95.0D);
    
    public class BinomialConfidenceCalc {
    
        public static double binP(double N,double p,double x1,double x2){
            double q = p/(1-p);
            double k = 0.0;
            double v = 1.0;
            double s = 0.0;
            double tot = 0.0;
    
            while(k<=N){                    
                tot += v;
                if(k >= x1 && k <= x2){                
                    s += v;
                }    
                if(tot > Math.pow(10,30)){                    
                    s = s/Math.pow(10,30);
                    tot = tot/Math.pow(10,30);
                    v = v/Math.pow(10,30);
                }
                k += 1;
                v = v*q*(N+1-k)/k;
    
            }
            return s/tot;
        }
    
    
        public static double[] calcBin(double vx,double vN,Double vCL){
    
            double vTU = (100 - vCL)/2;
            double vTL = vTU;
            double dl = 0.0;
            double vP = vx/vN;
            if(vx==0){            
                dl = 0.0;
            }
            else{
                double v = vP/2;
                double  vsL = 0;
                double vsH = vP;
                double p = vTL/100;
    
                while((vsH-vsL) > Math.pow(10,-5)){
                    if(binP(vN, v, vx, vN) > p){
                        vsH = v;
                        v = (vsL+v)/2;
                    }else{
                        vsL = v;
                        v = (v+vsH)/2;
                    }
                }
                dl = v;                             
            }
    
            double ul = 0.0;
            if(vx==vN){            
                ul = 1.0;
            }
            else{
    
                double v = (1+vP)/2;
                double vsL =vP;
                double vsH = 1;
                double p = vTU/100;
                while((vsH-vsL) > Math.pow(10,-5)){
                    if(binP(vN, v, 0, vx) < p){
                        vsH = v;
                        v = (vsL+v)/2;
                    }
                    else{
                        vsL = v;
                        v = (v+vsH)/2;
                    }
                }
                ul = v;
            }
            double dlUl[] = new double[]{dl,ul};
            return dlUl;
        }
    
    
    
    }
    
    0 讨论(0)
提交回复
热议问题