@std/math/statistics.ms#
Import each required symbol with import Name from "@std/math/statistics.ms".
BinCounts Type#
Equal-width counts over a range of values, from bin_counts.
(@std/data/histogram.ms has the recording Histogram.)
type BinCounts {
low Float
high Float
counts List[Int]
}BinCounts.counts#
The number of values in each bin; the last bin includes high.
counts List[Int]BinCounts.high#
The greatest value counted, which is the upper edge of the last bin.
high FloatBinCounts.low#
The least value counted, which is the lower edge of the first bin.
low FloatRegression Type#
The least-squares line y = slope * x + intercept fitted by linear_regression.
type Regression {
slope Float
intercept Float
}Regression.intercept#
The value of y at x = 0.
intercept FloatRegression.slope#
The change in y per unit of x.
slope Floatbin_counts Function#
Counts the values into bins equal-width bins between the least and greatest value, or returns null for an empty list or a bins below 1.
Values equal to the greatest value fall in the last bin, so an infinite greatest value does. When every value is equal they all fall in the first bin.
When the range is infinite, the finite values fall in the first bin.
Example: if bins := bin_counts([1.0, 2.0, 2.0, 3.0], 2): print(bins.counts) prints [1, 3].
fn bin_counts(values List[Float], bins Int) BinCounts? { ... }correlation Function#
Returns the Pearson correlation of paired values, from -1.0 to 1.0, or null when there are fewer than two pairs or either list has no spread.
Lists of different lengths return null.
Example: correlation([1.0, 2.0, 3.0], [2.0, 4.0, 6.0]) is 1.0.
fn correlation(xs List[Float], ys List[Float]) Float? { ... }linear_regression Function#
Returns the least-squares line through paired values, or null when there are fewer than two pairs or the xs are all equal.
Lists of different lengths return null.
Example: linear_regression([1.0, 2.0, 3.0], [3.0, 5.0, 7.0]) has slope 2.0 and intercept 1.0.
fn linear_regression(xs List[Float], ys List[Float]) Regression? { ... }mean Function#
Returns the arithmetic mean, or null for an empty list.
Example: mean([1.0, 2.0, 6.0]) is 3.0.
fn mean(values List[Float]) Float? { ... }median Function#
Returns the median, the middle value of the sorted list or the mean of the two middle
values, or null for an empty list. Example: median([5.0, 1.0, 3.0, 2.0]) is 2.5.
fn median(values List[Float]) Float? { ... }mode Function#
Returns the most frequent value, or null for an empty list. When several values are
equally frequent the least one wins. Example: mode([2.0, 1.0, 2.0, 1.0, 3.0]) is
1.0.
fn mode(values List[Float]) Float? { ... }percentile Function#
Returns the value percent percent of the way through the sorted list, interpolating linearly between neighbors, or null for an empty list or a percent outside 0 to 100 (NaN included).
percent runs from 0.0 (the least value) to 100.0 (the greatest).
Example: percentile([1.0, 2.0, 3.0, 4.0, 5.0], 25.0) is 2.0.
fn percentile(values List[Float], percent Float) Float? { ... }population_stdev Function#
Returns the population standard deviation, or null for an empty list.
fn population_stdev(values List[Float]) Float? { ... }population_variance Function#
Returns the population variance (divide by n), or null for an empty list.
Example: population_variance([1.0, 2.0, 3.0, 4.0]) is 1.25.
fn population_variance(values List[Float]) Float? { ... }quantiles Function#
Returns the parts - 1 cut points that divide the sorted values into parts groups of equal probability, using the same interpolation as percentile.
An empty list, or a parts below 2, gives an empty list.
Example: quantiles([1.0, 2.0, 3.0, 4.0, 5.0], 4) is [2.0, 3.0, 4.0].
fn quantiles(values List[Float], parts Int) List[Float] { ... }stdev Function#
Returns the sample standard deviation, or null when the list has fewer than two
values. Example: stdev([2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0]) is about 2.138.
fn stdev(values List[Float]) Float? { ... }variance Function#
Returns the sample variance (divide by n - 1), or null when the list has fewer than
two values. Example: variance([1.0, 2.0, 3.0, 4.0]) is 1.6666666666666667.
fn variance(values List[Float]) Float? { ... }