Hi you all, I have a question toward relevel the reference class in Logistic Regression. I used exactly the same codes as my professor giving but the reference class still not functioned as I set, anyone knows what is the reason for that?
Below are my code script. For some reason the forum does not accept my csv file, I did not mean to be rude, but if you guys could recognisize something, that would be great. Thanks a lot!
# install and acticate the following package # "regclass" # R-Studio logistic regression with OrganicsData.csv data OrganicsData <- read.csv ogdata <- OrganicsData summary(ogdata) attach(ogdata) ## relevel DemGender & PromClass DemGender <- relevel(DemGender, ref = "M") PromClass <- relevel(PromClass, ref = "Silver") ## since the outcome variable TargetBuy is stored as integer ## convert the column into factors TargetBuy <- as.factor(TargetBuy) # fit a logistic regression model with the given set of variables finalmodel <- glm(TargetBuy ~.-ï..ID, data = ogdata, family = binomial) # View estimation results summary(finalmodel) # compute and display odds ratios oddsratios <- exp(coef(finalmodel)) oddsratios # predicting the probabilities for individual cases from model predicted_probabilities <- predict(finalmodel, ogdata, type= "response") View(predicted_probabilities) ## setting a threshold to then predict 1 or 0 threshold <- 0.5 predictions <- factor( ifelse(predicted_probabilities >= threshold, 1, 0)) odata <- ogdata odata <- cbind(odata, predicted_probabilities, predictions) View(odata) # Confusion Matrix for the Logistic Regression model # install and acticate the following package # regclass ## use the confusion_matrix() function from this package confusion_matrix(finalmodel)