Home > @josh-brown/vector > calculateGeneralLeastSquares
Calculates a regression model for an arbitrary function.
Signature:
export declare function calculateGeneralLeastSquares<S>(dataPoints: Vector<S>[], functionTemplate: ApproximationFunctionTemplate<S>, numberOfTerms: number): LeastSquaresApproximation<S>;|
Parameter |
Type |
Description |
|---|---|---|
|
dataPoints |
Vector<S>[] |
The data used to construct the approximation |
|
functionTemplate |
A higher-order function which takes a vector of coefficients and yields a new function which takes a vector of independent variables to produce a value for the dependent variable | |
|
numberOfTerms |
number |
The number of coefficients needed to produce the approximation function |
Returns:
- the result of the linear regression
The result is on object which has: - coefficients: a vector whose entries correspond to the coefficients which must be plugged into the function template to yield the best approximation function - approximationFunction: a function which takes a vector of the independent variable values, and returns the predicted value of the dependent variable