# commons-issues mailing list archives

##### Site index · List index
Message view
Top
From Sébastien Brisard (Created) (JIRA) <j...@apache.org>
Subject [jira] [Created] (MATH-715) PascalDistribution returns wrong values of mean and variance
Date Tue, 29 Nov 2011 03:57:40 GMT
```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

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.