I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 0.50
sub units 0.50
+
0

Variance

viewed 2278 times and licensed 44 times
Calculates the variance of a given set of data.
Controller: CodeCogs

Dependents

Info

Interface

C++

Variance

 
template<class T> doublevarianceintn
T*data
booltotal = false )
Consider a discrete random variable \inline X. The variance \inline  X of is defined as

Note that \inline (X-E[X])^2 is a new random variable (it's a function of \inline X ). The variance is also denoted as \inline \sigma^2. A useful formula that follows inmediately from the definition is that

In words, the variance of \inline  X is the second moment of \inline X minus the first moment squared. The variance of a random variable determines a level of variation of the possible values of \inline X around its mean. However, as this measure is squared, the standard deviation is used instead when one wants to talk about how much a random variable varies around its expected value.

If we cannot analyze a whole population but we have to take a sample, we define its variance (denoted as \inline s^2) with the formula:

where \inline  \overline{x} is the aritmetic mean . The value for \inline s^2 is an estimator for \inline \sigma. \[]

If the value of the boolean argument <em> total </em> is true, then the variance is computed using the following formula:

References:

PlanetMath, http:planetmath.org/encyclopedia/Variance.html

Example 1

#include <codecogs/statistics/moments/variance.h>
#include <iostream>
int main()
 {
   int x[5] = {3 , 1 , 5 , 6 , 9};
   double var = Statistics::Moments::variance<int>(5, x);
   std::cout << "The population variance is: " << var << std::endl;
   return 0;
 }
Output:
The population variance is: 9.2

Parameters

nthe size of the population
datathe actual population data given as an array
totalDefault value = false

Returns

return value the variance of the given set of data

Authors

Anca Filibiu (August 2005)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.