Book contents

REGRESSION MODELLING FOR HEALTH PRACTITIONERS · CHAPTER 8

Generalized Linear Models

Unifying regression frameworks

The linear, logistic and Poisson models introduced in previous chapters are all special cases of the generalized linear model (GLM) framework. A GLM consists of three components:

  1. A random component specifying the distribution of the response variable (e.g., normal, binomial, Poisson).

  2. A systematic component specifying a linear predictor η=β0+β1x1+⋯+βpxp\eta = \beta_0 + \beta_1 x_1 + \cdots + \beta_p x_p.

  3. A link function g(⋅)g(\cdot) that relates the mean of the response to the linear predictor: g(μ)=ηg(\mu) = \eta.

GLMs allow us to model different types of data—continuous, binary, counts—within a common framework by choosing appropriate distributions and link functions. For example, linear regression uses the identity link and normal distribution, logistic regression uses the logit link and binomial distribution, and Poisson regression uses the log link and Poisson distribution.

When selecting a GLM for health data, match the distribution to the nature of the response and choose a link function that ensures predicted values lie in the appropriate range. Common families include:

Choosing the link function influences interpretability: the log link yields multiplicative effects (rate ratios), while the identity link yields additive effects.

Worked example: modelling hospital costs

Suppose we model hospital costs, a positive continuous variable that often exhibits right skewness. A gamma GLM with a log link can accommodate skewness and ensure positive predictions. Let Cost denote total cost, Age and LOS (length of stay) be predictors.

Worked example

R

# df has columns: Cost (positive), Age, LOS
fit_gamma <- glm(Cost ~ Age + LOS, family = Gamma(link = "log"), data = df)
summary(fit_gamma)
exp(coef(fit_gamma))  # multiplicative effect on expected cost

Python (statsmodels)

import statsmodels.api as sm
import statsmodels.formula.api as smf

# df: DataFrame with Cost, Age, LOS
model = smf.glm('Cost ~ Age + LOS', data=df,
                family=sm.families.Gamma(link=sm.families.links.log()))
result = model.fit()
print(result.summary())
print(np.exp(result.params))

Julia

using DataFrames, GLM

# df: DataFrame with Cost, Age, LOS
fm = @formula(Cost ~ Age + LOS)
fit_gamma = glm(fm, df, Gamma(), LogLink())
coeftable(fit_gamma)
exp.(coef(fit_gamma))

In the gamma model with a log link, exponentiated coefficients represent the multiplicative change in mean cost associated with a one–unit increase in the predictor. For instance, if exp(βLOS)=1.10\exp(\beta_{LOS}) = 1.10, each additional day in hospital multiplies the expected cost by 1.10 (a 10% increase).

Interpretation

Exercises

Exercises

  1. For a dataset on patient costs, compare models using (i) linear regression on log–transformed cost, (ii) gamma regression with log link, and (iii) gamma regression with inverse link. Evaluate model fit and interpret the coefficients.

  2. Simulate count data with a mean–variance relationship Var(Y)=1.5𝔼[Y]\operatorname{Var}(Y)=1.5\,\mathbb{E}[Y]. Fit Poisson and quasi-Poisson models and examine standard errors.

  3. For a binary outcome with event probability 0.8, fit both a logit and probit model. Compare the estimated coefficients and predicted probabilities.

  4. Explore how the choice of link function affects interpretability using a GLM with a log vs identity link for a positive outcome.

Code examples use illustrative datasets. Supply data with the named columns to run them.