Click or drag to resize
Accord.NET (logo)

StepwiseLogisticRegressionAnalysis Class

Backward Stepwise Logistic Regression Analysis.
Inheritance Hierarchy
SystemObject
  Accord.Statistics.AnalysisStepwiseLogisticRegressionAnalysis

Namespace:  Accord.Statistics.Analysis
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public class StepwiseLogisticRegressionAnalysis : IRegressionAnalysis, 
	IMultivariateAnalysis, IAnalysis, ISupervisedLearning<LogisticRegression, double[], double>
Request Example View Source

The StepwiseLogisticRegressionAnalysis type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyComplete
Gets the full model.
Public propertyCurrent
Gets the current best nested model.
Public propertyInputs
Gets or sets the name of the input variables.
Public propertyIterations
Gets or sets the maximum number of iterations to be performed by the regression algorithm. Default is 50.
Public propertyNested
Gets the collection of nested models obtained after a step of the backward stepwise procedure.
Public propertyOutput
Gets or sets the name of the output variables.
Public propertyOutputs
Gets the dependent variable value for each of the source input points.
Public propertyResult
Gets the resulting probabilities obtained by the most likely logistic regression model.
Public propertySource
Source data used in the analysis.
Public propertyThreshold
Gets or sets the significance threshold used to determine if a nested model is significant or not.
Public propertyToken
Gets or sets a cancellation token that can be used to stop the learning algorithm while it is running.
Public propertyTolerance
Gets or sets the difference between two iterations of the regression algorithm when the algorithm should stop. The difference is calculated based on the largest absolute parameter change of the regression. Default is 1e-5.
Public propertyVariables
Gets the final set of input variables indices as selected by the stepwise procedure.
Top
Methods
  NameDescription
Public methodCompute Obsolete.
Computes the Stepwise Logistic Regression.
Public methodDoStep
Computes one step of the Stepwise Logistic Regression Analysis.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodLearn
Learns a model that can map the given inputs to the given outputs.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

The Backward Stepwise regression is an exploratory analysis procedure, where the analysis begins with a full (saturated) model and at each step variables are eliminated from the model in a iterative fashion.

Significance tests are performed after each removal to track which of the variables can be discarded safely without implying in degradation. When no more variables can be removed from the model without causing a significant loss in the model likelihood, the method can stop.

Examples
// Suppose we have the following data about some patients.
// The first variable is continuous and represent patient
// age. The second variable is dichotomic and give whether
// they smoke or not (this is completely fictional data).

double[][] inputs =
{
    //            Age  Smoking
    new double[] { 55,    0   },  // 1
    new double[] { 28,    0   },  // 2
    new double[] { 65,    1   },  // 3
    new double[] { 46,    0   },  // 4
    new double[] { 86,    1   },  // 5
    new double[] { 56,    1   },  // 6
    new double[] { 85,    0   },  // 7
    new double[] { 33,    0   },  // 8
    new double[] { 21,    1   },  // 9
    new double[] { 42,    1   },  // 10
    new double[] { 33,    0   },  // 11
    new double[] { 20,    1   },  // 12
    new double[] { 43,    1   },  // 13
    new double[] { 31,    1   },  // 14
    new double[] { 22,    1   },  // 15
    new double[] { 43,    1   },  // 16
    new double[] { 46,    0   },  // 17
    new double[] { 86,    1   },  // 18
    new double[] { 56,    1   },  // 19
    new double[] { 55,    0   },  // 20
};

// Additionally, we also have information about whether
// or not they those patients had lung cancer. The array
// below gives 0 for those who did not, and 1 for those
// who did.

double[] output =
{
    0, 0, 0, 1, 1, 1, 0, 0, 0, 1,
    0, 1, 1, 1, 1, 1, 0, 1, 1, 0
};


// Create a Stepwise Logistic Regression analysis
var regression = new StepwiseLogisticRegressionAnalysis(inputs, output,
    new[] { "Age", "Smoking" }, "Cancer");

regression.Compute(); // compute the analysis.

// The full model will be stored in the complete property:
StepwiseLogisticRegressionModel full = regression.Complete;

// The best model will be stored in the current property:
StepwiseLogisticRegressionModel best = regression.Current;

// Let's check the full model results
DataGridBox.Show(full.Coefficients); 

// We can see only the Smoking variable is statistically significant.
// This is an indication the Age variable could be discarded from
// the model.

// And check the best inner model result
DataGridBox.Show(best.Coefficients);

// This is the best nested model found. This model only has the 
// Smoking variable, which is still significant. Since no other
// variables can be dropped, this is the best final model.

// The variables used in the current best model are
string[] inputVariableNames = best.Inputs; // Smoking

// The best model likelihood ratio p-value is
ChiSquareTest test = best.ChiSquare; // {0.816990081334823}

// so the model is distinguishable from a null model. We can also
// query the other nested models by checking the Nested property:

DataGridBox.Show(regression.Nested);

// Finally, we can also use the analysis to classify a new patient
double y = regression.Current.Regression.Compute(new double[] { 1 });

// For a smoking person, the answer probability is approximately 83%.
See Also