You are here: Symbol Reference > StatTools Namespace > Classes > TMtxMulLinReg Class
Stats Master VCL
ContentsIndex
PreviousUpNext
TMtxMulLinReg Class

Performs multiple linear regression.

StatTools_TMtxMulLinRegStatTools_TMtxMulLinReg
Pascal
TMtxMulLinReg = class(TMtxComponent);

Use TMtxMulLinReg component to perform multiple linear regression on dataset. The TMulLinRegress component 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), b(1) ... Here the observed values obey the following equation: 

y(k) = b(0) + b(1) * x(1,k) + b(2) * x(2,k) + ... 

i.e 

y = A * b 

 

How to use TMtxMulLinReg component? 

  1. Drop a TMtxMulLinReg component on the form.
  2. Define A, the matrix of independent variables.
  3. Define Y, vector of dependent variables.
  4. Define Weights (optional) vector.
  5. If you don't want to use intercept term b(0) in our calculations, set Constant property to false,
  6. Call the Recalc method to trigger calculation.

 

Results:

  1. RegressResult : regression coefficients (b), regression coefficients confidence intervals (BConfInt) and standard deviation (BStdDev), residuals (Residuals) and calculated dependent variables (YCalc).
  2. RegressStatistics : basic regression statistics (R2, Adjusted R2, residuals variance, F statistics, significance probability).

How to setup and run multiple linear regression? In this example we've also used the weights. This is done by specifying weights for each variable and setting UseWeights property to true.

Uses Statistics, StatTools, MtxVec;
procedure Example(MtxMLReg: TMtxMulLinReg);
begin
  // y = A*b
  MtxMLReg.A.SetIt(3,2,false,[-5,2,
                                1,4,
                                8,0.5]);
  MtxMLReg.Y.SetIt(false,[-2,
                            1,
                            11]);
  MtxMLReg.Weights.SetIt(false,[2,6,1]);
  MtxMLReg.UseWeights := true;
  MtxMLReg.Recalc;
  // MtxMLReg.RegressResult.B = ( 4.586, 0.871, -1.114 )
end;
#include "MtxVec.hpp"
#include "MtxExpr.hpp"
#include "Math387.hpp"
#include "Statistics.hpp"
#include "StatTools.hpp"
void __fastcall Example(TMtxMulLinReg* mlr)
{
  // y = A*b
  mlr->A->SetIt(3,2,false,OPENARRAY(double,(-5,2,
                                1,4,
                                8,0.5)));
  mlr->Y->SetIt(false,OPENARRAY(double,(-2,1,11)));
  mlr->Weights->SetIt(false,OPENARRAY(double,(2,6,1)));
  mlr->UseWeights = true;
  mlr->Recalc();
  // Result ==> b = ( 4.586, 0.871, -1.114 )
}
Examples on GitHub
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!