WeightedLeastSquares class
Implements Weighted Least Squares method for linear regression.
This class inherits all the attributes and methods from LeastSquares.
It also introduces the calculateWeightedResiduals() method, which computes the residuals
taking into account the weights associated with each observation.
Example:
var A = Matrix.fromList([[1, 2], [3, 4], [5, 6]]);
var b = Column.fromList([7, 8, 9]);
var W = Diagonal.fromList([0.5, 0.3, 0.2]);
var wls = WeightedLeastSquares(A, b, W);
wls.fit();
print(wls.beta); // Prints the coefficients of the regression model
print(wls.calculateWeightedResiduals()); // Prints the weighted residuals of the model
- Inheritance
-
- Object
- BaseLeastSquares
- WeightedLeastSquares
Constructors
- WeightedLeastSquares(Matrix A, ColumnMatrix b, DiagonalMatrix W, {EquationMethod method = EquationMethod.linear})
-
Creates an instance of the
WeightedLeastSquaresclass.
Properties
- A → Matrix
-
The designed or input matrix for the model.
finalinherited
- b → ColumnMatrix
-
The absolute terms or output column matrix for the model.
finalinherited
- beta ↔ Matrix
-
Coefficients vector, solved in the fit method.
getter/setter pairinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- method ↔ EquationMethod
-
Equation solving method.
getter/setter pairinherited
- residuals → Matrix
-
Computes residuals of the fitted model.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- W → DiagonalMatrix?
-
An optional diagonal matrix of weights.
finalinherited
Methods
-
calculateWeightedResiduals(
) → Matrix - Computes the residuals of the regression model, taking into account the weights associated with each observation.
-
confidenceLevel(
) → num -
Compute confidence level. Actual implementation depends on the fit and residuals.
inherited
-
covariance(
[bool isOnDesignMatrix = true]) → Matrix -
Compute covariance matrix either of the coefficients or of the residuals.
inherited
-
detectOutliers(
double confidenceLevel) → List< int> -
Detect outliers in the data using Chauvenet's criterion with a given confidence level.
inherited
-
errorEllipse(
) → Eigen -
Compute error ellipse parameters using eigenvalue decomposition on the covariance matrix.
inherited
-
fit(
{LinearSystemMethod linear = LinearSystemMethod.leastSquares, DecompositionMethod decomposition = DecompositionMethod.cholesky}) → void -
Fits the model to the data using the chosen method.
The method can be either linear or using a matrix decomposition.
inherited
-
normal(
) → Matrix -
Computes the normal equation matrix.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
predict(
Matrix xNew) → Matrix -
Uses the fitted model to predict new outputs given new inputs
xNew.inherited -
standardDeviation(
) → num -
Compute standard deviation of residuals.
inherited
-
standardError(
) → num -
Compute standard error of residuals, which is the standard deviation divided by the square root of the number of observations.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
unitVariance(
) → num -
Compute unit variance, also known as the mean square error (MSE).
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited