#Logistic Regression
install.packages(c("mlbench","pROC","ggplot2"))
library("mlbench")
library("pROC")
library("ggplot2")

# Load the dataset
data(PimaIndiansDiabetes)
data <- PimaIndiansDiabetes
# fit model
fit <- glm(diabetes~., data=data, family=binomial(link='logit'))
# summarize the fit
print(fit)
summary(fit)
# make predictions
probabilities <- predict(fit, PimaIndiansDiabetes[,1:8], type='response')
predictions <- ifelse(probabilities > 0.5,'pos','neg')
# summarize accuracy
table(predictions, data$diabetes,dnn =  c("Observado", "Esperado"))
# ROC curve
x <- c()
x[data[,9]== "pos"]<- 1
x[data[,9]== "neg"]<-0
p<- plot.roc(x, probabilities)
pROC::auc(p)
