Reference · Statistics

stats.pvariance

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

What it does

The population variance of a list of numbers: the mean of the squared distances from the mean, dividing by the count. It is Python's statistics.pvariance, for data that is the whole population; for a sample use stats.variance, which divides by one less. The answer is a float, computed with the compensated sums Python's fractions give.

Examples

print(stats.pvariance([1, 2, 3, 4]))print(stats.pvariance([0.0, 0.25, 0.25, 1.25, 1.5, 1.75, 2.75, 3.25]))
output
1.251.25

Edge cases

print(stats.pvariance([5]), stats.pvariance([7, 7, 7]))print(stats.pvariance([1, 2, 3, 4], 0), stats.pvariance([1, 2, 3, 4], 2.5), stats.pvariance([1, 2, 3, 4], null))
output
0.0 0.01.25 1.25 1.25

Errors

No data is a runtime error, not an error value: an empty list or null stops the request. So does an item that is not a number, or a second argument that is not a number.

this one fails
print(stats.pvariance([]))
output
line 1: `stats.pvariance` requires at least one data point
this one fails
print(stats.pvariance([1, 2], "x"))
output
line 1: `stats.pvariance` expects a number as argument 2, got str

Chaining

print([2, 4, 4, 4, 5, 5, 7, 9] | stats.pvariance)print([2, 4, 4, 4, 5, 5, 7, 9] | stats.pvariance | math.sqrt)
output
4.02.0

See also

stats.variance, stats.pstdev, stats.stdev, stats.mean

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

Thread 0 posts

On stats.pvariance(): 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