Fits multiple linear equations to data.
The routine fits equations to data by minimizing the sum of squared residuals. The observed values obey the following equation:
Example 1
In the following example we generate some data. Then we fit multiple linear function to this data and retreive it's regression coefficients. Uses MathExpr, RegModels;
procedure Example);
var Y,B: Vector;
X: Matrix;
begin
X.SetIt(3,2,false,[1.0, 2.0,
-3.2, 2.5,
8.0, -0.5]);
Y.SetIt(false, [-3.0, 0.25, 8.0]);
MulLinFit(B,X,Y,true);
// B = (18.646428571, -1.9464285714, -9.85 )
end;
#include "MtxVecCpp.h"
#include "Math387.hpp"
#include "RegModels.hpp"
#include "MtxVecTee.hpp"
void __fastcall Example();
{
Matrix X;
Vector Y,B;
X->SetIt(3,2,false,OPENARRAY(TSample,(1.0, 2.0,
-3.2, 2.5,
8.0, -0.5)));
Y->SetIt(3,false, OPENARRAY(TSample,(-3.0, 0.25, 9.0)));
MulLineFit(B,X,Y,true,NULL);
// B = (18.646428571, -1.9464285714, -9.85 )
}
using Dew.Math;
using Dew.Stats.Units;
namespace Dew.Examples
{
private void Example()
{
Matrix X = new Matrix(0,0);
Vector Y = new Vector(0);
Vector B = new Vector(0);
X.SetIt(3,2,false,new double[]{1.0, 2.0,
-3.2, 2.5,
8.0, -0.5});
Y.SetIt(3,false,new double[] {-3.0, 0.25, 9.0});
RegModels.MulLineFit(B,X,Y,true,null);
// B = (18.646428571, -1.9464285714, -9.85 )
}
}