001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.math3.stat.interval;
018
019import org.apache.commons.math3.exception.NumberIsTooLargeException;
020import org.apache.commons.math3.exception.OutOfRangeException;
021import org.apache.commons.math3.exception.NotPositiveException;
022import org.apache.commons.math3.exception.NotStrictlyPositiveException;
023
024/**
025 * Interface to generate confidence intervals for a binomial proportion.
026 *
027 * @see <a
028 *      href="http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval">Binomial
029 *      proportion confidence interval (Wikipedia)</a>
030 * @since 3.3
031 */
032public interface BinomialConfidenceInterval {
033
034    /**
035     * Create a confidence interval for the true probability of success
036     * of an unknown binomial distribution with the given observed number
037     * of trials, successes and confidence level.
038     * <p>
039     * Preconditions:
040     * <ul>
041     * <li>{@code numberOfTrials} must be positive</li>
042     * <li>{@code numberOfSuccesses} may not exceed {@code numberOfTrials}</li>
043     * <li>{@code confidenceLevel} must be strictly between 0 and 1 (exclusive)</li>
044     * </ul>
045     * </p>
046     *
047     * @param numberOfTrials number of trials
048     * @param numberOfSuccesses number of successes
049     * @param confidenceLevel desired probability that the true probability of
050     *        success falls within the returned interval
051     * @return Confidence interval containing the probability of success with
052     *         probability {@code confidenceLevel}
053     * @throws NotStrictlyPositiveException if {@code numberOfTrials <= 0}.
054     * @throws NotPositiveException if {@code numberOfSuccesses < 0}.
055     * @throws NumberIsTooLargeException if {@code numberOfSuccesses > numberOfTrials}.
056     * @throws OutOfRangeException if {@code confidenceLevel} is not in the interval {@code (0, 1)}.
057     */
058    ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses, double confidenceLevel)
059            throws NotStrictlyPositiveException, NotPositiveException,
060                   NumberIsTooLargeException, OutOfRangeException;
061
062}