You are here: Symbol Reference > Regress Namespace > Functions > Regress.StepwiseRegression Function
Stats Master VCL
ContentsIndex
Example

We are looking for best fit of:  

b0 + b1*x1 + b2*x2 + b3*x3 + b4*x4 + b5*x5 = y  

where b1..b5 can be either zero or not, but would like to know which are best set to zero. Last column of aSrc in the code example below is the dependent variable (y). 

 

Uses MtxExpr, Regress, StatTools, Math387;
procedure TForm78.RunButtonClick(Sender: TObject);
var aSrc, reportCoeff, reportSSE: Matrix;
    stdDevA: Vector;
    aList: TVecList;
    i: integer;
    bi: VectorInt;
    sMethod: TStepwiseMethod;
begin
    Memo.Lines.BeginUpdate;
    Memo.Lines.Clear;

    aList := TVecList.Create;
    try
        aSrc.SetIt(15,6,false, [83,34, 65, 63, 64, 106,
                                73, 19, 73, 48, 82, 92,
                                54, 81, 82, 65, 73, 102,
                                96, 72, 91, 88, 94, 121,
                                84, 53, 72, 68, 82, 102,
                                86, 72, 63, 79, 57, 105,
                                76, 62, 64, 69, 64, 97,
                                54, 49, 43, 52, 84, 92,
                                37, 43, 92, 39, 72, 94,
                                42, 54, 96, 48, 83, 112,
                                71, 63, 52, 69, 42, 130,
                                63, 74, 74, 71, 91, 115,
                                69, 81, 82, 75, 54, 98,
                                81, 89, 64, 85, 62, 96,
                                50, 75, 72, 64, 45, 103]);

        aList.DecomposeColumnMatrix(aSrc);
        stdDevA.Size(aList.Count);
        for i := 0 to aList.Count-1 do stdDevA[i] := aList[i].StdDev;
        bi.BitCount := aList.Count-1;
        sMethod := swBackward;

        StepwiseRegression(aList, stdDevA, sMethod, bi, reportSSE, reportCoeff);

        Memo.Lines.Add('');
        reportSSE.ValuesToStrings(Memo.Lines, '', ftaRightAlign, '0.###', '0.###', true);
        Memo.Lines.Add('');
        reportCoeff.ValuesToStrings(Memo.Lines, '', ftaRightAlign, '0.###', '0.###', true);
        Memo.Lines.Add('');
    finally
        Memo.Lines.EndUpdate;
        aList.Free;
    end;
end;
Copyright (c) 1999-2025 by Dew Research. All rights reserved.