Click or drag to resize

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:

DSxi denotes data container element, i = 0..n-1. For vector, array of doubles and array of nullable doubles DSxi denotes an array element or vector element.

Methods

Operation

Description

Performance

variance

Returns variance of the container's values.

DSVariance

StaticVariance(Vector, Boolean)

StaticVariance(IEnumerableDouble, Boolean)

StaticVariance(IEnumerableNullableDouble, Boolean)

sample variance

Returns sample variance of the container's values.

DSSample Var

StaticVarianceSample(Vector, Boolean)

StaticVarianceSample(IEnumerableDouble, Boolean)

StaticVarianceSample(IEnumerableNullableDouble, Boolean)

population variance

Returns population variance of the container's values.

DSPop Var

StaticVariancePopulation(Vector, Boolean)

StaticVariancePopulation(IEnumerableDouble, Boolean)

StaticVariancePopulation(IEnumerableNullableDouble, Boolean)

standard deviation

Returns standard deviation of the container's values.

DSStd Deviation

StaticStandardDeviation(Vector, Boolean)

StaticStandardDeviation(IEnumerableDouble, Boolean)

StaticStandardDeviation(IEnumerableNullableDouble, Boolean)

sample standard deviation

Returns sample standard deviation of the container's values.

DSSample Std Dev

StaticStandardDeviationSample(Vector, Boolean)

StaticStandardDeviationSample(IEnumerableDouble, Boolean)

StaticStandardDeviationSample(IEnumerableNullableDouble, Boolean)

population standard deviation

Returns population standard deviation of the container's values.

DSPop Std Dev

StaticStandardDeviationPopulation(Vector, Boolean)

StaticStandardDeviationPopulation(IEnumerableDouble, Boolean)

StaticStandardDeviationPopulation(IEnumerableNullableDouble, Boolean)

Code Sample

The example of variance and standard deviation calculation:

C#
 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}

See Also