2026-11-01

The question

Diabetes is closely tied to how the body handles sugar and insulin, and it raises the risk of serious problems such as heart disease.

Can we predict whether a patient has diabetes from a few simple measurements?

  • The outcome is yes/no, not a number
  • Ordinary linear regression does not fit a yes/no outcome well
  • We need a model for a probability: logistic regression

The data

Medical records of 532 women of Pima Indian heritage (age 21 or older) in Arizona.

Variable Meaning
type Diabetes status (outcome)
glu Plasma glucose concentration (mg/dL)
bmi Body mass index
age Age in years

About 33.3% of the women in the data have diabetes.

Why not linear regression?

If \(Y = 1\) for diabetes and \(Y = 0\) otherwise, then \(E(Y) = P(Y=1) = p\).

A straight line \(p = \beta_0 + \beta_1 x\) can give values below 0 or above 1, which makes no sense for a probability.

Fix: model the log-odds instead, which can be any real number:

\[\log\left(\frac{p}{1-p}\right) = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_3 x_3\]

The logistic model

Solving the log-odds equation for \(p\) gives an S-shaped curve:

\[p = P(Y=1 \mid x) = \frac{1}{1 + e^{-(\beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_3 x_3)}}\]

  • Always between \(0\) and \(1\)
  • Coefficients are estimated by maximum likelihood (not least squares)
  • \(e^{\beta_j}\) is the odds ratio: the factor by which the odds of diabetes are multiplied when \(x_j\) rises by one unit

Glucose differs a lot between the groups

Probability of diabetes rises with glucose

The R code behind the model

library(ggplot2)

pima <- rbind(MASS::Pima.tr, MASS::Pima.te)
pima$diabetes <- as.integer(pima$type == "Yes")

# Logistic regression with three predictors
fit <- glm(diabetes ~ glu + bmi + age, data = pima, family = binomial)
summary(fit)

# Odds ratios
exp(coef(fit))

# Plot the S-shaped curve for glucose alone
ggplot(pima, aes(x = glu, y = diabetes)) +
  geom_jitter(height = 0.04, alpha = 0.4) +
  geom_smooth(method = "glm", method.args = list(family = "binomial"))

The fitted model

\[\log\left(\frac{\hat p}{1-\hat p}\right) = -9.43 +0.034\,glu +0.084\,bmi +0.049\,age\]

##             Estimate Odds ratio  p-value
## (Intercept)   -9.429      0.000 1.47e-27
## glu            0.034      1.035 3.09e-17
## bmi            0.084      1.088 1.74e-06
## age            0.049      1.050 2.89e-06

Interpreting the odds ratios

  • Glucose: each extra 10 mg/dL multiplies the odds of diabetes by about 1.41, holding BMI and age fixed
  • BMI: each extra unit multiplies the odds by about 1.09
  • Age: each extra year multiplies the odds by about 1.05

All three predictors are statistically significant, and the 95% confidence interval for the glucose odds ratio (per 1 mg/dL) is (1.027, 1.043).

Interactive plot: glucose vs. BMI

Hover over the points to see values.

How well does the model predict?

Classify a patient as “diabetes” if \(\hat p > 0.5\):

##                         Actual
## pred_class               No diabetes Diabetes
##   Predicted: Diabetes             41      103
##   Predicted: No diabetes         314       74

Accuracy: \(\dfrac{\text{correct predictions}}{n} = 0.216\)

The model is right about 22% of the time. It is better than guessing, but it misses some patients with diabetes, so it is a screening aid, not a diagnosis.

Summary

  • Logistic regression models the log-odds of a yes/no outcome
  • Higher glucose, higher BMI, and older age all raise the odds of diabetes
  • Glucose is the strongest predictor in this data
  • Limits: one population, no insulin or heart disease measurements, and association does not mean causation

Thank you!