The OpenD Programming Language

simpleLinearRegression

A linear regression model with a single explanatory variable.

  1. sumType!YRange[2] simpleLinearRegression(XRange x, YRange y)
    template simpleLinearRegression(Summation summation = Summation.kbn)
    @safe
    sumType!YRange[2]
    simpleLinearRegression
    (
    XRange
    YRange
    )
    (
    XRange x
    ,
    YRange y
    )
    if (
    isInputRange!XRange &&
    &&
    !(
    isArray!XRange &&
    isArray!YRange
    )
    &&
    isFloatingPoint!(sumType!YRange)
    )
  2. sumType!(Y[])[2] simpleLinearRegression(X[] x, Y[] y)
  3. template simpleLinearRegression(string summation)

Members

Functions

simpleLinearRegression
sumType!YRange[2] simpleLinearRegression(XRange x, YRange y)
sumType!(Y[])[2] simpleLinearRegression(X[] x, Y[] y)

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[0].approxEqual(-0.95)); // shift
assert(params[1].approxEqual(1)); // slope

Meta