Regress.LinRegress Method

procedure LinRegress(const X: TVec; const Y: TVec; const B: TVec; Constant: Boolean; const Weights: TVec; const YCalc: TVec; const ATA: TMtx);

Simple linear regression.

#NameTypeDescription
1XTVec
2YTVec
3BTVec
4ConstantBoolean
5WeightsTVec
6YCalcTVec
7ATATMtx

Result: stored in self (calling object)

Remarks:

The routine fits equations to data by minimizing the sum of squared residuals:

SS = Sum [y(k) - ycalc(k)]^2 ,

where y(k) and ycalc(k) are respectively the observed and calculated value of the dependent variable for observation k. ycalc(k) is a function of the regression parameters b(0) and b(1). In case constant term is used, the observed values obey the following equation:

y(k) = b(0) + b(1) * x

i.e

Y = b(0) + b(1)*X.

or if constant term is NOT used:

y(k) = b(0) * x

To calculate additional regression statistical parameters, use Regress.RegressTest routine.

Examples
Uses MtxExpr, MtxVecTee, Regress;
procedure Example;
var x,y,b,yhat: Vector;
begin
    x.SetIt(false,[1.0, 1.5, 2.3, 3.8, 4.2, 5.0, 5.3, 5.9]);
    y.SetIt(false,[11, 12, 12.5, 14, 14.3, 15.2, 15.3, 17]);
    LinRegress(x,y,b,true,nil,yhat,nil);
    DrawValues(x,y,Series1,false); // draw original data
    DrawValues(x,yhat,Series2,false); // draw fitted data
end;
See Also: Regress.MulLinRegress, Regress.RegressTest