# 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);
``````
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
LVL 1
###### Who is Participating?

Commented:
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

Commented:
var =     (sum(  x - M)^2) / (n-1)
varp =  (sum(  x - M)^2) / n

where M  = Mean of the x population
0

Author Commented:
The question is:
How would I calculate a sample variance using Commons Math?
0

Commented:
M is the mean of the sample (the mean of the populataion being unknown
0
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.