Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 49E78921F for ; Fri, 21 Oct 2011 08:52:16 +0000 (UTC) Received: (qmail 49453 invoked by uid 500); 21 Oct 2011 08:52:15 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 49147 invoked by uid 500); 21 Oct 2011 08:52:15 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 49138 invoked by uid 99); 21 Oct 2011 08:52:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Oct 2011 08:52:14 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.213.43] (HELO mail-yw0-f43.google.com) (209.85.213.43) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Oct 2011 08:52:07 +0000 Received: by ywm13 with SMTP id 13so5079002ywm.30 for ; Fri, 21 Oct 2011 01:51:46 -0700 (PDT) Received: by 10.236.129.165 with SMTP id h25mr20032874yhi.38.1319187106183; Fri, 21 Oct 2011 01:51:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.147.38.4 with HTTP; Fri, 21 Oct 2011 01:51:26 -0700 (PDT) In-Reply-To: <4EA13152.1040409@gmail.com> References: <4E9AE229.1040300@gmail.com> <4E9AF10D.1070901@gmail.com> <4E9B1315.4090905@gmail.com> <4EA13152.1040409@gmail.com> From: Mikkel Meyer Andersen Date: Fri, 21 Oct 2011 10:51:26 +0200 Message-ID: Subject: Re: [math] SummaryStatistics.setVarianceImpl Usage To: Commons Users List Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org Dear Warren, As far as I know, in [math] we have adopted the standard naming convention (as you seem to use yourself), which is: E[X^2]: second moment E[(X - E[X])^2]: central second moment And similar for higher orders moments. Cheers, Mikkel. 2011/10/21 Warren Tang : > The getSecondMoment does not return the real second central moment which > should be equal to variance. I think it is confusing and should be > stressed in the document. > > > On 10/17/2011 1:23 AM, Warren Tang wrote: >> Thanks for the workaround. I've reported the bug here: >> https://issues.apache.org/jira/browse/MATH-691 >> >> Regards, >> Warren Tang >> >> >> On Sunday, October 16, 2011 11:24:26 PM, Mikkel Meyer Andersen wrote: >>> Dear Warren, >>> >>> This is probably a bug. Sorry for this. Would you be so kind to report >>> it as described on http://commons.apache.org/math/issue-tracking.html >>> . >>> >>> What you can do instead is this: >>> int[] scores = {1, 2, 3, 4}; >>> >>> SummaryStatistics stats = new SummaryStatistics(); >>> for(int i : scores) { >>> stats.addValue(i); >>> } >>> double sd = FastMath.sqrt(stats.getSecondMoment() / stats.getN()); >>> >>> System.out.println(sd); >>> >>> So, calculating sd as: >>> double sd = FastMath.sqrt(stats.getSecondMoment() / stats.getN()); >>> >>> And then there is no need to stats.setVarianceImpl(new Variance(false)). >>> >>> Cheers, Mikkel. >>> >>> 2011/10/16 Warren Tang : >>>> Hi, Mikkel >>>> >>>> I'm using commons-math 2.2. The code to reproduce the issue. >>>> >>>> import org.apache.commons.math.stat.descriptive.SummaryStatistics; >>>> import org.apache.commons.math.stat.descriptive.moment.Variance; >>>> >>>> @Test public void testStandardDeviation() { >>>> int[] scores = {1, 2, 3, 4}; >>>> SummaryStatistics stats = new SummaryStatistics(); >>>> stats.setVarianceImpl(new Variance(false)); //use "population variance" >>>> for(int i : scores) { >>>> stats.addValue(i); >>>> } >>>> double sd = stats.getStandardDeviation(); >>>> System.out.println(sd); >>>> } >>>> >>>> Regards, >>>> Warren Tang >>>> >>>> On 10/16/2011 10:43 PM, Mikkel Meyer Andersen wrote: >>>>> >>>>> Dear Warren, >>>>> >>>>> Could you provide values for the scores-variable in the current >>>>> example making it possible to reproduce? >>>>> >>>>> Are you in fact using version 1.2 as reflected by the link you gave? >>>>> Or which version are you using? >>>>> >>>>> Cheers, Mikkel. >>>>> >>>>> 2011/10/16 Warren Tang: >>>>>> >>>>>> Hello, everyone >>>>>> >>>>>> I'm trying to get a "population standard deviation >>>>>> >>>>>> " >>>>>> >>>>>> (non-bias-corrected) from SummaryStatistics. >>>>>> >>>>>> This is what I did: >>>>>> >>>>>> SummaryStatistics stats = new SummaryStatistics(); >>>>>> stats.setVarianceImpl(new Variance(false)); //use "population >>>>>> variance" >>>>>> ( sum((x_i - mean)^2) / n ) >>>>>> for(int i : scores) { >>>>>> stats.addValue(i); >>>>>> } >>>>>> double sd = stats.getStandardDeviation(); >>>>>> >>>>>> However, the value of "sd" is "NaN". How can I do it correctly? >>>>>> >>>>>> -- >>>>>> Regards, >>>>>> Warren Tang >>>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >>>>> For additional commands, e-mail: user-help@commons.apache.org >>>>> >>>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >>> For additional commands, e-mail: user-help@commons.apache.org >>> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org