You are here: Symbol Reference > StatTools Namespace > Classes > TMtxLogistReg Class
Stats Master VCL
ContentsIndex
PreviousUpNext
TMtxLogistReg Class

Performs logistic regression.

StatTools_TMtxLogistRegStatTools_TMtxLogistReg
Pascal
TMtxLogistReg = class(TMtxComponent);

Use TMtxLogistReg component to perform ordinary or ordinal logistic regression on dataset.Suppose y takes values in k ordered categories, and let p_ij be the cumulative probability that y(i) falls in the j'th category or higher. The ordinal logistic regression model is defined as: 

 

logit(p_ij) = theta(j) + A_i'B , i = 1,..,length(Y), j = 1,..,k-1,  

 

where A_i is the i'th row of A . The number of ordinal categories k is taken to be the number of distinct values of int(y). If k is 2 (two categories) the model is ordinary logistic regression.  

 

How to use TMtxLogistReg component?  

  1. Drop a TMtxLogistReg component on the form.
  2. Define crefA, the matrix of independent variables.
  3. Define crefY, grouping (categories) vector.All values have to be integers.
  4. Define initial estimates for crefTheta and crefB coefficients. Alternatively you can also set crefAutoInitEstimates to true and let the algorithm calculate initial estimates for Theta and B.
  5. (Optionally) Set crefTolerance to define desired B, Theta estimates precision. Set crefMaxIteration to define maximum number of iterations in main calculation loop.
  6. Call the crefRecalc method to trigger calculation.

Results:

  1. crefB : B coefficients estimates.
  2. crefTheta : Theta coefficients estimates.
  3. crefTBStdErr : Theta and B coefficients estimates standard errors.

How to setup and run logistic regression? In the following example we'll perform ordinary (i.e. with two categories) logistic regression on data, taken from NCSS statistics program. Note that TMtxLogistReg.Y vector values are binary integer values.

Uses ..., StatTools, MtxVecEdit;
var TestComp: TMtxLogistReg;
begin
    TestComp := TMtxLogistReg.Create(Self);
    try
      TestComp.A.SetIt(27,3,false,
      [0.8, 1.9, 0.996,
      0.9, 1.4, 0.992,
      0.8, 0.8, 0.982,
      1, 0.7, 0.986,
      0.9,  1.3, 0.98,
      1,    0.6, 0.982,
      0.95, 1,  0.992,
      0.95, 1.9,    1.02,
      1,    0.8,    0.999,
      0.95, 0.5, 1.038,
      0.85, 0.7, 0.988,
      0.7,  1.2, 0.982,
      0.8,  0.4, 1.006,
      0.2,  0.8, 0.99,
      1,    1.1, 0.99,
      1,    1.9, 1.02,
      0.65, 0.5,    1.014,
      1,    1,  1.004,
      0.5,  0.6, 0.99,
      1,    1.1, 0.986,
      1,    0.4,    1.01,
      0.9,  0.6, 1.02,
      1,    1,  1.002,
      0.95, 1.6, 0.988,
      1,    1.7, 0.99,
      1,    0.9, 0.986,
      1,    0.7, 0.986]);
      TestComp.Y.SetIt(false,[1,1,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1,0]);
      TestComp.Recalc;
      // Results =>
      // B = (9.65215222458842, 3.86710032907408, -82.073774279211)
      // Theta = (-67.6339061278272)
      // TBStdErr = (56.8875416435276, 7.75107606604495, 1.77827769017976, 61.712376172072)
      // meaning Theta StdErr = 56.8875416435276,
      //         Beta StdErrs = 7.75107606604495, 1.77827769017976, 61.712376172072
      ViewValues(TestComp.b,'B',true);
      ViewValues(TestComp.Theta,'Theta',true);
      ViewValues(TestComp.TBStdErr,'SE',true);
    finally
      TestComp.Free;
    end;
end;
#include "StatTools.hpp"
#include "Math387.hpp"
#include "MtxExpr.hpp"
void __fastcall Example(TMtxLogistReg* tc)
{
  const int aDataLen = 81;
  double aData[aDataLen] = {0.8, 1.9, 0.996,
                0.9, 1.4, 0.992,
                0.8, 0.8, 0.982,
                1, 0.7, 0.986,
                0.9,    1.3, 0.98,
                1,  0.6, 0.982,
                0.95,   1,  0.992,
                0.95,   1.9,    1.02,
                1,  0.8,    0.999,
                0.95,   0.5, 1.038,
                0.85, 0.7, 0.988,
                0.7,    1.2, 0.982,
                0.8,    0.4, 1.006,
                0.2,    0.8, 0.99,
                1,  1.1, 0.99,
                1,  1.9, 1.02,
                0.65, 0.5,  1.014,
                1,  1,  1.004,
                0.5,    0.6, 0.99,
                1,  1.1, 0.986,
                1,  0.4,    1.01,
                0.9,    0.6, 1.02,
                1,  1,  1.002,
                0.95, 1.6, 0.988,
                1,  1.7, 0.99,
                1,  0.9, 0.986,
                1,  0.7, 0.986};

    const int yDataLen = 27;
    double yData[yDataLen] = {1,1,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1,0};

    tc->A->SetIt(27,3,false, aData, aDataLen-1);
    tc->Y->SetIt(false,yData, yDataLen-1);
    tc->Recalc();
    // Results =>
    // B = (9.65215222458842, 3.86710032907408, -82.073774279211)
    // Theta = (-67.6339061278272)
    // TBStdErr = (56.8875416435276, 7.75107606604495, 1.77827769017976, 61.712376172072)
    // meaning Theta StdErr = 56.8875416435276,
    //         Beta StdErrs = 7.75107606604495, 1.77827769017976, 61.712376172072
}
Examples on GitHub
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!