Reference · Statistics

stats.stdev

signature
stats.stdev(list, num | null=) -> float

What it does

The sample standard deviation of a list of numbers: the square root of stats.variance, as Python's statistics.stdev. It is the std that stats.describe reports. For the whole population use stats.pstdev.

Examples

print(stats.stdev([1, 2, 3, 4]))print(stats.stdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75]))
output
1.29099444873580561.0810874155219827

Edge cases

print(stats.stdev([7, 7, 7]), stats.stdev([1, 2], 1.5), stats.stdev([1, 2], null))print(stats.stdev([1, 2, 3, 4]) == math.sqrt(stats.variance([1, 2, 3, 4])))print(stats.stdev([1, 2, 3, 4]) == stats.describe([1, 2, 3, 4]).std)
output
0.0 0.7071067811865476 0.7071067811865476truetrue

Errors

Fewer than two numbers is a runtime error, not an error value: an empty list, null or a list of one stops the request. So does an item that is not a number.

this one fails
print(stats.stdev([5]))
output
line 1: `stats.stdev` requires at least 2 data points

Chaining

let xs = [2, 4, 4, 4, 5, 5, 7, 9]print(xs | stats.stdev | round(3))let m = stats.mean(xs)let s = stats.stdev(xs)print(xs | filter((x) => x > m + s))
output
2.138[9]

See also

stats.pstdev, stats.variance, stats.describe, stats.zscore

Thread
6Useful? Like it, or add to its thread below.

Thread 0 posts

On stats.stdev(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo