StepwiseLogisticRegressionAnalysis Class 
Namespace: Accord.Statistics.Analysis
[SerializableAttribute] public class StepwiseLogisticRegressionAnalysis : IRegressionAnalysis, IMultivariateAnalysis, IAnalysis, ISupervisedLearning<LogisticRegression, double[], double>
The StepwiseLogisticRegressionAnalysis type exposes the following members.
Name  Description  

StepwiseLogisticRegressionAnalysis(Double, Double) 
Constructs a Stepwise Logistic Regression Analysis.
 
StepwiseLogisticRegressionAnalysis(Double, Double, String, String) 
Constructs a Stepwise Logistic Regression Analysis.

Name  Description  

Complete 
Gets the full model.
 
Current 
Gets the current best nested model.
 
Inputs 
Gets or sets the name of the input variables.
 
Iterations 
Gets or sets the maximum number of iterations to be
performed by the regression algorithm. Default is 50.
 
Nested 
Gets the collection of nested models obtained after
a step of the backward stepwise procedure.
 
Output 
Gets or sets the name of the output variables.
 
Outputs 
Gets the dependent variable value
for each of the source input points.
 
Result 
Gets the resulting probabilities obtained
by the most likely logistic regression model.
 
Source 
Source data used in the analysis.
 
Threshold 
Gets or sets the significance threshold used to
determine if a nested model is significant or not.
 
Token 
Gets or sets a cancellation token that can be used to
stop the learning algorithm while it is running.
 
Tolerance 
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 1e5.
 
Variables 
Gets the final set of input variables indices
as selected by the stepwise procedure.

Name  Description  

Compute  Obsolete.
Computes the Stepwise Logistic Regression.
 
DoStep 
Computes one step of the Stepwise Logistic Regression Analysis.
 
Equals  Determines whether the specified object is equal to the current object. (Inherited from Object.)  
Finalize  Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)  
GetHashCode  Serves as the default hash function. (Inherited from Object.)  
GetType  Gets the Type of the current instance. (Inherited from Object.)  
Learn 
Learns a model that can map the given inputs to the given outputs.
 
MemberwiseClone  Creates a shallow copy of the current Object. (Inherited from Object.)  
ToString  Returns a string that represents the current object. (Inherited from Object.) 
Name  Description  

HasMethod 
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)  
ToT  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.)  
ToT  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 Matrix.) 
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.
// 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 pvalue 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%.