Regress::MulLinRegress Function

Overload List

#SignatureDescription
1void MulLinRegress(TVec *Y, TMtx *A, TVec *b, bool Constant = true, TVec *YCalc = null, TMtx *ATA = null, TRegSolveMethod Method = TRegSolveMethod::regSolveLQR);Multivariante linear regression.
2void MulLinRegress(TVec *Y, TMtx *A, TVec *b, TVec *Weights, bool Constant = true, TVec *YCalc = null, TMtx *ATA = null, TRegSolveMethod Method = TRegSolveMethod::regSolveLQR);Multivariante linear regression.

Overload 1: void MulLinRegress(TVec *Y, TMtx *A, TVec *b, bool Constant = true, TVec *YCalc = null, TMtx *ATA = null, TRegSolveMethod Method = TRegSolveMethod::regSolveLQR);

Multivariante linear regression.

#NameTypeDescription
1YTVec *
2ATMtx *
3bTVec *
4Constant = truebool
5YCalc = nullTVec *
6ATA = nullTMtx *
7Method = TRegSolveMethod::regSolveLQRTRegSolveMethod
Examples
#include "MtxExpr.h"
#include "Units.MtxExpr.h"
#include "Regress.h"
#include "Units.Regress.h"

using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Stats;
using namespace Dew::Math::Units::MtxExpr;
using namespace Dew::Stats::Units::Regress;

void Example()
{
    Vector y, b, w, yhat, resid, bstd;
    Matrix A, ATA;
    TRegStats RegStat;

    A.SetIt(4, 2, false, DewArray<double>{1.0, 2.0, -3.2, 2.5, 8.0, -0.5, -2.2, 1.8}); // independent variables

    w.SetIt(false, DewArray<double>{1, 2, 2, 1}); // weights
    y.SetIt(false, DewArray<double>{-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, resid, bstd, true, w); // do basic regression stats
    // RegStat = (ResidualVar:0.037230395108; R2:0.99965713428;
    // AdjustedR2:0.99897140285; F:1457.7968725; SignifProb: 0.01851663347)
}
Declared in Dew::Stats::Units::Regress · Dew.Stats/Units.Regress.h · Cross-compiler

Overload 2: void MulLinRegress(TVec *Y, TMtx *A, TVec *b, TVec *Weights, bool Constant = true, TVec *YCalc = null, TMtx *ATA = null, TRegSolveMethod Method = TRegSolveMethod::regSolveLQR);

Multivariante linear regression.

#NameTypeDescription
1YTVec *Defines vector of dependant variable.
2ATMtx *Defines matrix of independant (also X) variables.
3bTVec *Returns calculated regression coefficiens.
4WeightsTVec *Defines weights (optional).
5Constant = trueboolIf true then intercept term b(0) will be included in calculations. If false, set intercept term b(0) to 0.0.
6YCalc = nullTVec *Returns vector of calculated dependant variable, where YCalc = A*b.
7ATA = nullTMtx *Returns inverse matrix of normal equations i.e [A(T)*A]^-1.
8Method = TRegSolveMethod::regSolveLQRTRegSolveMethodUse QR, SVD, or LU solver. Typically QR will yield best compromise between stability and performance.
Remarks:

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 Regress::RegressTest routine.

Examples
#include "MtxExpr.h"
#include "Regress.h"
#include "Units.Regress.h"

using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Stats;
using namespace Dew::Stats::Units::Regress;

void Example()
{
    Matrix A(0, 0);
    Matrix ATA(0, 0);
    Vector y(0);
    Vector b(0);
    Vector w(0);
    Vector yhat(0);
    Vector residuals(0);
    Vector BStdDev(0);

    TRegStats rs;
    // independent variables
    A.SetIt(4, 2, false, DewArray<double>{1.0, 2.0,
        -3.2, 2.5,
            8.0, -0.5,
            -2.2, 1.8});
    w.SetIt(false, DewArray<double>{ 1, 2, 2, 1 }); // weights
    y.SetIt(false, DewArray<double>{ -3.0, 0.25, 8.0, 5.5 }); // dependent variables
    MulLinRegress(y, A, b, w, true, yhat, ATA, TRegSolveMethod::regSolveLQR); //do regression
        // b=(19.093757944, -2.0141843616, -10.082487055)
    RegressTest(y, yhat, ATA, rs, residuals, BStdDev, true, w); // do basic regression stats
        // RegStat = (ResidualVar:0.037230395108; R2:0.99965713428;
        // AdjustedR2:0.99897140285; F:1457.7968725; SignifProb: 0.01851663347)
}
See Also: Regress::RegressTest, Regress::LinRegress, Regress::NLinRegress
Declared in Dew::Stats::Units::Regress · Dew.Stats/Units.Regress.h · Cross-compiler