type TMtxMulLinReg = class(TMtxComponent);
Performs multiple linear regression.
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 TMtxMulLinReg.A, the matrix of independent variables. 3. Define TMtxMulLinReg.Y, vector of dependent variables. 4. Define TMtxMulLinReg.Weights (optional) vector. 5. If you don't want to use intercept term b(0) in our calculations, set TMtxMulLinReg.Constant property to false, 6. Call the TMtxMulLinReg.Recalc method to trigger calculation.
Results:
1. TMtxMulLinReg.RegressResult : regression coefficients (b), regression coefficients confidence intervals (BConfInt) and standard deviation (BStdDev), residuals (Residuals) and calculated dependent variables (YCalc). 2. TMtxMulLinReg.RegressStatistics : basic regression statistics (R2, Adjusted R2, residuals variance, F statistics, significance probability).
Examples
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;
Properties
| Name | Type | Description |
|---|---|---|
| A | TMtx | Matrix of independent variables. |
| Alpha | Double | Desired significant value for the statistical tests. |
| AutoUpdate | Boolean | If true then changing any of the TMtxMulLinReg properties will trigger the TMtxMulLinReg.Recalc method. |
| BlockAssign | Boolean | Block streaming of specific properties when storing only a "template". |
| Constant | Boolean | Intercept term. |
| Dirty | Boolean | When any of the TMtxMulLinReg properties changes, this property is automatically set to true. |
| EditorActive | Boolean | Returns True, if the component editor is displayed. |
| Reference | TReferenceList | Stores a list of components that have to be notified, when this component is destroyed. |
| RegressResult | TRegResultClass | Regression results. |
| RegressStatistics | TRegStatsClass | Regression results statistics. |
| SolveMethod | TRegSolveMethod | Defines A*x=b solving method. |
| UseWeights | Boolean | Weighted multiple linear regression. |
| Weights | TVec | Weights for MLR. |
| Y | TVec | Vector of dependent variables. |
Methods
| Name | Description |
|---|---|
| AllowStreaming | Returns the negatated value of BlockAssign. |
| Assign | Assign values of all published properties from Source. |
| AssignTemplate | Assign values of "template-like" published properties from Source. |
| EditorClass | To be overriden in descendanr classses. |
| LoadFromStream | Load the component from Src stream. |
| LoadTemplateFromFile | Load a template from file. |
| LoadTemplateFromStream | Load a template from stream. |
| Recalc | Triggers multiple linear regression recalculation. |
| Reset | Reset is called after loading the data from stream or file. |
| SaveTemplateToFile | Save template to file. |
| SaveTemplateToStream | Save template to stream. |
| SaveToStream | Save the component to Dst stream. |
| ValidSystem | Checks if system is valid. |