Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 812797A47 for ; Tue, 29 Nov 2011 03:58:11 +0000 (UTC) Received: (qmail 16826 invoked by uid 500); 29 Nov 2011 03:58:09 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 16707 invoked by uid 500); 29 Nov 2011 03:58:08 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 16686 invoked by uid 99); 29 Nov 2011 03:58:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Nov 2011 03:58:04 +0000 X-ASF-Spam-Status: No, hits=-2001.2 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Nov 2011 03:58:01 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 22279A579B for ; Tue, 29 Nov 2011 03:57:40 +0000 (UTC) Date: Tue, 29 Nov 2011 03:57:40 +0000 (UTC) From: =?utf-8?Q?S=C3=A9bastien_Brisard_=28Created=29_=28JIRA=29?= To: issues@commons.apache.org Message-ID: <491908463.20964.1322539060141.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Created] (MATH-715) PascalDistribution returns wrong values of mean and variance MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org 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=C3=A9bastien Brisard The header of the Javadoc states that the random variable (say X) being rep= resented 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 t= he number of *successes*) : different formulas therefore apply for the mean= and variance of X. The javadoc should be made clearer, for example by incl= usion of full formulas. Also the parameters differing from the Wikipedia re= ference 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 success= es in CM. This could be renamed (say) {{s}}. Finally, with the current notations of CM, the mean of X is given by {{mean= (X) =3D r * (1 - p) / p}}, while the currently implemented formula is {{r *= p / (1 - p)}}, which is actually the formula corresponding to the Wikipedi= a 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 =3D 10; final double p =3D 0.2; final int numTerms =3D 1000; final PascalDistribution distribution =3D new PascalDistribution(r, = p); double mean =3D 0.; for (int k =3D numTerms - 1; k >=3D 0; k--) { mean +=3D k * distribution.probability(k); } // The following prints 40.00000000000012 System.out.println("Estimate of the mean =3D " + mean); // The following prints 2.5 System.out.println("CM implementation =3D " + distribution.getNumericalMean()); // The following prints 2.5 System.out.println("r * p / (1 - p) =3D " + (r * p / (1 - p))); // The following prints 40.0 System.out.println("r * (1 - p) / p =3D " + (r * (1 - p) / p)); } } {code} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrato= rs: https://issues.apache.org/jira/secure/ContactAdministrators!default.jsp= a For more information on JIRA, see: http://www.atlassian.com/software/jira