Table of Contents

Struct LeastSquares

Namespace
LinqStatistics
Assembly
LinqStatistics.dll

Represents the result of a LeastSquares calculation of the form y = mX + b

public struct LeastSquares : IFormattable, IEquatable<LeastSquares>
Implements
Inherited Members

Constructors

LeastSquares(double, double)

public LeastSquares(double m, double b)

Parameters

m double

The slope

b double

The intercept

LeastSquares(double, double, double)

public LeastSquares(double m, double b, double r2)

Parameters

m double

The slope

b double

The intercept

r2 double

The R Squared correlation coefficient

Fields

Empty

Empty instance - returned when EnumerableStats.LeastSquares is passed a singular matrix. All members are zero.

public static readonly LeastSquares Empty

Field Value

LeastSquares
Represents the result of a LeastSquares calculation of the form y = mX + b

Properties

B

B Coefficient for y = Mx + B (i.e. y intercept)

public readonly double B { get; }

Property Value

double
Represents the result of a LeastSquares calculation of the form y = mX + b

M

M Coefficient for y = Mx + B (i.e. slope)

public readonly double M { get; }

Property Value

double
Represents the result of a LeastSquares calculation of the form y = mX + b

RSquared

The R Squared correlation coefficient

public readonly double RSquared { get; }

Property Value

double
Represents the result of a LeastSquares calculation of the form y = mX + b

Methods

Equals(LeastSquares)

public readonly bool Equals(LeastSquares other)

Parameters

other LeastSquares

Returns

bool

True if other has equal m and b values

Equals(object)

public override readonly bool Equals(object obj)

Parameters

obj object

The object to compare to

Returns

bool

True if obj is a LeastSquares and has equal m and b values

GetHashCode()

public override readonly int GetHashCode()

Returns

int

Hash code of the instance

IsNaN(LeastSquares)

Determines if the LeastSquares argument has Not a Number elements

public static bool IsNaN(LeastSquares ls)

Parameters

ls LeastSquares

Returns

bool

True if either M, B or RSquared is NaN

Solve(double)

Uses the calculated coefficients to solve Y for inputted X

public readonly double Solve(double x)

Parameters

x double

X value to solve for

Returns

double

Y value (y = Mx + B)

SolveForX(double)

Uses the calculated coefficients to solve X for inputted Y

public readonly double SolveForX(double y)

Parameters

y double

Y value to solve for

Returns

double

X value (x = (y - b) / m)

ToFunc(LeastSquares)

Casts a LeastSqaures to a Function Solve(double)

public static Func<double, double> ToFunc(LeastSquares ls)

Parameters

ls LeastSquares

The LeastSquares instance

Returns

Func<double, double>
Represents the result of a LeastSquares calculation of the form y = mX + b

ToString()

public override readonly string ToString()

Returns

string

ToString(IFormatProvider)

public readonly string ToString(IFormatProvider provider)

Parameters

provider IFormatProvider

Returns

string

ToString(string)

public readonly string ToString(string format)

Parameters

format string

Returns

string

ToString(string, IFormatProvider)

public readonly string ToString(string format, IFormatProvider formatProvider)

Parameters

format string
formatProvider IFormatProvider

Returns

string

Operators

operator ==(LeastSquares, LeastSquares)

Equality operator (M, B and RSquared must be equal)

public static bool operator ==(LeastSquares lhs, LeastSquares rhs)

Parameters

lhs LeastSquares
rhs LeastSquares

Returns

bool

implicit operator Func<double, double>(LeastSquares)

Casts a LeastSqaures to a Function Solve(double)

public static implicit operator Func<double, double>(LeastSquares ls)

Parameters

ls LeastSquares

The LeastSquares instance

Returns

Func<double, double>
Represents the result of a LeastSquares calculation of the form y = mX + b

operator !=(LeastSquares, LeastSquares)

Inequality operatory

public static bool operator !=(LeastSquares lhs, LeastSquares rhs)

Parameters

lhs LeastSquares
rhs LeastSquares

Returns

bool