Variances and Standard Deviations |
Variance and Standard deviation are measurements of variability or diversity widely used in statistics. It shows how much data elements vary from the average (mean, or expected value). A low standard deviation indicates that the data points tend to be very close to the mean, whereas high standard deviation indicates that the data are spread out over a large range of values.
Technically, the standard deviation of a statistical population or data set is the square root of its variance.
Be careful between the distinction of the population and sample variances (or standard deviations), as they have different definitions. You have to realize the difference between a sample and the population it was drawn from. There are separate methods to distinguish the population and sample variances. Variance method and VariancePopulation method are identical. For standard deviations there are also separate methods StandardDeviation, StandardDeviationPopulation and StandardDeviationSample, again StandardDeviation and StandardDeviationPopulation are identical.
Hereinafter the following convention is used:
denotes data container element, i = 0..n-1. For vector, array of doubles and array of nullable doubles denotes an array element or vector element.
Operation | Description | Performance |
---|---|---|
variance | Returns variance of the container's values. | |
sample variance | Returns sample variance of the container's values. VarianceSample(Vector, Boolean) | |
population variance | Returns population variance of the container's values. VariancePopulation(Vector, Boolean) | |
standard deviation | Returns standard deviation of the container's values. StandardDeviation(Vector, Boolean) | |
sample standard deviation | Returns sample standard deviation of the container's values. StandardDeviationSample(Vector, Boolean) | |
population standard deviation | Returns population standard deviation of the container's values. StandardDeviationPopulation(Vector, Boolean) StandardDeviationPopulation(IEnumerableDouble, Boolean) StandardDeviationPopulation(IEnumerableNullableDouble, Boolean) |
The example of variance and standard deviation calculation:
1using System; 2using FinMath.LinearAlgebra; 3using FinMath.Statistics; 4using FinMath.Statistics.Distributions; 5 6namespace FinMath.Samples 7{ 8 class VectorVariancesSample 9 { 10 static void Main() 11 { 12 // Input parameters. 13 const Int32 observationsCount = 10; 14 15 // Generate input vector. 16 Normal normalDistribution = new Normal(); 17 Vector vector = Vector.Random(observationsCount, normalDistribution); 18 Console.WriteLine("Input vector:"); 19 Console.WriteLine(" " + vector.ToString("0.000")); 20 21 // Calculate and output different types of statistics. 22 Console.WriteLine("Results:"); 23 Console.WriteLine(" Variance sample: " + vector.VarianceSample()); 24 Console.WriteLine(" Variance population: " + vector.VariancePopulation()); 25 // Note: this is exactly the same as population variance. 26 Console.WriteLine(" Variance: " + vector.Variance()); 27 Console.WriteLine(" Standard deviation sample: " + vector.StandardDeviationSample()); 28 Console.WriteLine(" Standard deviation population: " + vector.StandardDeviationPopulation()); 29 // Note: this is exactly the same as population standatd deviation. 30 Console.WriteLine(" Standard deviation: " + vector.StandardDeviation()); 31 } 32 } 33}