You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Warren Tang <wa...@gmail.com> on 2011/10/16 15:54:49 UTC

[math] SummaryStatistics.setVarianceImpl Usage

Hello, everyone

I'm trying to get a "population standard deviation
<http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
(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 <http://blog.tangcs.com>

Re: [math] SummaryStatistics.setVarianceImpl Usage

Posted by Warren Tang <wa...@gmail.com>.
Let's see your workaround:
    double populationStandardDeviation = 
FastMath.sqrt(stats.getSecondMoment() / stats.getN());
Another way to compute the same standard deviation is:
   double samePopulationStandardDeviation = FastMath.sqrt(new 
Variance(false).evaluate(scores));
We can infer from previous two statements that in [math]:
  stats.getSecondMoment() / stats.getN() = new 
Variance(false).evaluate(scores)  = sum((x_i - mean)^2) / n ;

But this is not the convention 
<http://en.wikipedia.org/wiki/Second_moment#Variance>that the second 
central moment is equal to variance, i.e. "sum((x_i - mean)^2) / n".

In a word, the return value of "SummaryStatistics.getSecondMoment" is 
only the "sum((x_i - mean)^2)" without being divided by N; So it is not 
the *expected value*,  as the document of " states:
"Returns a statistic related to the Second Central Moment. Specifically, 
what is returned is the sum of squared deviations from the sample mean 
among the values that have been added."

Regards,
Warren Tang <http://blog.tangcs.com>

On 10/21/2011 4:51 PM, Mikkel Meyer Andersen wrote:
> 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<wa...@gmail.com>:
>> 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<http://blog.tangcs.com>
>>>
>>>
>>> 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<wa...@gmail.com>:
>>>>> 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<http://blog.tangcs.com>
>>>>>
>>>>> 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<wa...@gmail.com>:
>>>>>>> Hello, everyone
>>>>>>>
>>>>>>> I'm trying to get a "population standard deviation
>>>>>>>
>>>>>>> <http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
>>>>>>>
>>>>>>> (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<http://blog.tangcs.com>
>>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> 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
>

Re: [math] SummaryStatistics.setVarianceImpl Usage

Posted by Mikkel Meyer Andersen <mi...@mikl.dk>.
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 <wa...@gmail.com>:
> 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 <http://blog.tangcs.com>
>>
>>
>> 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 <wa...@gmail.com>:
>>>> 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 <http://blog.tangcs.com>
>>>>
>>>> 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<wa...@gmail.com>:
>>>>>>
>>>>>> Hello, everyone
>>>>>>
>>>>>> I'm trying to get a "population standard deviation
>>>>>>
>>>>>> <http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
>>>>>>
>>>>>> (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<http://blog.tangcs.com>
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> 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


Re: [math] SummaryStatistics.setVarianceImpl Usage

Posted by Phil Steitz <ph...@gmail.com>.
On 10/21/11 1:46 AM, Warren Tang wrote:
> 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.

That is a good point. The javadoc for SecondMoment points this out,
saying it "Computes a statistic related to the Second Central
Moment" and then presents the formula used. I would be +0 for making
SecondMoment, ThirdMoment and FourthMoment have package scope (i.e.,
removing them from the public API) because they are nonstandard and
really only there to be used by the updating formulas for Variance,
Skewness and Kurtosis.

Phil
>
>
> 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 <http://blog.tangcs.com>
>>
>>
>> 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 <wa...@gmail.com>:
>>>> 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 <http://blog.tangcs.com>
>>>>
>>>> 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<wa...@gmail.com>:
>>>>>> Hello, everyone
>>>>>>
>>>>>> I'm trying to get a "population standard deviation
>>>>>>
>>>>>> <http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
>>>>>>
>>>>>> (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<http://blog.tangcs.com>
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> 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


Re: [math] SummaryStatistics.setVarianceImpl Usage

Posted by Warren Tang <wa...@gmail.com>.
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 <http://blog.tangcs.com>
>
>
> 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 <wa...@gmail.com>:
>>> 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 <http://blog.tangcs.com>
>>>
>>> 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<wa...@gmail.com>:
>>>>>
>>>>> Hello, everyone
>>>>>
>>>>> I'm trying to get a "population standard deviation
>>>>>
>>>>> <http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
>>>>>
>>>>> (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<http://blog.tangcs.com>
>>>>>
>>>> ---------------------------------------------------------------------
>>>> 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


Re: [math] SummaryStatistics.setVarianceImpl Usage

Posted by Warren Tang <wa...@gmail.com>.
Thanks for the workaround. I've reported the bug here: 
https://issues.apache.org/jira/browse/MATH-691

Regards,
Warren Tang <http://blog.tangcs.com>


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 <wa...@gmail.com>:
>> 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 <http://blog.tangcs.com>
>>
>> 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<wa...@gmail.com>:
>>>>
>>>> Hello, everyone
>>>>
>>>> I'm trying to get a "population standard deviation
>>>>
>>>> <http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
>>>> (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<http://blog.tangcs.com>
>>>>
>>> ---------------------------------------------------------------------
>>> 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


Re: [math] SummaryStatistics.setVarianceImpl Usage

Posted by Phil Steitz <ph...@gmail.com>.
On 10/16/11 10:55 AM, Warren Tang wrote:
> I've manually calculated it (1.1180339887498948482045868343656).
> So Mikkel's is right.

Thanks for reporting this.  This points to another bug.  Ugh.  I
will open it.

Phil
>
> Regards,
> Warren Tang <http://blog.tangcs.com>
>
> On 10/17/2011 1:49 AM, Warren Tang wrote:
>> Hi, Phil
>>
>> Your workaround does not work. Switching the value of
>> isBiasCorrected between true and false produces the same standard
>> deviation (1.2909944487358056), which is different from the
>> result of Mikkel's formula (1.118033988749895).
>>
>> Regards,
>> Warren Tang <http://blog.tangcs.com>
>>
>> On 10/17/2011 1:20 AM, Phil Steitz wrote:
>>> On 10/16/11 8:24 AM, Mikkel Meyer Andersen wrote:
>>>> Dear Warren,
>>>>
>>>> This is probably a bug. Sorry for this. Would you be so kind to
>>>> report
>>>> it as described
>>>> onhttp://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)).
>>> Yes, this is a bug.  Lets track it.  The problem is that the
>>> code is
>>> using instanceOf check to identify overridden impls, which fails in
>>> this case.  This needs to be fixed.
>>>
>>> Another workaround that should work is to get the default variance
>>> impl and set its biasCorrected property:
>>>
>>> SummaryStatistics stats = new SummaryStatistics();
>>> Variance variance = (Variance) stats.getVarianceImpl();
>>> variance.setBiasCorrected(false);
>>>
>>> then just use the stats instance directly and the reported variance
>>> should be non-bias-corrected.
>>>
>>> Phil
>>>> Cheers, Mikkel.
>>>>
>>>> 2011/10/16 Warren Tang<wa...@gmail.com>:
>>>>> 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<http://blog.tangcs.com>
>>>>>
>>>>> 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<wa...@gmail.com>:
>>>>>>> Hello, everyone
>>>>>>>
>>>>>>> I'm trying to get a "population standard deviation
>>>>>>>
>>>>>>> <http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
>>>>>>>
>>>>>>> (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<http://blog.tangcs.com>
>>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>>
>>>>>> 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


Re: [math] SummaryStatistics.setVarianceImpl Usage

Posted by Warren Tang <wa...@gmail.com>.
I've manually calculated it (1.1180339887498948482045868343656). So 
Mikkel's is right.

Regards,
Warren Tang <http://blog.tangcs.com>

On 10/17/2011 1:49 AM, Warren Tang wrote:
> Hi, Phil
>
> Your workaround does not work. Switching the value of isBiasCorrected 
> between true and false produces the same standard deviation 
> (1.2909944487358056), which is different from the result of Mikkel's 
> formula (1.118033988749895).
>
> Regards,
> Warren Tang <http://blog.tangcs.com>
>
> On 10/17/2011 1:20 AM, Phil Steitz wrote:
>> On 10/16/11 8:24 AM, Mikkel Meyer Andersen wrote:
>>> Dear Warren,
>>>
>>> This is probably a bug. Sorry for this. Would you be so kind to report
>>> it as described onhttp://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)).
>> Yes, this is a bug.  Lets track it.  The problem is that the code is
>> using instanceOf check to identify overridden impls, which fails in
>> this case.  This needs to be fixed.
>>
>> Another workaround that should work is to get the default variance
>> impl and set its biasCorrected property:
>>
>> SummaryStatistics stats = new SummaryStatistics();
>> Variance variance = (Variance) stats.getVarianceImpl();
>> variance.setBiasCorrected(false);
>>
>> then just use the stats instance directly and the reported variance
>> should be non-bias-corrected.
>>
>> Phil
>>> Cheers, Mikkel.
>>>
>>> 2011/10/16 Warren Tang<wa...@gmail.com>:
>>>> 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<http://blog.tangcs.com>
>>>>
>>>> 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<wa...@gmail.com>:
>>>>>> Hello, everyone
>>>>>>
>>>>>> I'm trying to get a "population standard deviation
>>>>>>
>>>>>> <http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
>>>>>> (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<http://blog.tangcs.com>
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>

Re: [math] SummaryStatistics.setVarianceImpl Usage

Posted by Warren Tang <wa...@gmail.com>.
Hi, Phil

Your workaround does not work. Switching the value of isBiasCorrected 
between true and false produces the same standard deviation 
(1.2909944487358056), which is different from the result of Mikkel's 
formula (1.118033988749895).

Regards,
Warren Tang <http://blog.tangcs.com>

On 10/17/2011 1:20 AM, Phil Steitz wrote:
> On 10/16/11 8:24 AM, 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)).
> Yes, this is a bug.  Lets track it.  The problem is that the code is
> using instanceOf check to identify overridden impls, which fails in
> this case.  This needs to be fixed.
>
> Another workaround that should work is to get the default variance
> impl and set its biasCorrected property:
>
> SummaryStatistics stats = new SummaryStatistics();
> Variance variance = (Variance) stats.getVarianceImpl();
> variance.setBiasCorrected(false);
>
> then just use the stats instance directly and the reported variance
> should be non-bias-corrected.
>
> Phil
>> Cheers, Mikkel.
>>
>> 2011/10/16 Warren Tang<wa...@gmail.com>:
>>> 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<http://blog.tangcs.com>
>>>
>>> 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<wa...@gmail.com>:
>>>>> Hello, everyone
>>>>>
>>>>> I'm trying to get a "population standard deviation
>>>>>
>>>>> <http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
>>>>> (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<http://blog.tangcs.com>
>>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>

Re: [math] SummaryStatistics.setVarianceImpl Usage

Posted by Phil Steitz <ph...@gmail.com>.
On 10/16/11 8:24 AM, 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)).

Yes, this is a bug.  Lets track it.  The problem is that the code is
using instanceOf check to identify overridden impls, which fails in
this case.  This needs to be fixed.

Another workaround that should work is to get the default variance
impl and set its biasCorrected property:

SummaryStatistics stats = new SummaryStatistics();
Variance variance = (Variance) stats.getVarianceImpl();
variance.setBiasCorrected(false);

then just use the stats instance directly and the reported variance
should be non-bias-corrected.

Phil
>
> Cheers, Mikkel.
>
> 2011/10/16 Warren Tang <wa...@gmail.com>:
>> 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 <http://blog.tangcs.com>
>>
>> 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<wa...@gmail.com>:
>>>> Hello, everyone
>>>>
>>>> I'm trying to get a "population standard deviation
>>>>
>>>> <http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
>>>> (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<http://blog.tangcs.com>
>>>>
>>> ---------------------------------------------------------------------
>>> 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


Re: [math] SummaryStatistics.setVarianceImpl Usage

Posted by Mikkel Meyer Andersen <mi...@mikl.dk>.
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 <wa...@gmail.com>:
> 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 <http://blog.tangcs.com>
>
> 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<wa...@gmail.com>:
>>>
>>> Hello, everyone
>>>
>>> I'm trying to get a "population standard deviation
>>>
>>> <http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
>>> (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<http://blog.tangcs.com>
>>>
>> ---------------------------------------------------------------------
>> 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


Re: [math] SummaryStatistics.setVarianceImpl Usage

Posted by Warren Tang <wa...@gmail.com>.
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 <http://blog.tangcs.com>

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<wa...@gmail.com>:
>> Hello, everyone
>>
>> I'm trying to get a "population standard deviation
>> <http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
>> (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<http://blog.tangcs.com>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

Re: [math] SummaryStatistics.setVarianceImpl Usage

Posted by Mikkel Meyer Andersen <mi...@mikl.dk>.
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 <wa...@gmail.com>:
> Hello, everyone
>
> I'm trying to get a "population standard deviation
> <http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.html>"
> (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 <http://blog.tangcs.com>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org