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<warren.c.tang@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
>
|