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 ) }
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
|