Statistics

functions and helpers for working with statistics and samples


Functions


The Statistics module provides essential functions for statistical analysis of numerical data. From basic averages to more complex statistical measures like variance and kurtosis, it offers everything you need for common statistical operations.

Key Concepts

  • Works with collections of numbers (blocks and ranges)
  • Supports both population and sample statistics
  • All operations handle integer, floating and rational numbers
  • Results are always returned as floating-point numbers for maximum precision

Basic Usage

Getting Averages and Medians

data: [1 2 3 5 7]

avg: average data     ; => 3.6
med: median data      ; => 3

; works with ranges too!
print average 1..100  ; 50.5

Note
average and median both require the data to be numeric. For mixed data types, make sure to filter non-numeric values first.

Calculating Variance and Standard Deviation

numbers: [2 4 4 4 5 5 7 9]

; population statistics (default)
print deviation numbers      ; 2.0
print variance numbers       ; 4.0

; sample statistics
print deviation.sample numbers  ; 2.138089935299395
print variance.sample numbers   ; 4.571428571428571

Tip
Use sample statistics (with the .sample attribute) when working with data that represents a subset of a larger population.

Distribution Analysis

data: [1 2 2 3 3 3 4 4 5]

; check how the distribution leans
print round.to:3 skewness data         ; 0.0    (symmetric)
print round.to:3 kurtosis data         ; -0.75  (platykurtic)

; for sample data
print round.to:3 skewness.sample data  ; 0.0
print round.to:3 kurtosis.sample data  ; -0.286

Common Patterns

Basic Statistical Summary

A common task is getting a quick overview of your data:

data: [12 15 18 22 25 28 32]

print ["Average:" average data]
print ["Deviation: ±" deviation data]
print ["Range:" min data ".." max data]

Outlier Detection

Using standard deviations to find potential outliers:

scores: [75 78 82 85 85 86 89 91 92 97 98 135]
avg: average scores
dev: deviation scores

loop scores 'score [
    if (abs score - avg) > 2 * dev ->
        print ["Possible outlier:" score]
]