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 (1) 

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 (2) 

VarianceAround works with 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 (2) 

VarianceAround applied to 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 can not be calculated for a list with a single element:

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

Neat Examples (1) 

Study the variance and its uncertainty for a sequence of values and compare it 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]=

Publisher

SHuisman

Version History

  • 1.0.0 – 26 June 2019

Source Metadata

License Information