void LinRegress(TVec *X, TVec *Y, TVec *B, bool Constant = true, TVec *Weights = null, TVec *YCalc = null, TMtx *ATA = null);
Simple linear regression.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | X | TVec * | |
| 2 | Y | TVec * | |
| 3 | B | TVec * | |
| 4 | Constant = true | bool | |
| 5 | Weights = null | TVec * | |
| 6 | YCalc = null | TVec * | |
| 7 | ATA = null | TMtx * |
Remarks:
The 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) and b(1). In case constant term is used, the observed values obey the following equation:
y(k) = b(0) + b(1) * x
i.e
Y = b(0) + b(1)*X.
or if constant term is NOT used:
y(k) = b(0) * x
To calculate additional regression statistical parameters, use Regress::RegressTest routine.
Examples
#include "MtxExpr.h"
#include "Units.Regress.h"
using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Stats;
using namespace Dew::Stats::Units::Regress;
void Example()
{
Vector x(0);
Vector y(0);
Vector b(0);
Vector yhat(0);
x.SetIt(false,DewArray<double> {1.0, 1.5, 2.3, 3.8, 4.2, 5.0, 5.3, 5.9});
y.SetIt(false,DewArray<double> {11, 12, 12.5, 14, 14.3, 15.2, 15.3, 17});
LinRegress(x,y,b,true,nullptr,yhat,nullptr);
}
See Also: Regress::MulLinRegress, Regress::RegressTest
Declared in Dew::Stats::Units::Regress · Dew.Stats/Units.Regress.h · Cross-compiler