Data and Math

vstats

Mean, median, variance, correlation, percentiles and least squares lines.

Released v1.0.0 · 2026-09-28
Import
use "stdlib/stats.ven"
vstats.ven
print mean([2, 4, 4, 4, 5, 5, 7, 9])
:: 5.0
Reference (14 functions)

API reference

mean(values)

Gives back the arithmetic mean of values.

mean([2, 4, 4, 4, 5, 5, 7, 9])
:: 5.0

median(values)

Gives back the median (middle value) of values.

median([2, 4, 4, 4, 5, 5, 7, 9])
:: 4.5
median([1, 2, 3])
:: 2

mode(values)

Gives back every value tied for the highest occurrence count in values.

mode([1, 2, 2, 3, 3])
:: [2, 3]

variance(values)

Gives back the population variance of values.

variance([2, 4, 4, 4, 5, 5, 7, 9])
:: 4.0

stdev(values)

Gives back the population standard deviation of values.

stdev([2, 4, 4, 4, 5, 5, 7, 9])
:: 2.0

covariance(a, b)

Gives back the population covariance between a and b.

covariance([1, 2, 3, 4], [2, 4, 6, 8])
:: 2.5

correlation(a, b)

Gives back the Pearson correlation coefficient between a and b.

correlation([1, 2, 3, 4], [2, 4, 6, 8])
:: 0.9999999999999998

percentile(values, p)

Gives back the linear-interpolation percentile p of values.

percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 90)
:: 9.1

quartiles(values)

Gives back the first, second, and third quartiles of values as a Tuple.

quartiles([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
:: (3.25, 5.5, 7.75)

z_score(value, mean_value, stdev_value)

Gives back how many standard deviations value sits from mean_value.

z_score(85, 70, 10)
:: 1.5

linear_regression(x, y)

Fits an ordinary-least-squares line through the points (x[i], y[i]).

linear_regression([1, 2, 3, 4], [2, 4, 6, 8])
:: (2.0, 0.0, 1.0)

histogram(values, bucket_count)

Buckets values into bucket_count equal-width histogram bins.

histogram([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)
:: [(1.0, 4.0, 3), (4.0, 7.0, 3), (7.0, 10.0, 4)]

moving_average(values, window)

Gives back the sliding-window average of values over the given window size.

moving_average([1, 2, 3, 4, 5], 3)
:: [2.0, 3.0, 4.0]

outliers_iqr(values)

outliers_iqr([1, 2, 2, 3, 3, 3, 4, 4, 100])
:: [100]

Get notified when vstats changes

Get notified about

New versions and security advisories.

New and updated packages, once a day.

News on the math model built in Venutian.