Concept

Algorithms for calculating variance

Summary
Algorithms for calculating variance play a major role in computational statistics. A key difficulty in the design of good algorithms for this problem is that formulas for the variance may involve sums of squares, which can lead to numerical instability as well as to arithmetic overflow when dealing with large values. Naïve algorithm A formula for calculating the variance of an entire population of size N is: :\sigma^2 = \overline{(x^2)} - \bar x^2 = \frac {\sum_{i=1}^N x_i^2 - (\sum_{i=1}^N x_i)^2/N}{N}. Using Bessel's correction to calculate an unbiased estimate of the population variance from a finite sample of n observations, the formula is: :s^2 = \left(\frac {\sum_{i=1}^n x_i^2} n - \left( \frac {\sum_{i=1}^n x_i} n \right)^2\right) \cdot \frac {n}{n-1}. Therefore, a naïve algorithm to calculate the estimated variance is given by the following:
  • Let n ← 0, Sum ← 0, SumSq ← 0
  • For each datum x: ** n ← n + 1 ** Sum ← Sum + x
About this result
This page is automatically generated and may contain information that is not correct, complete, up-to-date, or relevant to your search query. The same applies to every other page on this website. Please make sure to verify the information with EPFL's official sources.
Related publications

Loading

Related people

Loading

Related units

Loading

Related concepts

Loading

Related courses

Loading

Related lectures

Loading