4) Forward Stepwise Logistic Regression.

This Blog entry is from the Logistic Regression section in Learn R.

As previous Blog entries allude, whereas the linear regression function in R was lm(), the logistic regression function is glm(), with supplementary parameters specifying the family as being a binomial distribution (which is a stalwart distribution for classification problems).  The syntax is very similar to create a logistic regression model, albeit including the family argument to detail the type of curve to fit:

LogisticRegressionModel <- glm(Dependent ~ Count_Unsafe_Terminals_1_Day,data=FraudRisk,family="binomial")
1.png

Run the line of script to console:

2.png

As with a lm() type model, the summary() function can return the model output:

summary(LogisticRegressionModel)
3.png

Run the line of script to console:

4.png

As with models created using the lm() function, the summary is somewhat inadequate to get the coefficients with correct precision, notwithstanding that the predict.glm() function will be used for recall:

coefficients(LogisticRegressionModel)
5.png

Run the line of script to console to output the coefficients for a manual deployment of the logistic regression model:

6.png

This Blog entry would naturally lead into a stepwise multiple logistic regression model, and in this example a factor as created in preceding Blog entries will be added with the assumption that it is the next strongest correlating factor:

7.png

Run the line of script to console:

8.png

Write out the coefficients to observe the treatment of each different state inside the factor TypeFactor:

9.png