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")

Run the line of script to console:


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


Run the line of script to console:


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:


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


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:


Run the line of script to console:


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