?
Solved

Commons Math - Variance

Posted on 2011-09-21
4
Medium Priority
?
1,034 Views
Last Modified: 2012-05-12
The attached spreadsheet has a dataset of: 2,4,6,8,10,12
The following excel functions give results:

VAR:      14
VARP:      11.66666667

Then In Java, if I code like so:
org.apache.commons.math.stat.descriptive.moment.Variance variance = new Variance();
double sigma = variance.evaluate(myDoubleArray);

Open in new window

where myDoubleArray contains 2.0, 4.0, 6.0, 8.0, 10.0, 12.0
then sigma is 14.0.
So I would conclude that the variance calculated by Commons Math is a sample variance not a population variance.

How would I calculate a sample variance using Commons Math?



standardDeviation.xlsx
0
Comment
Question by:allelopath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 36576153
var =     (sum(  x - M)^2) / (n-1)
varp =  (sum(  x - M)^2) / n

where M  = Mean of the x population
0
 
LVL 1

Author Comment

by:allelopath
ID: 36576246
The question is:
How would I calculate a sample variance using Commons Math?
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 36576310
just apply the formulas above...

if VAR is sum of squares divided by n-1, then multiply by n-1 and then divide by n to get VARP


variance.evaluate(myDoubleArray) * ( myDoubleArray.length - 1) / myDoubleArray.length
0
 
LVL 27

Expert Comment

by:aburr
ID: 36576322
M is the mean of the sample (the mean of the populataion being unknown
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question