Generalized Linear Models: Binary Logistic Regression

Kim Johnson, Ziyun Meng

2025-09-24

Learning Objectives

  1. Understand what generalized linear models are
  2. Understand the use of logistic models and its assumptions
  3. Know how to estimate logistic models in R, check assumptions and interpret results
  4. Basic knowledge of Receiver Operating Characteristic (ROC) Curves and understand what AUC is (this may show up as extra credit on an exam)

What is a generalized linear model (GLM)?

The logistic model

The probability can be constrained between 0 and 1 by taking the natural log of the odds, which has a range from -∞ to ∞ solving our problem

The logistic model

Predicted probabilities

Research questions and hypotheses

Assessing model fit for the logistic model

  1. Likelihood ratio test
  2. Wald test
  3. Pseudo R2
  4. Hosmer and Lemeshow GOF test
  5. Wald test for individual variables

1. Likelihood Ratio Test (LR test or LRT)

What it is: Compares the fit of two nested models (a full model and a reduced model with the same number of observations). The reduced model is a special case of the full model with one or more variables omitted.

Purpose: To test whether adding one or more predictors significantly improves the models ability to explain the data.

How it works:

This statistic follows a chi-square distribution with degrees of freedom equal to the difference in the number of estimated parameters (df between the models).

Significant p-value: The full model provides a better fit than the reduced model

LR test example

Reduced model: log odds of heart disease= \(\beta_0\) + \(\beta_1\)*income

We could then ask if sex improves the model fit:

Full model: log odds of heart disease= \(\beta_0\) + \(\beta_1\)*income + \(\beta_2\)*sex

The reduced and full model can be compared using the LRT. A significant p-value indicates an improvement in model fit.

2. Wald test (for more than one predictor)

What it is: Compares whether a set of regression coefficients are all equal to zero. Can test blocks of predictors.

Purpose: To determine if a group of predictors improves the model’s ability to predict the outcome.

How it works:

Significant p-value: At least one of coefficient is not zero (the block improves model fit)

3. Pseudo \(R^2\)

What it is: There is no \(R^2\) like in linear regression that gives the percent of variance explained by the model. Instead, there is a pseudo R2 with several variations (McFadden’s, Cox and Snell’s, Nagelkerke’s)

Purpose: To mimic the \(R^2\)

Interpretation of Pseudo \(R^2\): higher values indicate better fit. There is no interpretation like \(R^2\) in linear regression

Suggest not using (more discussion on that can be found at https://statisticalhorizons.com/r2logistic/#)

4. Hosmer and Lemeshow Goodness of Fit test

What it is: A statistical test that checks how well the model’s predicted probabilities agree with the actual observed outcomes.

Purpose: To evaluate whether the logistic regression model provides an adequate overall fit to the data.

How it works:

  1. Sort subjects by predicted probability of the outcome.

  2. Divide them into groups (often 10 groups, or “deciles”)

  3. For each group, compare the number of observed events vs. the number expected from the model.

  4. Calculate a chi-square statistic across all groups.

Interpretation:

High p-value (e.g., >0.05): The predicted and observed outcomes match reasonably well. There is no evidence of poor fit.

Low p-value (e.g., <0.05): The model predictions differ from what was observed. The model may not fit adequately.

Note: In very large samples, even small differences can lead to a significant result.

5. Wald test (for one predictor)

What it is: Tests whether an individual regression coefficient is equal to zero.

Purpose: To evaluate whether a single predictor has a statistically significant association with the outcome after adjusting for all other predictors in the model.

How it works:

  1. Estimate \(\beta_i\) and its standard error
  2. Compute the Wald statistic according to the formula:

\(Z\) = \(\beta\)/\(SE\)

  1. Square of this statistic follows a chi-square distribution with 1 degree of freedom

Interpretation:

Significant p-value: The predictor is associated with the outcome.

Assumptions

Assumption Description Example Test
Independence of observations Observations are not related to each other Counties in the same state NA
No multicollinearity among explanatory variables Variables are not measuring similar things Weight and BMI VIF
No extreme outliers No influential observations A billionaire income

Cook’s Distance DFFITS

DFBETAS

Linearity Association between continuous IV and log odds of DV is linear income is linearly related to outcome on log scale Box Tidwell test

Testing assumptions

Linearity assumption: In linear regression, each continous predictor is assumed to have a linear association with the outcome. In logistic regression, each continuous predictor is assumed to have a linear association with the log odds of the outcome.

Box Tidwell test can check this

Multicollinearity: This happens when predictors are highly correlated with each other (i.e. they measure similar or the same thing). This makes it difficult to estimate their individual effects on the outcome.

The VIF test can check this.

Testing assumptions

Influential observations

Typically, one should not remove influential values unless there is a very good reason to do so. Avoid “cherry-picking” and “p-hacking”. Be very clear about what data was removed and why it was removed when reporting results.

Interpreting odds ratios

Example interpretations

Categorical exposure

OR = 5.65 and 95% CI (3.98 to 8.36): Compared to those who were categorized as underweight, the odds of reporting diabetes was 5.65 (95% CI 3.98 to 8.36) times higher for those who were categorized as obese.

The odds of diabetes in individuals in the obese BMI category is 5.65 (95% CI 3.98 to 8.36) times higher than the odds of diabetes in individuals in the underweight category.

OR = 0.18 and 95% CI (0.12 to 0.25): The odds of diabetes in those who are underweight is 0.18 (95% CI 0.12 to 0.25) times the odds of diabetes in those who are obese.

The odds of diabetes in individuals in the underweight bmi category is 82% (OR = 0.18, 95% CI 0.12 to 0.25) lower than the odds of diabetes in individuals in the obese category.

Continuous exposure

OR = 1.09 (95% CI 1.08 to 1.10). For every one unit increase in BMI, the odds of diabetes increases by 9% (OR = 1.09, 95% CI 1.08 to 1.10).

For every one unit increase in BMI, the odds of diabetes increases by 1.09 (95% CI 1.08 to 1.10) times.

OPTIONAL MATERIAL TO REVIEW ON YOUR OWN (or with Kim or Kyle in an office hour appointment)

Predictive modeling

Recall some basic relevant concepts from Epidemiology

Predicted probabilities and model predicted outcomes

Receiver Operating Characteristic (ROC) curves

Area under the curve (AUC)

AUC value interpretation

0.9 ≤ AUC Excellent

0.8 ≤ AUC < 0.9 Good

0.7 ≤ AUC < 0.8 Fair

0.6 ≤ AUC < 0.7 Poor

0.5 ≤ AUC < 0.6 Fail

ROC Curve Application Examples