Data and Math
vstats
Mean, median, variance, correlation, percentiles and least squares lines.
Released v1.0.0 · 2026-09-28use "stdlib/stats.ven"
print mean([2, 4, 4, 4, 5, 5, 7, 9])
:: 5.0
Reference (14 functions)
API reference
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])
:: 2mode(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.0stdev(values)
Gives back the population standard deviation of values.
stdev([2, 4, 4, 4, 5, 5, 7, 9])
:: 2.0covariance(a, b)
Gives back the population covariance between a and b.
covariance([1, 2, 3, 4], [2, 4, 6, 8])
:: 2.5correlation(a, b)
Gives back the Pearson correlation coefficient between a and b.
correlation([1, 2, 3, 4], [2, 4, 6, 8])
:: 0.9999999999999998percentile(values, p)
Gives back the linear-interpolation percentile p of values.
percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 90)
:: 9.1quartiles(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.5linear_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]