
## https://www.kaggle.com/datasets/pentakrishnakishore/diabetes-csv

rm(list=ls())

D = read.csv("diabetes.csv",header=TRUE)
attach(D)
n = nrow(D)

names(D)

### GLM all features
out = glm(Outcome ~.,data=D,family="binomial")
summary(out)


### GLM Only Glucose
out = glm(Outcome ~ Glucose,data=D,family="binomial")
summary(out)

## Call:
## glm(formula = Outcome ~ Glucose, family = "binomial", data = D)
## 
## Coefficients:
##              Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -5.350080   0.420827  -12.71   <2e-16 ***
## Glucose      0.037873   0.003252   11.65   <2e-16 ***
## ---
## Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 993.48  on 767  degrees of freedom
## Residual deviance: 808.72  on 766  degrees of freedom
## AIC: 812.72
## 
## Number of Fisher Scoring iterations: 4




beta0 = out$coefficients[1]
beta1 = out$coefficients[2]
beta0;  beta1
o = order(Glucose)
fun = exp(beta0+beta1*Glucose[o])/(1+exp(beta0+beta1*Glucose[o]))
pdf("Logistic_estimate.pdf")
plot(Glucose[o],fun,type="l",col="purple",lwd=4,ylab="",xlab="",
                ylim=c(0,1),cex.axis=1.3)
points(out$y,pch=20,cex=1.3,col="red")
title(ylab="Diabetes", line=2.1, cex.lab=2)
title(xlab="Glucose",line=2.6, cex.lab=2)
dev.off()

print(confint(out))







