![]() |
|
|
| |
|
||||
In statistics, a formula for calculating the variance of a population of size n is:
A formula for calculating the unbiased estimation of the population variance from n finite samples is:
The method of calculation may be more easily understood from the table below where the mean is 8.
Note: Details of the variance calculation: 338 = [52 + 72 + 82 + 102 + 102] AlgorithmTherefore a simple algorithm to calculate variance can be described by the following pseudocode: long n = 0; double sum = 0; double sum_sqr = 0; double variance; foreach x in data: n += 1; sum += x; sum_sqr += x*x; end for variance = (sum_sqr - sum*sum/n)/(n-1); AlgorithmAnother algorithm which avoids large numbers in sum_sqr while summing up double avg = 0; double var = 0; long n = data.length; // number of elements for i = 1 to n avg = (avg*i + data[i]) / (i + 1); var = (var * (i - 1) + (data[i] - avg)*(data[i] - avg)) / i; end for return var; // resulting variance
|
||||||||||||||||||||||||||||||||
|
|
|
|
|
|
Copyright 2008 WordIQ.com - Privacy Policy
::
Terms of Use
:: Contact Us
:: About Us This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article "Algorithms for calculating variance". |