Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
The header of the Javadoc states that the random variable (say X) being represented by this o.a.c.m.distribution.PascalDistribution is the number of failures. The current Javadoc is slightly confusing, because it refers to the Wikipedia website, where the opposite convention is adopted (X is the number of successes) : different formulas therefore apply for the mean and variance of X. The javadoc should be made clearer, for example by inclusion of full formulas. Also the parameters differing from the Wikipedia reference should not have the same name
- p is the probability of success in both cases: OK,
- r is the number of failures in Wikipedia, but the number of successes in CM. This could be renamed (say) s.
Finally, with the current notations of CM, the mean of X is given by mean(X) = r * (1 - p) / p, while the currently implemented formula is r * p / (1 - p), which is actually the formula corresponding to the Wikipedia convention.
The following piece of code shows that the current implementation is faulty
public class PascalDistributionDemo { public static void main(String[] args) { final int r = 10; final double p = 0.2; final int numTerms = 1000; final PascalDistribution distribution = new PascalDistribution(r, p); double mean = 0.; for (int k = numTerms - 1; k >= 0; k--) { mean += k * distribution.probability(k); } // The following prints 40.00000000000012 System.out.println("Estimate of the mean = " + mean); // The following prints 2.5 System.out.println("CM implementation = " + distribution.getNumericalMean()); // The following prints 2.5 System.out.println("r * p / (1 - p) = " + (r * p / (1 - p))); // The following prints 40.0 System.out.println("r * (1 - p) / p = " + (r * (1 - p) / p)); } }