[英]Using Apache Commons Math to determine confidence intervals
I have a set of benchmark data for which I compute summary statistics using Apache Math Commons. 我有一组基准数据,我使用Apache Math Commons计算汇总统计数据。 Now I want to use the package to compute confidence intervals for the arithmetic means of eg running time measurements.
现在我想使用该包来计算例如运行时间测量的算术平均值的置信区间。
Is this possible at all? 这有可能吗? I am convinced that the package supports this, however I am at a loss about where to start.
我确信该软件包支持这一点,但是我不知道从哪里开始。
This is the solution I ended up using with the help of Brent Worden's suggestion: 这是我在Brent Worden建议的帮助下最终使用的解决方案:
private double getConfidenceIntervalWidth(StatisticalSummary statistics, double significance) {
TDistribution tDist = new TDistribution(statistics.getN() - 1);
double a = tDist.inverseCumulativeProbability(1.0 - significance / 2);
return a * statistics.getStandardDeviation() / Math.sqrt(statistics.getN());
}
Apache Commons Math does not have direct support for constructing confidence intervals. Apache Commons Math没有直接支持构建置信区间。 However, it does have everything needed to compute them.
但是,它确实拥有计算它们所需的一切。
First, use SummaryStatistics , or some other StatisticalSummary implementation to summarize your data into sample statistics. 首先,使用SummaryStatistics或其他一些StatisticalSummary实现将您的数据汇总到样本统计信息中。
Next, use TDistribution to compute critical values for your desired confidence level. 接下来,使用TDistribution计算所需置信度的关键值。 The degrees of freedom can be inferred from the summary statistics'
n
property. 可以从摘要统计'
n
属性推断出自由度。
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. 最后,使用摘要统计信息中的
mean
, variance
和n
属性值以及分布中的t临界值来计算置信下限和置信上限。
If you still want to calculate binomial in java by using only standard edition You can use below class like below. 如果您仍然想要仅使用标准版本来计算java中的二项式您可以使用下面的类,如下所示。
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.