var

The var aggregate calculates the sample variance.

Synopsis

AFL% aggregate(array,var(attribute)[,dimension_1, ... ])
AQL% SELECT var(attribute) FROM array [ GROUP BY dimension_1 [ , dimension_2 ...  ] ];

Summary

The var aggregate returns the sample variance of a set of values. You can optionally specify one or more dimensions to group by. The sample variance of an empty set is NULL. The sample variance of a set that contains only NULL values is also NULL. If the set contains NULL and NOT NULL values, the var aggregate considers only NOT NULL values.

Example

To find the variance of every column of a 3×3 array, do the following:

  1. Create an array:

    AFL% CREATE ARRAY m3x3<val:double>[i=0:2; j=0:2];
  2. Put random values between 1 and 9 into m3x3:

    AFL% store(build(m3x3, random()%10/1.0), m3x3);  


    The output is:

    {i,j} val
    {0,0} 7
    {0,1} 4
    {0,2} 5
    {1,0} 3
    {1,1} 7
    {1,2} 8
    {2,0} 6
    {2,1} 0
    {2,2} 7
  3. Find the variance for each column of m3x3:

    AFL% aggregate(m3x3,var(val),j);


    The output is:

    {j} val_var
    {0} 4.33333
    {1} 12.3333
    {2} 2.33333
  4. Remove the array:

    AFL% remove(m3x3);