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
LeastSquares(double, double, double)
public LeastSquares(double m, double b, double r2)
Parameters
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
objectThe 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
Solve(double)
Uses the calculated coefficients to solve Y for inputted X
public readonly double Solve(double x)
Parameters
x
doubleX 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
doubleY 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
LeastSquaresThe LeastSquares instance
Returns
ToString()
public override readonly string ToString()
Returns
ToString(IFormatProvider)
public readonly string ToString(IFormatProvider provider)
Parameters
provider
IFormatProvider
Returns
ToString(string)
public readonly string ToString(string format)
Parameters
format
string
Returns
ToString(string, IFormatProvider)
public readonly string ToString(string format, IFormatProvider formatProvider)
Parameters
format
stringformatProvider
IFormatProvider
Returns
Operators
operator ==(LeastSquares, LeastSquares)
Equality operator (M, B and RSquared must be equal)
public static bool operator ==(LeastSquares lhs, LeastSquares rhs)
Parameters
lhs
LeastSquaresrhs
LeastSquares
Returns
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
LeastSquaresThe LeastSquares instance
Returns
operator !=(LeastSquares, LeastSquares)
Inequality operatory
public static bool operator !=(LeastSquares lhs, LeastSquares rhs)
Parameters
lhs
LeastSquaresrhs
LeastSquares