Report a bug
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

# mir.math.stat

This module contains base statistical algorithms.
Note that used specialized summing algorithms execute more primitive operations than vanilla summation. Therefore, if in certain cases maximum speed is required at expense of precision, one can use Summation.fast .
Authors:
Ilya Yaroshenko
template `mean`(Summation summation = Summation.appropriate)

template `mean`(string summation)
Computes the average of r, which must be a finite iterable.
Returns:
The average of all the elements in the range r.
Examples:
```assert(mean([1.0, 2, 3]) == 2);
assert(mean([1.0 + 3i, 2, 3]) == 2 + 1i);
```
@safe sumType!Range `mean`(Range)(Range `r`)
if (hasLength!Range || summation == Summation.appropriate || summation == Summation.fast || summation == Summation.naive);
template `simpleLinearRegression`(Summation summation = Summation.kbn)

template `simpleLinearRegression`(string summation)
A linear regression model with a single explanatory variable.
Examples:
```import mir.math.common: approxEqual;
static immutable x = [0, 1, 2, 3];
static immutable y = [-1, 0.2, 0.9, 2.1];
auto params = x.simpleLinearRegression(y);
assert(params.approxEqual(-0.95)); // shift
assert(params.approxEqual(1)); // slope
```
@safe sumType!YRange `simpleLinearRegression`(XRange, YRange)(XRange `x`, YRange `y`)
if (isInputRange!XRange && isInputRange!YRange && !(isArray!XRange && isArray!YRange) && isFloatingPoint!(sumType!YRange));

@safe sumType!(Y[]) `simpleLinearRegression`(X, Y)(scope const X[] `x`, scope const Y[] `y`);
Parameters:
 XRange `x` `x`[i] points YRange `y` f(`x`[i]) values
Returns:
The pair of shift and slope of the linear curve.