-
Notifications
You must be signed in to change notification settings - Fork 1
var
Aggregation functions > var
- var(values_attribute)
- var(values_attribute, relation)
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).
- attribute values_attribute with a numeric value type (Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64)
- attribute relation (optional) with a relation to the grouping domain
- The values_attribute must have a numeric value type.
- If specified, relation must define a valid grouping.
- Null values in values_attribute are excluded from the calculation.
- Without relation: a parameter with Float64 value type
- With relation: an attribute with Float64 value type and the domain of the relation's values unit
| 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).
1.0
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)
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)
- 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.
GeoDMS ©Object Vision BV. Source code distributed under GNU GPL-3. Documentation distributed under CC BY-SA 4.0.