Dew Stats Master .NET
MulLinRegress Routines
Summary
Multivariante linear regression.

Unit
Regress

Declaration
Procedure MulLinRegress(y: TVec; A: TMtx; b: TVec; Constant: boolean = true; YCalc: TVec = nil; ATA: TMtx = nil; Method: TRegSolveMethod = regSolveLQR);


Declaration
Procedure MulLinRegress(y: TVec; A: TMtx; b: TVec; Weights: TVec; Constant: boolean = true; YCalc: TVec = nil; ATA: TMtx = nil; Method: TRegSolveMethod = regSolveLQR);
 Parameter  Description 
Defines vector of dependant variable. 
Defines matrix of independant variables. 
Returns calculated regression coefficiens. 
Weights Defines weights (optional). 
Constant If true then include intercept term b(0) in calculations. If false, set intercept term b(0) to 0.0. 
YCalc Returns vector of calculated dependant variable, where YCalc = A*b. 
ATA Returns inverse matrix of normal equations i.e [A(T)*A]^-1. 

Description
Multivariante linear regression. 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), 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.

To calculate additional regression statistical values, use RegressTest routine.

Categories
Regression routines.
 See Also 
RegressTest 
LinRegress 
NLinRegress 

Example 1

The following example performs multiple linear regression.
Uses Regress, MtxExpr; procedure Example; var y,b,w,yhat: Vector; A, ATA : Matrix; RegStat : TRegStats; begin A.SetIt(4,2,false,[1.0, 2.0, -3.2, 2.5, 8.0, -0.5, -2.2, 1.8]); // independent variables w.SetIt(false,[1,2,2,1]); // weights y.SetIt(false,[-3.0, 0.25, 8.0, 5.5]); // dependent variables MulLinRegress(y,A,b,w,true,yhat,ATA); //do regression // b=(19.093757944, -2.0141843616, -10.082487055) RegressTest(y,yhat,V,RegStat,w); // do basic regression stats // RegStat = (ResidualVar:0.037230395108; R2:0.99965713428; // AdjustedR2:0.99897140285; F:1457.7968725; SignifProb: 0.01851663347) end;
#include "MtxVecCpp.h" #include "Regress.hpp" void _fastcall Example() { Matrix A,ATA: Vector y,b,w,yhat; TRegStats rs; // independent variables A->SetIt(4,2,false,OPENARRAY(TSample,(1.0, 2.0, -3.2, 2.5, 8.0, -0.5, -2.2, 1.8))); w->SetIt(false,OPENARRAY(TSample,(1,2,2,1))); // weights y->SetIt(false,OPENARRAY(TSample,(-3.0, 0.25, 8.0, 5.5))); // dependent variables MulLinRegress(y,A,b,w,true,yhat,ATA); //do regression // b=(19.093757944, -2.0141843616, -10.082487055) RegressTest(y,yhat,ATA,RegStat,w); // do basic regression stats // RegStat = (ResidualVar:0.037230395108; R2:0.99965713428; // AdjustedR2:0.99897140285; F:1457.7968725; SignifProb: 0.01851663347) }
using Dew.Math; using Dew.Stats.Units; using Dew.Stats; namespace Dew.Examples { private void Example() { Matrix A = new Matrix(0,0); Matrix ATA = new Matrix(0,0); Vector y = new Vector(0); Vector b = new Vector(0); Vector w = new Vector(0); Vector b = new Vector(0); // independent variables A.SetIt(4,2,false, new double[] {1.0, 2.0, -3.2, 2.5, 8.0, -0.5, -2.2, 1.8}); w.SetIt(false, new double[] {1,2,2,1}); // weights y.SetIt(false, new double[] {-3.0, 0.25, 8.0, 5.5}); // dependent variables TRegStats rs = MulLinRegress(y,A,b,w,true,yhat,ATA); //do regression // b=(19.093757944, -2.0141843616, -10.082487055) RegressTest(y,yhat,ATA,RegStat,w); // do basic regression stats // RegStat = (ResidualVar:0.037230395108; R2:0.99965713428; // AdjustedR2:0.99897140285; F:1457.7968725; SignifProb: 0.01851663347) } }

Copyright 2008 Dew Research
http://www.dewresearch.com