Our Statistics and Probability experts always do their best to answer most of the questions posted on this platform. We have always provided free myMathlab Answers on our website. If we have not answered this question, then we'll be on it very soon. However, sometimes we get engaged, and we might not answer it within the time you expect. In any case, if you are looking to pay someone to help you with your online classes , or to answer this question, then we are at your service. Our experts can also help you complete your online statistics classes. You can contact us via WhatsApp or use MyMathLab Homework Help link.
#### LOGISTIC REGRESSION using R
The importance of splitting the dataset into a test data and a Training data is for purposes of testing the accuracy of the prediction model.
bankloan <- read.csv("bankloan.csv")
bankloan <- bankloan[complete.cases(bankloan), ]
# train- and test sets creation
set.seed(12345); Use set.seed () so that you can obain similar results everytime the dataset is selected.
train.prop <- 0.8 # 80% of the data is set as the test data
train.cases <- sample(nrow(bankloan),
nrow(bankloan) * train.prop)
bankloan.train <- bankloan[train.cases, ]
bankloan.test <- bankloan[-train.cases, ]
# LR model fit
glm.fit <- glm(default ~ employ + address + debtinc
+ creddebt, data = bankloan.train, family = "binomial")
# posterior probabilities # The posterior proababilities are assigned to a variable so that the table is constructed.
glm.prob <- predict(glm.fit, bankloan.test, type = "response")
# a class variable
glm.class <- glm.prob
glm.class[glm.class > 0.5] <- "Yes"
glm.class[glm.class <= 0.5] <- "No"
#### Test the accuracy of the Model.
# confusion matrix
# prediction accuracy
mean(glm.class == bankloan.test$default)
# adjusted rand index