[ https://issues.apache.org/jira/browse/MATH-715?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sébastien Brisard resolved MATH-715.
------------------------------------
Resolution: Fixed
Fix Version/s: 3.0
Fixed in {{r1210359}}.
> PascalDistribution returns wrong values of mean and variance
> ------------------------------------------------------------
>
> Key: MATH-715
> URL: https://issues.apache.org/jira/browse/MATH-715
> Project: Commons Math
> Issue Type: Bug
> Reporter: Sébastien Brisard
> Assignee: Sébastien Brisard
> Fix For: 3.0
>
>
> 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
> {code:java}
> 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));
> }
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira