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

Aggregation functions > sd

syntax

  • sd(values_attribute)
  • sd(values_attribute, relation)

description

The sd function calculates the standard deviation of the values in values_attribute.

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

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

The standard deviation is calculated as the square root of the variance:

sd = √(Σ(x - μ)² / n)

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

Note: This calculates the population standard deviation. For sample standard deviation (dividing by n-1 under the square root), use: sd(x) * sqrt(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, then square root).

since version

1.0

example

total standard deviation

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

parameter<float64> age_stddev := sd(Person/age);
// Result: 7.071... (≈ √50)

partitioned standard deviation

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_sd_per_region (Region) := sd(Person/salary, Person/region_rel);
// Result: [4082.48, 2867.44] (standard deviation per region)

see also

  • var - variance (square of standard deviation)
  • [standard deviance(sd)|standard deviance(sd)] - alternative documentation page
  • mean - arithmetic mean
  • covariance - covariance between two attributes

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

Clone this wiki locally