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:
A random component specifying the distribution of the response variable (e.g., normal, binomial, Poisson).
A systematic component specifying a linear predictor .
A link function that relates the mean of the response to the linear predictor: .
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.
Choosing distributions and link functions
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:
Gaussian family (identity link): continuous outcomes with roughly constant variance (ordinary linear regression).
Binomial family (logit or probit link): binary outcomes or proportions (logistic regression).
Poisson family (log link): count outcomes with mean equal to variance (Poisson regression).
Gamma family (inverse or log link): positive continuous outcomes with variance proportional to the square of the mean (e.g., cost or time data).
Inverse Gaussian family (inverse squared link): right–skewed positive continuous outcomes.
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 , each additional day in hospital multiplies the expected cost by 1.10 (a 10% increase).
Interpretation
Model fit. Use diagnostic plots and information criteria to assess whether the chosen distribution and link provide a good fit. Compare alternative links (e.g., identity vs log) and distributions.
Overdispersion. For count data, check whether the variance exceeds the mean. If so, consider a negative binomial model or quasi-Poisson approach.
Zero–inflated models. When there are excessive zeros, as in hospital infection counts, zero–inflated or hurdle models may be appropriate.
Transformations. Sometimes transforming the outcome (e.g., log transformation) and using linear regression can suffice, but GLMs provide a coherent probabilistic framework.
Exercises
Exercises
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.
Simulate count data with a mean–variance relationship . Fit Poisson and quasi-Poisson models and examine standard errors.
For a binary outcome with event probability 0.8, fit both a logit and probit model. Compare the estimated coefficients and predicted probabilities.
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.