You are here: Symbol Reference > Regress Namespace > Functions > Regress.LinRegress Function
Stats Master VCL
ContentsIndex
Example

The following example loads data for simple linear regression (line equation) and then extracts line parameters b(0)=n and b(1)=k:

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;
#include "MtxExpr.hpp"
#include "Regress.hpp"
#include "MtxVecTee.hpp"
void __fastcall Test(TLineSeries* series1, TLineSeries* series2)
{
  sVector x,y,b,yhat;
  x.SetIt(false,OPENARRAY(double,(1.0, 1.5, 2.3, 3.8, 4.2, 5.0, 5.3, 5.9)));
  y.SetIt(false,OPENARRAY(double,(11, 12, 12.5, 14, 14.3, 15.2, 15.3, 17)));
  LinRegress(x,y,b,true,NULL,yhat,NULL);
  DrawValues(x,y,series1,false); // draw original data
  DrawValues(x,yhat,series2,false); // draw fitted data
}
Copyright (c) 1999-2025 by Dew Research. All rights reserved.