/*
This is a proprietary part of DataMelt package.
License: the Creative Commons Attribution-Share Alike License; either version 3.0 of the License,
or any later version.
http://creativecommons.org/licenses/by-sa/3.0/
Permission to use, copy and modify this software and its documentation for
NON-COMMERCIAL purposes is granted,
without fee, provided that an acknowledgement to the author, Dr Sergei Chekanov
appears in all copies and associated documentation or publications.
Redistributions of the source code, or parts of the source codes,
must retain the copyright notice, this list of conditions and the following disclaimer
(all at the top of each source code) and requires the written permission of Sergei Chekanov
Redistribution in binary form of all or parts of a class must reproduce the
copyright notice, this list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution and requires the written permission of Sergei Chekanov
Details about license agreement or commercial use are: http://jwork.org/jhepwork/license.php
*/
package jhpro.stat;
import jhplot.*;
/**
* Computes the mean, standard deviation and 95% approximate confidence
* interval.
*
* Note: the two-pass formula is preferred for stability.
*
*/
public class ConfInterval {
private double lo;
private double hi;
private double variance;
private double stddev;
private double xbar;
/**
* Initialize calculation of confidence interval.
*
* @param p0d
* input array of numbers
*/
public ConfInterval(P0D p0d) {
double sumx = 0;
for (int i = 0; i < p0d.size(); i++)
sumx += p0d.get(i);
xbar = sumx / p0d.size();
// second pass: compute sample variance
double xxbar = 0.0;
for (int i = 0; i < p0d.size(); i++) {
xxbar += (p0d.get(i) - xbar) * (p0d.get(i) - xbar);
}
variance = xxbar / (p0d.size() - 1);
stddev = Math.sqrt(variance);
lo = xbar - 1.96 * stddev;
hi = xbar + 1.96 * stddev;
// print results
/*
* System.out.println("average = " + xbar);
* System.out.println("sample variance = " + variance);
* System.out.println("sample stddev = " + stddev);
* System.out.println("95% approximate confidence interval");
* System.out.println("[ " + lo + ", " + hi + " ]");
*/
}
double getMean() {
return xbar;
};
double getVariance() {
return variance;
};
double getStdDev() {
return stddev;
};
/**
* Get lowest value in 95% confidence interval.
*/
double getMinCon() {
return lo;
};
/**
* Get higest value in 95% confidence interval.
*/
double getMaxCon() {
return hi;
};
}
Ads help maintain this website.