void MulLinFit(TVec *B, TMtx *X, TVec *Y, bool Constant = false, TVec *Weights = null);
Fits multiple linear equations to data.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | B | TVec * | Returns regression coefficients for multiple linear function. |
| 2 | X | TMtx * | Vector of independent variable. |
| 3 | Y | TVec * | Vector of dependent variable. |
| 4 | Constant = false | bool | If true then intercept term b(0) will be included in calculations. If false, set intercept term b(0) to 0.0. |
| 5 | Weights = null | TVec * | Weights (optional). Weights are used only if they are set. |
Remarks:
The routine fits equations to data by minimizing the sum of squared residuals. The observed values obey the following equation:
where X is matrix, Y, B are vectors.
Examples
#include "MtxExpr.h"
#include "Units.RegModels.h"
using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Stats;
using namespace Dew::Stats::Units::RegModels;
void Example()
{
Matrix X(0,0);
Vector Y(0);
Vector B(0);
X.SetIt(3,2,false,DewArray<double>{1.0, 2.0,
-3.2, 2.5,
8.0, -0.5});
Y.SetIt(false,DewArray<double>{-3.0, 0.25, 8.0});
MulLinFit(B,X,Y,true,nullptr);
// B = (18.646428571, -1.9464285714, -9.85 )
}
See Also: RegModels::MulLinEval
Declared in Dew::Stats::Units::RegModels · Dew.Stats/Units.RegModels.h · Cross-compiler