/** * Create a Pascal distribution with the given number of successes and * probability of success. * * @param numberOfSuccesses the number of successes. * @param probabilityOfSuccess the probability of success * @return a new Pascal distribution * @since 1.2 */ public PascalDistribution createPascalDistribution( int numberOfSuccesses, double probabilityOfSuccess) { return new PascalDistributionImpl(numberOfSuccesses, probabilityOfSuccess); }
/** * Returns the mean. * * For number of successes <code>r</code> and * probability of success <code>p</code>, the mean is * <code>( r * p ) / ( 1 - p )</code> * * @return the mean * @since 2.2 */ public double getNumericalMean() { final double p = getProbabilityOfSuccess(); final double r = getNumberOfSuccesses(); return ( r * p ) / ( 1 - p ); }
/** * Create a binomial distribution with the given number of trials and * probability of success. * @param r the number of successes * @param p the probability of success */ public PascalDistributionImpl(int r, double p) { super(); setNumberOfSuccessesInternal(r); setProbabilityOfSuccessInternal(p); }
/** * Create a binomial distribution with the given number of trials and * probability of success. * @param r the number of successes * @param p the probability of success */ public PascalDistributionImpl(int r, double p) { super(); setNumberOfSuccesses(r); setProbabilityOfSuccess(p); }
/** * Change the number of successes for this distribution. * @param successes the new number of successes * @throws IllegalArgumentException if <code>successes</code> is not * positive. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setNumberOfSuccesses(int successes) { setNumberOfSuccessesInternal(successes); }
/** * Change the probability of success for this distribution. * @param p the new probability of success * @throws IllegalArgumentException if <code>p</code> is not a valid * probability. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setProbabilityOfSuccess(double p) { setProbabilityOfSuccessInternal(p); }
/** * Change the number of successes for this distribution. * @param successes the new number of successes * @throws IllegalArgumentException if <code>successes</code> is not * positive. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setNumberOfSuccesses(int successes) { setNumberOfSuccessesInternal(successes); } /**
/** * Change the probability of success for this distribution. * @param p the new probability of success * @throws IllegalArgumentException if <code>p</code> is not a valid * probability. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setProbabilityOfSuccess(double p) { setProbabilityOfSuccessInternal(p); } /**
/** * Returns the variance. * * For number of successes <code>r</code> and * probability of success <code>p</code>, the mean is * <code>( r * p ) / ( 1 - p )^2</code> * * @return the variance * @since 2.2 */ public double getNumericalVariance() { final double p = getProbabilityOfSuccess(); final double r = getNumberOfSuccesses(); final double pInv = 1 - p; return ( r * p ) / (pInv * pInv); } }
/** * Create a Pascal distribution with the given number of trials and * probability of success. * @param r the number of successes * @param p the probability of success */ public PascalDistributionImpl(int r, double p) { super(); setNumberOfSuccessesInternal(r); setProbabilityOfSuccessInternal(p); }
/** * Generates a random value from the {@link PascalDistributionImpl Pascal Distribution}. * This implementation uses {@link #nextInversionDeviate(IntegerDistribution) inversion} * to generate random values. * * @param r the number of successes of the Pascal distribution * @param p the probability of success of the Pascal distribution * @return random value sampled from the Pascal(r, p) distribution * @throws MathException if an error occurs generating the random value * @since 2.2 */ public int nextPascal(int r, double p) throws MathException { return nextInversionDeviate(new PascalDistributionImpl(r, p)); }
/** * For this distribution, X, this method returns P(X = x). * @param x the value at which the PMF is evaluated * @return PMF for this distribution */ public double probability(int x) { double ret; if (x < 0) { ret = 0.0; } else { ret = MathUtils.binomialCoefficientDouble(x + getNumberOfSuccesses() - 1, getNumberOfSuccesses() - 1) * Math.pow(getProbabilityOfSuccess(), getNumberOfSuccesses()) * Math.pow(1.0 - getProbabilityOfSuccess(), x); } return ret; }
/** * For this distribution, X, this method returns P(X ≤ x). * @param x the value at which the PDF is evaluated * @return PDF for this distribution * @throws MathException if the cumulative probability can not be computed * due to convergence or other numerical errors */ public double cumulativeProbability(int x) throws MathException { double ret; if (x < 0) { ret = 0.0; } else { ret = Beta.regularizedBeta(getProbabilityOfSuccess(), getNumberOfSuccesses(), x + 1); } return ret; }