Function Repository Resource:

PooledVariance

Source Notebook

Compute the pooled variance of multiple lists of data

Contributed by: Seth J. Chandler

ResourceFunction["PooledVariance"][{l1,l2,}]

computes a weighted sum of the variances of each list li in which the weights are proportionate to the lengths of the constituent lists minus one.

Details and Options

ResourceFunction["PooledVariance"] will not evaluate unless each list li has length greater than 1.

Examples

Basic Examples (2) 

Compute the pooled variance of two lists of data, one of which has three values and variance of 4, and the other of which has four values and a variance of 15:

In[1]:=
ResourceFunction["PooledVariance"][{{2, 4, 6}, {3, 6, 9, 12}}]
Out[1]=

Compute the pooled variance of symbolic data, assuming that the elements of the data are real:

In[2]:=
ResourceFunction[
   "PooledVariance"][{Array[x, {2}], Array[y, {3}], Array[z, 4]}] /. Conjugate[n_] :> n // FullSimplify
Out[2]=

Scope (3) 

PooledVariance can work on collections of any finite length:

In[3]:=
ResourceFunction[
 "PooledVariance"][{{12, 14, 16}, {1, 20, 3, 6, 15, 16, 17}, {14, 3, 10, 15, 13}, {11, 7}, {11, 19, 18, 5, 7, 5, 3}}]
Out[3]=

PooledVariance can work on complex values:

In[4]:=
ResourceFunction[
 "PooledVariance"][{{-2 I, -3 - 5 I, -2 + 5 I}, {-5 - 3 I, -2 + 3 I, -4 - 2 I, -1}}]
Out[4]=

PooledVariance can work on symbolic values:

In[5]:=
ResourceFunction["PooledVariance"][{{a, b, c}, {d, e, f, g, h}}]
Out[5]=

Applications (1) 

Compute Hedge’s g statistic, which makes use of the square root of a pooled variance to measure the effect size for the difference between means:

In[6]:=
With[{data = {{2, 4, 6}, {3, 6, 9, 12}}}, Abs[{1, -1} . Mean /@ data/
  Sqrt[ResourceFunction["PooledVariance"][data]]]]
Out[6]=

Properties and Relations (2) 

One can compute the pooled standard deviation by taking the square root of the pooled variance:

In[7]:=
Sqrt[ResourceFunction["PooledVariance"][{{2, 4, 6}, {3, 6, 9, 12}}]]
Out[7]=

The same value can also be computed using the resource function PooledStandardDeviation:

In[8]:=
ResourceFunction[
  "PooledStandardDeviation"][{{2, 4, 6}, {3, 6, 9, 12}}]
Out[8]=

The pooled variance of a collection is not the same as the variance of the flattened collection, even if the lengths of all the elements of the collection are the same:

In[9]:=
With[{data = {{1, 2, 3}, {1, 2, 3}}}, {ResourceFunction[
   "PooledVariance"][data], Variance[Flatten[data]]}]
Out[9]=

Possible Issues (1) 

PooledVariance will not evaluate unless each inner list has a length greater than 1:

In[10]:=
ResourceFunction["PooledVariance"][{{1}, {2, 3, 4}}]
Out[10]=

Publisher

Seth J. Chandler

Version History

  • 1.0.0 – 13 December 2019

Related Resources

License Information