• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1051
  • Last Modified:

Commons Math - Variance

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?

  • 2
1 Solution
var =     (sum(  x - M)^2) / (n-1)
varp =  (sum(  x - M)^2) / n

where M  = Mean of the x population
allelopathAuthor Commented:
The question is:
How would I calculate a sample variance using Commons Math?
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
M is the mean of the sample (the mean of the populataion being unknown
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now