Skip to content
Maarten Hilferink edited this page Apr 8, 2026 · 1 revision

Aggregation functions > var

syntax

  • var(values_attribute)
  • var(values_attribute, relation)

description

The var function calculates the variance of the values in values_attribute.

When called with a single argument, it calculates the total variance across all elements.

When called with a relation argument, it calculates the variance per group defined by the relation, producing a partitioned result.

The variance is calculated using the formula:

var = Σ(x - μ)² / n

where μ is the mean and n is the count of defined values.

Note: This calculates the population variance. For sample variance (dividing by n-1), use: var(x) * count(x) / (count(x) - 1).

applies to

conditions

  1. The values_attribute must have a numeric value type.
  2. If specified, relation must define a valid grouping.
  3. Null values in values_attribute are excluded from the calculation.

result

performance

aspect indication
time complexity O(n) where n = number of elements
memory O(1) for total, O(k) for partitioned where k = number of groups
parallelization tiled parallel processing supported

The calculation uses a numerically stable two-pass algorithm (first for mean, second for variance).

since version

1.0

example

total variance

unit<uint32> Person: nrofrows = 5
{
   attribute<float32> age: [25, 30, 35, 40, 45];
}

parameter<float64> age_variance := var(Person/age);
// Result: 50.0 (population variance)

partitioned variance

unit<uint32> Person: nrofrows = 6
{
   attribute<float32> salary: [50000, 55000, 60000, 45000, 48000, 52000];
   attribute<Region>  region_rel: [0, 0, 0, 1, 1, 1];
}

unit<uint32> Region: nrofrows = 2;

attribute<float64> salary_var_per_region (Region) := var(Person/salary, Person/region_rel);
// Result: [16666666.67, 8222222.22] (variance per region)

see also

  • sd - standard deviation (square root of variance)
  • mean - arithmetic mean
  • covariance - covariance between two attributes
  • correlation - correlation coefficient

GeoDMS ©Object Vision BV. Source code distributed under GNU GPL-3. Documentation distributed under CC BY-SA 4.0.

Clone this wiki locally