Created
January 18, 2015 15:53
-
-
Save komiya-atsushi/133085ef955c24303eed to your computer and use it in GitHub Desktop.
commons-math3 を使って二項比率の信頼区間を求めるデモプログラム。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.math3.stat.interval.*; | |
import java.util.Arrays; | |
import java.util.List; | |
/** | |
* commons-math3 を使って二項比率の信頼区間を求めるデモプログラム。 | |
*/ | |
public class BinomialProportionDemo { | |
static void demo(int numClicks, int numImpression) { | |
List<BinomialConfidenceInterval> methods = Arrays.asList( | |
new NormalApproximationInterval(), | |
new ClopperPearsonInterval(), | |
new WilsonScoreInterval(), | |
new AgrestiCoullInterval()); | |
double alpha = 0.05; | |
System.out.println("---"); | |
for (BinomialConfidenceInterval method : methods) { | |
String name = method.getClass().getSimpleName(); | |
try { | |
ConfidenceInterval ci = method.createInterval(numImpression, numClicks, 1 - alpha); | |
System.out.printf("%s: %s\n", name, ci.toString()); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
System.out.printf("%s: Cannot calculate confidence interval\n", name); | |
} | |
} | |
} | |
public static void main(String[] args) { | |
demo(5, 1000); | |
demo(0, 1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment