Skip to content
FutureBlitz

    Install

    Import std.math.stats

    std.math.stats

    Statistics: mean, median, variance, standard deviation, percentiles, and histograms.

    Statistics of numbers of any type, worked out in Doubles: the mean, the median, the variance and standard deviation of a sample and of a whole population, percentiles, and histograms. Too few values for what's asked panics, as Python's statistics raises.

    Examples

    
    Local scores = [2, 4, 4, 4, 5, 5, 7, 9]
    Expect(Median(scores) == 4.5 && Percentile(scores, 50) == 4.5)
    Expect(PopulationVariance(scores) == 4.0 && PopulationStdDev(scores) == 2.0)
    Expect(IsClose(Variance(scores), 32.0 / 7) && IsClose(StdDev(scores), Sqrt(32.0 / 7)))

    std/math/stats.fb

    Functions

    Mean function

    @PanicsAtCaller Public Function Mean<T: Bounded>(values: T[]): Double

    The mean, the sum over the count, or the sum of each value's share where the sum overflows and the values don't. No values panics.

    Examples

    Local scores = [2, 4, 4, 4, 5, 5, 7, 9]
    Expect(Mean(scores) == 5.0)
    Expect(Median(scores) == 4.5)
    Expect(PopulationStdDev(scores) == 2.0)
    Expect(Percentile(scores, 100) == 9.0)

    std/math/stats.fb, line 58

    Median function

    @PanicsAtCaller Public Function Median<T: Bounded>(values: T[]): Double

    The middle value, or the mean of the two middle ones for an even count. No values, or a NaN, panics.

    std/math/stats.fb, line 78

    Variance function

    @PanicsAtCaller Public Function Variance<T: Bounded>(values: T[]): Double

    The variance of a sample, the squared differences from the mean over the count less 1, as an estimate of the variance of all it was drawn from. Fewer than two values panics.

    std/math/stats.fb, line 105

    StdDev function

    @PanicsAtCaller Public Function StdDev<T: Bounded>(values: T[]): Double

    The standard deviation of a sample: the square root of its Variance. Fewer than two values panics.

    std/math/stats.fb, line 113

    PopulationVariance function

    @PanicsAtCaller Public Function PopulationVariance<T: Bounded>(values: T[]): Double

    The variance of the values as the whole population: the squared differences from the mean over the count. No values panics.

    std/math/stats.fb, line 121

    PopulationStdDev function

    @PanicsAtCaller Public Function PopulationStdDev<T: Bounded>(values: T[]): Double

    The standard deviation of the values as the whole population: the square root of their PopulationVariance. No values panics.

    std/math/stats.fb, line 129

    Percentile function

    @PanicsAtCaller Public Function Percentile<T: Bounded>(values: T[], percent: Double): Double

    The value below which percent of them lie, from 0 for the least to 100 for the largest, between the two nearest when it falls between them, as NumPy's percentile does: 50 is the Median. No values, a NaN, or a percent outside 0 to 100, panics.

    std/math/stats.fb, line 138

    Histogram function

    @PanicsAtCaller Public Function Histogram<T: Bounded>(values: T[], bins: Int, low: Double, high: Double): Int[]

    How many values fall in each of bins equal ranges from low to high, the last range holding high too; those outside, and NaN, are left out. A count of bins that isn't above 0, or a low that isn't below high, or isn't finite, panics.

    Examples

    Expect(Histogram([1, 2, 2, 3, 9], 2, 0, 10) == [4, 1])

    std/math/stats.fb, line 180

    Histogram function

    @PanicsAtCaller Public Function Histogram<T: Bounded>(values: T[], bins: Int): Int[]

    How many values fall in each of bins equal ranges from the least value to the largest, which all do. No values, a NaN or an infinite one, or a count of bins that isn't above 0, panics.

    std/math/stats.fb, line 237

    Report an issue with this page or with FutureBlitz on GitHub.