TMtxLogistReg Class

Source: StatTools.cs · Assembly: Dew.Stats
ComponentTMtxComponentTMtxLogistReg

public class TMtxLogistReg : TMtxComponent

Performs logistic regression.

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?

  • Drop a TMtxLogistReg component on the form.
  • Define Dew.Stats.TMtxLogistReg.A, the matrix of independent variables.
  • Define Dew.Stats.TMtxLogistReg.Y, grouping (categories) vector. Note: All values have to be integers.
  • Define initial estimates for Dew.Stats.TMtxLogistReg.Theta and Dew.Stats.TMtxLogistReg.B coefficients. Alternatively you can also set Dew.Stats.TMtxLogistReg.AutoInitEstimates to true and let the algorithm calculate initial estimates for Theta and B.
  • (Optionally) Set Dew.Stats.TMtxLogistReg.Tolerance to define desired B, Theta estimates precision. Set Dew.Stats.TMtxLogistReg.MaxIteration to define maximum number of iterations in main calculation loop.
  • Call the Dew.Stats.TMtxLogistReg.Recalc method to trigger calculation.

Results:

  • Dew.Stats.TMtxLogistReg.B : B coefficients estimates.
  • Dew.Stats.TMtxLogistReg.Theta : Theta coefficients estimates.
  • Dew.Stats.TMtxLogistReg.TBStdErr : Theta and B coefficients estimates standard errors.

Examples

csharp
using Dew.Stats;
using Dew.Stats.Units;
using Dew.Math;
namespace Dew.Examples
{
    private void Example(StatTools.TMtxLogistReg tc)
    {
        tc.A.SetIt(27,3,false, new double[]
            {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});;
        tc.Y.SetIt(false,new double[] {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.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
    }
}

Properties

NameTypeDescription
ATMtxIndependent variables.
AlphaDoubleDesired significant value for the statistical tests.
AutoInitEstimatesBooleanAutomatically calculate initial estimates for regression coefficients.
AutoUpdateBooleanIf true then changing any of the TMtxLogistReg properties will trigger the Dew.Stats.TMtxLogistReg.Recalc method.
BTVecB coefficients estimates.
BlockAssignBooleanBlock streaming of specific properties when storing only a "template".
DirtyBooleanWhen any of the TMtxLogistReg properties changes, this property is automatically set to true.
EditorActiveBooleanReturns True, if the component editor is displayed.
MaxIterationInt32Defines one of the conditions for terminating the regression coefficient calculation.
ReferenceTReferenceListStores a list of components that have to be notified, when this component is destroyed.
TBStdErrTVecStandard errors of Theta, B estimates.
ThetaTVecTheta coefficients estimates.
ToleranceDoubleDefines one of the conditions for terminating the regression coefficient calculation.
YTVecGrouping variable.

Methods

NameDescription
AllowStreamingReturns the negatated value of BlockAssign.
AssignAssign values of all published properties from Source.
AssignTemplateAssign values of "template-like" published properties from Source.
EditorClassTo be overriden in descendanr classses.
LoadFromStreamLoad the component from Src stream.
LoadTemplateFromFileLoad a template from file.
LoadTemplateFromStreamLoad a template from stream.
RecalcTriggers logistic regression recalculation.
ResetReset is called after loading the data from stream or file.
SaveTemplateToFileSave template to file.
SaveTemplateToStreamSave template to stream.
SaveToStreamSave the component to Dst stream.