RegModels.LineFit Method

void LineFit(TVec B, TVec X, TVec Y, TVec Weights)

Fits linear equation to data.

#NameDescription
1XVector of independent variable.
2YVector of dependent variable.
3WeightsWeights (optional). Weights are used only if they are set.
4BReturns regression coefficients for linear function.

Result: stored in self (calling object)

Remarks:

The routine fits equations to data by minimizing the sum of squared residuals. The observed values obey the following equation:

Y=b[0]+b[1]X.Y=b[0]+b[1]\cdot X \quad .
Examples
using Dew.Math;
using Dew.Stats.Units;
namespace Dew.Examples
{
    private void Example(Steema.TeeChart.Styles.Line line1,
        Steema.TeeChart.Styles.Line line2)
    {
        Vector X = new Vector(100,false);
        Vector Y = new Vector(100,false);
        Vector YHat = new Vector(0);
        Vector B = new Vector(0);

        X.Ramp(-5.0, 0.1); // x= -5, -4.95, ...-0.05
        Y.RandGauss(3.5, 0.12); // sample data
        RegModels.LineFit(B,X,Y,null); // calculate coefficients
        // evaluate y by using calculated coefficients
        LineEval(B,X, YHat);
        MtxVecTee.DrawValues(X,Y,line1,false); // draw original data
        MtxVecTee.DrawValues(X,YHat,line2,false); // draw fitted data
    }
}
See Also: RegModels.LineDeriv, RegModels.LineEval