Wolfram Research

Function Repository Resource:

VarianceAround

Source Notebook

Calculate the variance of a list along with its uncertainty

Contributed by: Sander Huisman

ResourceFunction["VarianceAround"][{x1,x2,x3,}]

gives an Around object describing the variance of xi and its uncertainty.

Details and Options

The standard error of the variance is defined as: , 
where s2 represents the variance of the sample.
The “Value” of the Around object is calculated using the built-in Variance function.

Examples

Basic Examples

Calculate the variance of some numbers:

In[1]:=
ResourceFunction["VarianceAround"][{1.1, 2.2, 2.6, 1.4, 2.2, 2.3}]
Out[1]=

Scope

VarianceAround also works with (partially) symbolic expressions:

In[2]:=
ResourceFunction["VarianceAround"][{a, b, c, d}]
Out[2]=

VarianceAround also works with quantities with units:

In[3]:=
ResourceFunction[
 "VarianceAround"][{Quantity[1, "Meters"], Quantity[1.1, "Meters"], Quantity[0.98, "Meters"], Quantity[0.99, "Meters"]}]
Out[3]=

Possible Issues

VarianceAround with symbolic expressions can get unwieldy fast:

In[4]:=
ResourceFunction[
 "VarianceAround"][{a, b, c, d, e, f, g, h, i, j, k, l}]
Out[4]=

The variance cannot be calculated for a list with a single element:

In[5]:=
ResourceFunction["VarianceAround"][{1}]
Out[5]=

Neat Examples

Study the variance and its uncertainty for a sequence of values and compare to the theoretical value of the distribution:

In[6]:=
SeedRandom[3];
dist = NormalDistribution[2, 3];
vals = RandomVariate[dist, 10^6];
values = Table[{n, ResourceFunction["VarianceAround"][vals[[;; n]]]}, {n, Round[10^Range[2, 6, 1/8]]}];
ListLogLinearPlot[values, PlotRange -> {6, 12}, GridLines -> {{}, {Variance[dist]}}, GridLinesStyle -> Dashed, AxesLabel -> {"Number of values", "Estimate of the variance"}, ImageSize -> 500]
Out[10]=

Resource History

Source Metadata

License Information