HSCI 410 · Lesson 4

Generalized Linear Models

Exploratory Data Analysis For Epidemiology

Learning objectives for this lesson:

  1. Classify an outcome as continuous, count, binary, ordinal or nominal from what its values mean, and choose the matching regression model and the name of its exponentiated coefficient (a difference in means, an odds ratio, a relative risk ratio or an incidence rate ratio).
  2. Explain why binary, categorical and count outcomes break the assumptions of linear regression, identify which residual plot checks each assumption, and describe a generalized linear model by its distribution, link function and linear predictor.
  3. Interpret an odds ratio from a logistic regression with its confidence interval, explain why crude and adjusted odds ratios can differ, and judge whether a model has enough events per predictor.
  4. Explain why an ordinal outcome is analysed with ordinal logistic regression, interpret its odds ratios and predicted probabilities, and judge the proportional-odds assumption from a Brant test, naming what to do if it fails.
  5. Explain why a nominal outcome is analysed with multinomial logistic regression, interpret its relative risk ratios (naming both categories) and predicted probabilities, and explain the role of the reference category and the independence of irrelevant alternatives.
  6. Describe count outcomes and the Poisson distribution, interpret incidence rate ratios from a Poisson regression, and explain when an offset is needed and what the rate ratios then compare.
  7. Check a Poisson model for overdispersion with the dispersion ratio and the observed and expected zeros, explain what overdispersion does to standard errors, and choose between Poisson and negative binomial regression with these checks and the AIC.

This course was developed by Dr. Kiffer G. Card based on Dohoo, I. R., Martin, S. W., & Stryhn, H. (2012). Methods in Epidemiologic Research. VER Inc.

Reference

Glossary: Key Terms, People & Concepts

📚 Reference page, available throughout the lesson

This glossary collects the key concepts, methods and people in this lesson. It can be used as a reference while working through the material or as a review before assessments. Typing in the search box filters the entries.

Key Concepts & Ideas
Outcome Variable The outcome variable is the variable a model tries to explain or predict, such as blood pressure or self-rated health. Its type decides which regression model is used.
Predictor A predictor is a variable used to explain or predict the outcome, such as age or smoking. Every model in this lesson uses age and smoking as predictors.
Continuous Variable A continuous variable is a numeric variable that can take any value in a range, including decimals, such as systolic blood pressure. It is modelled with linear regression.
Discrete Variable (Count) A discrete variable is a numeric variable that takes only whole numbers. A count records how many times an event happened, such as urgent care visits in a year, and it is modelled with Poisson or negative binomial regression.
Categorical Variable A categorical variable places each person into a group. It can be binary, ordinal or nominal.
Binary Variable A binary variable is a categorical variable with exactly two groups, such as hypertension (yes or no). It is modelled with logistic regression.
Ordinal Variable An ordinal variable is a categorical variable with three or more groups that have a natural order but unknown spacing, such as self-rated health from poor to excellent. It is modelled with ordinal logistic regression.
Nominal Variable A nominal variable is a categorical variable with three or more groups that have no natural order, such as usual place of care. It is modelled with multinomial logistic regression.
Assumption An assumption is a condition that must hold for a model's estimates, confidence intervals and p-values to be trustworthy. Each assumption has a matching check.
Residual A residual is the difference between an observed value and the value the model predicts for it. Most checks of linear regression look at the residuals.
Independence Independence is the assumption that each observation is unrelated to every other observation. It is judged from the study design, and it fails with repeated or clustered measurements.
Overdispersion Overdispersion occurs when count data are more spread out than a Poisson model allows, so the variance is larger than the mean. It makes Poisson standard errors too small.
Reference Category The reference category is the category that the other categories are compared with. In a multinomial model every other outcome category is compared with it, and for a predictor such as smoking it is the group (non-smokers) that the other group is compared with.
Offset An offset is the log of each person's follow-up time (or a population size), added to a count model with its coefficient fixed at 1. It turns a model for counts into a model for rates.
Methods & Statistical Concepts
Linear Regression Linear regression is a model for a continuous outcome in which the average outcome is a straight-line function of the predictors. It is fitted in R with lm(), and its coefficients are differences in means.
LINE Assumptions The LINE assumptions are the four assumptions of linear regression: Linearity, Independence, Normality of the residuals and Equal variance of the residuals. All except independence are checked with plot(model).
Q-Q Plot A Q-Q plot compares the residuals with a normal distribution. Points close to the diagonal line support the normality assumption.
Equal Variance (Homoscedasticity) Equal variance is the assumption that the residuals are spread about equally at every predicted value. A funnel shape in the residual plots suggests that it fails.
Cook's Distance Cook's distance measures how much a single observation changes the fitted model. Points beyond the dashed Cook's distance lines in the residuals versus leverage plot are influential.
Generalized Linear Model (GLM) A generalized linear model is a regression model with three parts: a distribution for the outcome, a linear predictor, and a link function that connects the average outcome to the linear predictor.
Link Function The link function is the transformation of the average outcome that is set equal to the linear predictor, such as the logit (log-odds) in logistic regression or the log in Poisson regression.
Linear Predictor The linear predictor is the weighted sum β0 + β1X1 + β2X2 + … that combines the predictors, as in linear regression.
Logistic Regression Logistic regression is the GLM for a binary outcome, with a binomial distribution and a logit link. Its exponentiated coefficients are odds ratios.
Events per Predictor Events per predictor is the number of events (people with the outcome) divided by the number of predictors. A common rule of thumb for logistic regression asks for about 10.
Ordinal Logistic Regression Ordinal logistic regression is a model for an ordered outcome that fits every at-or-above split at once, with one odds ratio per predictor. It is also called the proportional-odds model and is fitted with MASS::polr().
Proportional-Odds Assumption The proportional-odds assumption states that each predictor has the same odds ratio at every split of an ordinal outcome. It is checked with the Brant test.
Brant Test The Brant test checks the proportional-odds assumption by comparing coefficients across the splits of an ordinal outcome. A p-value above 0.05 means the data are consistent with the assumption, and the test is run with brant::brant().
Multinomial Logistic Regression Multinomial logistic regression is a model for a nominal outcome that compares each category with a reference category, with separate coefficients for each comparison. It is fitted with nnet::multinom().
Relative Risk Ratio (RRR) A relative risk ratio is the exponentiated coefficient of a multinomial model. It compares the ratio of one category to the reference category between two groups.
Independence of Irrelevant Alternatives (IIA) The IIA assumption states that the comparison between two categories of a multinomial outcome does not change when other categories are added or removed. It is doubtful when two categories are close substitutes.
Predicted Probability A predicted probability is the probability of an outcome category that a fitted model gives for a chosen combination of predictor values. It is obtained with predict(model, newdata, type = "probs").
Poisson Distribution The Poisson distribution describes counts of independent events that occur at a constant rate. Its variance equals its mean.
Poisson Regression Poisson regression is the GLM for a count, with a Poisson distribution and a log link. It is fitted with glm(family = poisson), and its exponentiated coefficients are incidence rate ratios.
Incidence Rate Ratio (IRR) An incidence rate ratio is the exponentiated coefficient of a Poisson or negative binomial model. It gives the factor by which the expected count (or rate) is multiplied for a one-unit change in a predictor.
Dispersion Ratio The dispersion ratio is the sum of squared Pearson residuals divided by the residual degrees of freedom. A value close to 1 supports the Poisson model, and a value clearly above 1 signals overdispersion.
Negative Binomial Regression Negative binomial regression is a count model with an extra parameter, theta (θ), that lets the variance exceed the mean. It is fitted with MASS::glm.nb(), and its exponentiated coefficients are incidence rate ratios.
AIC (Akaike Information Criterion) The AIC measures model fit with a penalty for each estimated parameter, and a lower value is better. A difference of about 10 points or more is strong support for the lower-AIC model, provided both models are fitted to the same people.
Zero-Inflated and Hurdle Models Zero-inflated and hurdle models are count models for data with more zeros than even a negative binomial model expects. They are beyond the scope of this lesson.
Key People
John Nelder (1924–2010) and Robert Wedderburn (1947–1975) Nelder and Wedderburn were British statisticians who set out the generalized linear model in 1972, joining linear, logistic and Poisson regression in one framework.
Peter McCullagh (1952– ) McCullagh is an Irish statistician who developed the proportional-odds model for ordinal outcomes in 1980.
Rollin Brant Brant is a statistician who in 1990 published the test of the proportional-odds assumption that bears his name.
Siméon-Denis Poisson (1781–1840) Poisson was a French mathematician after whom the Poisson distribution and Poisson regression are named.
No matching entries. Try a different search term.
Section 1 of 4

Analyzing Different Outcome Types Using GLMs

⏱ Estimated time: 45 minutes
Lesson 4 · Section 1

Analyzing Different Outcome Types Using GLMs

Every outcome has a type, and the type of the outcome decides which regression model to use.

Variable types

Two families of variables

Numeric

Continuous variables can take any value in a range, such as blood pressure or BMI.

Discrete variables take whole numbers only, such as the number of clinic visits.

Categorical

Nominal variables have groups with no order, such as usual place of care.

Ordinal variables have groups with a natural order, such as self-rated health.

Binary variables have exactly two groups, such as hypertension (yes or no).

Running example

Five outcomes from the PHAA survey

Five bar charts or histograms, one for each outcome type: systolic blood pressure, urgent care visits, hypertension, self-rated health and usual place of care, each labelled with the model that suits it.
Each panel shows one outcome type from the PHAA survey (795 people with complete data), labelled with the model that suits it.
Review

Linear regression draws a straight line

Linear model for systolic blood pressure
\[ \color{#0B7B6B}{\text{SBP}} = \color{#6D28D9}{\beta_0} + \color{#1D4ED8}{\beta_1}\,\text{age} + \color{#C2410C}{\beta_2}\,\text{smoker} + \varepsilon \]
SBP outcome (mmHg) β0 intercept β1 change per year of age β2 smokers minus non-smokers
0.45
mmHg higher per extra year of age
6.06
mmHg higher in smokers than non-smokers of the same age
Assumptions

Linear regression rests on four assumptions (LINE)

L: Linearity

The average outcome changes in a straight line with each continuous predictor.

I: Independence

Each person's outcome is unrelated to every other person's outcome.

N: Normality

The residuals follow a roughly bell-shaped (normal) distribution.

E: Equal variance

The residuals are spread about equally at every predicted value.

A fifth check looks for influential points that pull the line toward themselves.

Model checking

plot(lin) draws the four checks

The four standard diagnostic plots for the linear model of systolic blood pressure on age and smoking: residuals versus fitted, Q-Q residuals, scale-location and residuals versus leverage.
All four panels look acceptable: a flat cloud, points on the Q-Q line, an even spread, and no point beyond Cook's distance.
Limits of the straight line

Other outcomes break these assumptions

Binary

The outcome is 0 or 1. A straight line can predict values below 0 or above 1, and the residuals cannot be normal.

Counts

Counts cannot be negative, pile up near zero, and spread out more as the average rises.

Categories

Ordinal and nominal groups have no numeric spacing, so a slope per one-unit step has no meaning.

Generalized linear models

A GLM keeps the line and changes two things

The GLM recipe
\[ \color{#C2410C}{g}\big(\color{#0B7B6B}{\text{average of } Y}\big) = \color{#6D28D9}{\beta_0 + \beta_1 X_1 + \beta_2 X_2} \]
g link function average of Y the mean or probability being modelled β0 + β1X1 + … linear predictor

1. Distribution (family)

The distribution describes the kind of values the outcome takes, such as normal, binomial, Poisson or negative binomial.

2. Link function

The link function transforms the average, for example with the log or the logit (log-odds).

Model menu

One outcome type, one model

Outcome typeModelR functioneβ is a…
ContinuousLinear regressionlm()(not exponentiated) difference in means
BinaryLogistic regressionglm(family = binomial)odds ratio
OrdinalOrdinal logistic regressionMASS::polr()odds ratio
NominalMultinomial logistic regressionnnet::multinom()relative risk ratio
CountPoisson regressionglm(family = poisson)incidence rate ratio
Overdispersed countNegative binomial regressionMASS::glm.nb()incidence rate ratio
Review

Logistic regression and its checks

2.65
odds ratio for smokers (95% CI 1.04 to 6.30)
1.05
odds ratio per year of age (95% CI 1.01 to 1.08)
  • The outcome has exactly two categories, and observations are independent.
  • Each continuous predictor has a straight-line relationship with the log-odds.
  • There are about 10 events per predictor (23 events here support about two predictors).
Carry forward

What to take into the next section

  • The type of the outcome is identified first: continuous, binary, ordinal, nominal or count.
  • Every model has assumptions, and each assumption has a check that is run after fitting.
  • A GLM keeps the linear predictor and changes the distribution and the link, which sets the meaning of eβ.

Overview

Regression models describe how an outcome changes with one or more predictors. The two most familiar are linear regression for a continuous outcome and logistic regression for a binary (yes-or-no) outcome. Many outcomes in public health are neither continuous nor binary. Self-rated health is recorded in ordered categories, the place a person usually goes for care is a choice among unordered options, and the number of emergency visits is a count. This lesson presents one model for each of these outcome types. This first section shows how to classify a variable and match an outcome to its model, reviews linear regression and the assumptions on which it rests, explains why other types of outcome break those assumptions, and introduces generalized linear models (GLMs), the family to which every model in the lesson belongs. It closes with a review of logistic regression in R, the GLM for a binary outcome.

Learning Objectives

  • 1.1 Classify a variable as continuous, discrete (count), binary, ordinal or nominal from what its values mean, rather than from how they are stored.
  • 1.2 Match each outcome type to its regression model and say what the model's exponentiated coefficient is called.
  • 2.1 State the four assumptions of linear regression and identify the plot from plot(model), or the feature of the study design, that checks each one.
  • 2.2 Explain why binary, categorical and count outcomes break the assumptions of linear regression.
  • 2.3 Describe the three parts of a generalized linear model: the distribution, the linear predictor and the link function.
  • 3.1 Fit a logistic regression in R, interpret its odds ratios with their confidence intervals, compare crude and adjusted odds ratios, and check that there are enough events per predictor.

1.1 Types of Variables

Every variable in a dataset belongs to one of two families. Numeric variables record an amount. They are continuous when any value in a range is possible (blood pressure, body mass index, age measured precisely) and discrete when only whole numbers are possible (the number of visits, cases or falls). Categorical variables place each person into a group. They are nominal when the groups have no natural order (usual place of care, type of cancer, province of residence) and ordinal when the groups have a natural order (self-rated health, pain rated none to severe, stage of disease). A categorical variable with exactly two groups is called binary.

Table 4.1 lists the five types with the family to which each belongs and an example of each from the PHAA data, the survey used throughout this lesson.

Table 4.1. The five types of variable, grouped into two families, with an example of each from the PHAA data.

FamilyTypeWhat the values look likeExample in the PHAA data
NumericContinuousAny value in a range, including decimalssystolic_bp (mmHg)
NumericDiscrete (count)Whole numbers 0, 1, 2, and so onurgent_visits in the past 12 months
CategoricalBinaryTwo groupshypertension (No, Yes)
CategoricalOrdinalThree or more groups with a natural orderself_rated_health (Poor to Excellent)
CategoricalNominalThree or more groups with no orderusual_care (Family doctor, Walk-in clinic, Emergency department, No usual place)

The type of a variable is decided by what its values mean, and the way it is stored in a file can mislead. Self-rated health might be stored as the numbers 1 to 5, yet it is still ordinal, because the distance between "good" and "very good" is unknown. A postal code is made of characters and numbers, yet it is nominal. Click each of the five cards below to read a fuller description of each type, with further examples and the model that each type of outcome calls for.

ContinuousClick to explore
Discrete (Count)Click to explore
BinaryClick to explore
OrdinalClick to explore
NominalClick to explore

As the cards show, each type of outcome has its own model, which is why classification comes first. Worked Example 4.1 applies the definitions to the outcomes of four studies planned by a health unit; notice that each type is decided from what the values mean, not from how they are recorded.

Worked Example 4.1: Classifying Four Outcomes

A health unit plans four studies. The first records the number of falls each resident of a care home has in a year, which is a count. The second records whether each resident was admitted to hospital (yes or no), which is binary. The third asks residents how often they feel lonely (never, sometimes, often), which is ordinal. The fourth records the main reason for admission (infection, injury, heart condition, other), which is nominal. Each study therefore needs a different model, even if the predictors are identical.

Worked Example 4.1 shows that four studies with identical predictors can need four different models, because their outcomes differ in type. The next step turns this observation into a guide for choosing a model.

1.2 Matching the Outcome to a Model

The choice of model follows from the type of the outcome, and the predictors play no part in it. The decision guide in Figure 4.1 can be worked through for any new outcome. The first question is whether the outcome is numeric or categorical, and the second question narrows the choice to one model. Follow each row of the guide from its question to the model it leads to.

Figure 4.1. A decision guide that leads from the type of the outcome to a model, with one column for numeric outcomes and one for categorical outcomes.

Each model also has a name for its result, and that name is part of matching the outcome to the model. A linear regression coefficient is a difference in means and is not exponentiated. The other models report exponentiated coefficients, which are ratios: logistic regression reports odds ratios, ordinal logistic regression reports odds ratios for being in a higher category, multinomial logistic regression reports relative risk ratios, and Poisson and negative binomial regression report incidence rate ratios. Why these coefficients are exponentiated is explained with generalized linear models in 2.3, where Table 4.2 sets out the whole pairing in one place.

With a model matched to each type of outcome, the next step is to look closely at the model for a continuous outcome, linear regression, and at the assumptions that the other models are designed to relax.

2.1 Linear Regression and Its Assumptions

Linear regression models the average of a continuous outcome as a straight-line function of the predictors. For systolic blood pressure (SBP) in the PHAA survey, with age and smoking as predictors, the model is written as in Equation 4.1.

Linear regression for systolic blood pressure
\[ \color{#0B7B6B}{\text{SBP}} = \color{#6D28D9}{\beta_0} + \color{#1D4ED8}{\beta_1}\,\text{age} + \color{#C2410C}{\beta_2}\,\text{smoker} + \varepsilon \]Eq 4.1
A person's systolic blood pressure equals an intercept, plus a slope for age times their age, plus a difference for smokers if they smoke, plus a random error (ε) that captures everything the model leaves out.

When this model is fitted to the 795 people with complete data, the slope for age is 0.45 mmHg per year (95% CI 0.40 to 0.49) and the difference for smokers is 6.06 mmHg (95% CI 4.33 to 7.79). In R, lm() fits the model and confint() gives the intervals. The estimates can be trusted only if four assumptions are reasonable: linearity, independence, normality of the residuals and equal variance of the residuals, often remembered as LINE. A fifth check looks for single observations with too much influence. Three of the assumptions, and the check for influence, are read from the four plots that plot(model) draws, while independence is judged from the study design. Expand each panel below to see what the assumption means, how it is checked in R and what to do if it fails.

Linearity

What it means. The average outcome changes in a straight line as each continuous predictor increases. Blood pressure should rise by about the same amount between ages 30 and 40 as between ages 60 and 70.

How to check it. In the Residuals vs Fitted plot from plot(model), the red smoothed line should be close to flat at zero. A clear curve (a U shape or an arch) suggests that the relationship is not a straight line.

If it fails. A squared term for the predictor, such as I(age^2), can capture a curve, and its coefficient tests whether the curve is needed.

Independence

What it means. Each person's outcome is unrelated to every other person's outcome once the predictors are taken into account.

How to check it. Independence is judged from the study design and cannot be read from a plot. It is usually reasonable when each person is sampled once. It fails when the same person is measured several times, or when people are clustered (patients within clinics, students within schools).

If it fails. Models for dependent data handle repeated or clustered measurements.

Normality of the residuals

What it means. The residuals (each observed value minus the value predicted by the model) follow a roughly bell-shaped distribution. The assumption concerns the residuals, which are checked after the model is fitted, and a skewed outcome can still give normal residuals.

How to check it. In the Q-Q Residuals plot, the points should lie close to the dotted diagonal line. Small wiggles at the ends are common and are not a concern in a large sample.

If it fails. A strongly skewed outcome can sometimes be transformed (for example, by taking its log). If the outcome is a count or a category, a GLM from this lesson is the better choice.

Equal variance of the residuals

What it means. The residuals are spread about equally across the whole range of predicted values. The technical name for this property is homoscedasticity.

How to check it. In the Residuals vs Fitted and Scale-Location plots, the band of points should have roughly the same height from left to right. A funnel that widens to one side is the usual sign of a problem.

If it fails. Sandwich (heteroscedasticity-consistent) standard errors or a transformation of the outcome can correct the problem. When the spread grows with the mean because the outcome is a count, a Poisson or negative binomial model is the better choice.

No overly influential points

What it means. No single observation pulls the fitted line far from where the rest of the data would put it.

How to check it. In the Residuals vs Leverage plot, points that fall beyond the dashed Cook's distance lines have large influence. When no point is near them, R does not draw the lines inside the plotting area.

If it fails. The influential record is checked for a data-entry error. If it is a genuine value, the model is reported with and without it.

Figure 4.2 shows the four plots that plot(lin) draws for the blood pressure model, so that each of the checks described in the panels can be seen on real output.

Four diagnostic plots for the linear model of systolic blood pressure on age and smoking. Residuals versus fitted shows a flat cloud around zero; the Q-Q plot follows the diagonal; the scale-location plot shows an even band; no point lies beyond Cook's distance in the residuals versus leverage plot.
Figure 4.2. The four plots drawn by plot(lin) for the blood pressure model. The cloud of residuals is flat and even (linearity and equal variance), the points follow the Q-Q line (normality), and no point lies beyond Cook's distance (no overly influential points). In the first three panels the numbered points are the three largest residuals, and in Residuals vs Leverage they are the three largest Cook's distances; R labels them by row number.

For the blood pressure model, the plots in Figure 4.2 support each of the assumptions that a plot can check. The next step is to see what the same plots look like when the outcome is not continuous.

2.2 Why Some Outcomes Break These Assumptions

The same four plots look very different when a straight line is fitted to an outcome that is a count. Figure 4.3 shows the first two plots for a linear regression of urgent_visits (the number of urgent care visits in the past year) on age and smoking.

Two diagnostic plots for a linear model fitted to urgent care visits. The residuals versus fitted plot shows parallel diagonal stripes, one for each count value, with a long tail of large positive residuals. The Q-Q plot bends sharply away from the diagonal line at the upper end.
Figure 4.3. The two plots come from a linear model fitted to a count. Panel A shows a stripe of residuals for each possible count (0, 1, 2 and so on) and a long upper tail. Panel B shows residuals that are far from normal. Both plots signal that a straight-line model with normal errors is the wrong tool for this outcome.

Each outcome type breaks the assumptions in its own way, and seeing how helps to explain why each needs its own model. A binary outcome takes only the values 0 and 1. A straight line has no floor or ceiling, so as a predictor such as age increases, the line keeps rising and can eventually predict a "probability" below 0 or above 1, which is impossible. The residuals are also unusual: for any person the residual can take only two values, one if they had the event and one if they did not, so the residuals form two bands rather than a bell-shaped spread and can never be normal. A count cannot be negative and often has many zeros, so its distribution is lopsided rather than bell-shaped. Counts also become more variable as their average increases. A group that averages 0.2 visits a year has little room to vary, while a group that averages 5 visits a year can range from 0 to 15 or more, so the spread of the residuals grows with the predicted value, which breaks the equal-variance assumption. An ordinal outcome has an order but no known spacing between its categories. If self-rated health is coded 1 to 5, a linear slope assumes that moving from "poor" to "fair" is the same size of change as moving from "very good" to "excellent", and nothing in the data supports that, so a slope "per category" has no clear meaning. A nominal outcome has no order at all, so any numbers attached to its categories are arbitrary labels, and a slope fitted to those labels would change if the categories were simply numbered in a different order.

Linear regression is therefore suited to a continuous outcome, and each of the other four types of outcome calls for a model that matches the values the outcome can take. The next step introduces the family of models that provides one for each type.

2.3 The Three Parts of a Generalized Linear Model

A generalized linear model (GLM) extends linear regression so that it can handle these outcomes. The extension was set out by Nelder and Wedderburn (1972) and is now the standard framework for regression in epidemiology. The central idea is that linear regression can be taken apart into pieces, and that only some of the pieces need to change for a new kind of outcome. Every GLM has three parts. The distribution (also called the family) describes the kind of values the outcome can take and how they vary around their average. A continuous outcome is described by the normal distribution, a binary outcome by the binomial distribution and a count by the Poisson distribution. The linear predictor is the familiar sum β0 + β1X1 + β2X2 + …, which combines the predictors exactly as in linear regression; this is the part that stays the same in every GLM, and it is why the models in this lesson are all written and fitted in a similar way. The link function is a transformation of the average outcome that is set equal to the linear predictor. It is the bridge between the two other parts, connecting the straight-line sum of the predictors to an average outcome that may be a probability or a count.

Equation 4.2 shows how the link function connects the average outcome to the linear predictor.

The general form of a GLM
\[ \color{#C2410C}{g}\big(\color{#0B7B6B}{\mu}\big) = \color{#6D28D9}{\beta_0 + \beta_1 X_1 + \beta_2 X_2 + \dots} \]Eq 4.2
A link function g applied to the average outcome μ (a mean, a probability or an expected count) equals the linear predictor. For logistic regression, g is the logit (the log of the odds); for Poisson regression, g is the natural log.

The link function is the part of a GLM that is least familiar, so it is worth slowing down. By setting a transformation of the average outcome equal to the linear predictor, we mean that the model does not draw its straight line on the outcome itself. Instead, it first transforms the average outcome onto a new scale and draws the straight line on that scale. The linear predictor can take any value from minus infinity to plus infinity, but many outcomes cannot. The transformation stretches the restricted range of the outcome onto that unlimited scale, so that whatever value the linear predictor produces, it translates back into an average that makes sense. Different models use different link functions, that is, different kinds of transformation, because different outcomes have different limits.

The purpose of the link is therefore to keep the model's predictions within a sensible range. For example, a probability must lie between 0 and 1, so when a model predicts a probability, as logistic regression does for a binary outcome, it uses the logit link, which guarantees that every predicted probability falls between 0 and 1. An expected count, such as the average number of urgent care visits, must stay positive and can never be negative, so when a model predicts an expected count, as Poisson regression does, it uses the log link, which guarantees that every predicted count is above 0. A continuous outcome such as blood pressure needs no protection of this kind, so linear regression uses the identity link, which leaves the average unchanged.

In addition to keeping predictions in range, the link also decides how the coefficients are read. In linear regression the identity link leaves the outcome on its own scale, so a coefficient is read directly as a difference in the average outcome: the slope of 0.45 for age in 2.1 means that average blood pressure is 0.45 mmHg higher for each additional year of age. With a log or logit link, such as those used in Poisson and logistic regression, the coefficient (written β) is on a log scale, and a difference on a log scale is hard to picture. When the coefficient is exponentiated, that is, when e is raised to the power of the coefficient (eβ, calculated with exp(coef(model)) in R or with the ex key on a calculator), it becomes a ratio: an odds ratio, a relative risk ratio or a rate ratio, depending on the model. This changes its interpretation. Instead of saying how much the outcome goes up or down, the ratio says how many times larger or smaller the odds, risk or rate is in one group than in another. With these ratios, a value of 1 means no association, because the two groups are the same. A ratio above 1 means the outcome is more likely or more frequent, and a ratio below 1 means it is less likely or less frequent.

Table 4.2 lists each model used in this lesson with its type of outcome, its distribution and link, the reading of eβ, and the R function that fits it. The note beneath the table explains how the ordinal and multinomial models relate to the GLM family.

Table 4.2. The regression models in this lesson, with the distribution, link, reading of eβ and R function of each.

ModelOutcomeDistributionLinkeβ is read asR function
Linear regressionContinuousNormalIdentity (no transformation)Not exponentiated: β is a difference in meanslm()
Logistic regressionBinaryBinomialLogitOdds ratio (OR)glm(family = binomial)
Ordinal logistic regressionOrdinalMultinomial (ordered)Cumulative logitOdds ratio for a higher categoryMASS::polr()
Multinomial logistic regressionNominalMultinomialLogit versus a reference categoryRelative risk ratio (RRR)nnet::multinom()
Poisson regressionCountPoissonLogIncidence rate ratio (IRR)glm(family = poisson)
Negative binomial regressionOverdispersed countNegative binomialLogIncidence rate ratio (IRR)MASS::glm.nb()

Strictly, the ordinal and multinomial models are close relatives of the GLM family (they are often called multivariate GLMs), because they model several probabilities at once. They are fitted and read in the same way, and this course treats them as members of the family.

Every model in Table 4.2 therefore keeps the linear predictor and differs in its distribution and link, and the link decides what its exponentiated coefficient is called. The rest of this section applies the framework to the GLM for a binary outcome, logistic regression.

3.1 Fitting and Interpreting a Logistic Regression

Logistic regression is the GLM for a binary outcome, with a binomial distribution and a logit link. It models the log of the odds of the event, and its exponentiated coefficients are odds ratios. In R it is fitted with glm(hypertension ~ age + smoker, data = phaa, family = binomial), and the line exp(cbind(OR = coef(logit), confint(logit))) in Activity 4.1 prints the odds ratios with their 95% confidence intervals. Reading those results, checking that the model has enough data, and comparing crude with adjusted estimates are taken in turn below.

3.1.1 Reading Odds Ratios and Their Confidence Intervals

Four statistical ideas from earlier courses are needed to read the results of every model in this lesson. Read the callout below to refresh them, and try its retrieval question before you read on.

Recall: Statistical Foundations

Four ideas are needed to read the results in this lesson.

Confidence intervals. A 95% confidence interval is a range of values calculated from the data. The method that produces it captures the true value in 95% of repeated samples, and the values inside it are those most compatible with the data. For a ratio, an interval that includes 1 shows that the data cannot rule out no association; for a difference, the corresponding value is 0.

p-values. A p-value is the probability of an estimate at least as far from “no association” as the one observed, if there were truly no association. A small p-value shows that the data are hard to reconcile with no association. It is not the probability that the null hypothesis is true, and it does not measure the size or importance of the association.

Probability and odds. The odds of an event are p ÷ (1 − p), the probability that it happens divided by the probability that it does not, and a probability is recovered as odds ÷ (1 + odds). When an event is rare, the odds and the probability are close.

Exponentiated coefficients. A log or logit link puts coefficients on a log scale. On that scale, effects add: each predictor adds its coefficient to the log-odds or log-rate. Exponentiating a coefficient (eβ) moves it back to the ordinary scale, where it becomes a ratio, such as an odds ratio, and effects multiply instead of add. An odds ratio of 1.5, for example, means that the odds are multiplied by 1.5. The two ends of the confidence interval are exponentiated in the same way, which is why an interval for a ratio is often not centred on its estimate.

Optional fuller reading: HSCI 341 Lesson 6, Section 4, and the confidence-interval paragraph of the mediation example in HSCI 410 Lesson 1, Section 1.

Retrieval question. In the paragraph that follows this callout, smokers have an odds ratio for hypertension of 2.65 (95% CI 1.04 to 6.30). What does the interval show?

AnswerThe data are most compatible with odds of hypertension in smokers between about 1.04 and 6.30 times the odds in non-smokers of the same age. The interval lies entirely above 1, so the data are hard to reconcile with no association, but its width shows that the estimate is imprecise, because only 23 people had hypertension.

In the PHAA data, R reports that the odds of hypertension are 2.65 times as high for smokers as for non-smokers of the same age (95% CI 1.04 to 6.30), and 1.05 times as high (about 5% higher) for each additional year of age (95% CI 1.01 to 1.08). Each odds ratio tells us by how much the odds of the event are multiplied, so a correct interpretation speaks of odds rather than risk. It also names the comparison group (non-smokers, or people one year younger) and the variables held constant (age for the smoking estimate, smoking for the age estimate), because an odds ratio has no meaning without knowing who is being compared with whom. The interval for smoking lies entirely above 1, so the data are hard to reconcile with no association, but it is wide. Only 23 of the 795 people have hypertension, and with so few events the model has little information about each predictor: the point estimate of 2.65 suggests a strong association, yet the data are consistent with anything from a very small increase to a six-fold increase in the odds. Reporting the interval alongside the estimate makes this uncertainty visible to readers.

The small number of events also limits how many predictors the model can support, which is one of the assumptions of logistic regression taken up next.

3.1.2 Assumptions and the Number of Events

The assumptions of logistic regression differ from those of linear regression, because a binary outcome has no normal residuals and no constant spread to check. Table 4.3 lists the assumptions of logistic regression with the way each is checked.

Table 4.3. The assumptions of logistic regression and how each is checked.

AssumptionWhat it meansHow to check it
Binary outcomeThe outcome has exactly two categories.table(outcome) shows two groups.
IndependenceEach person contributes one independent observation.Judged from the study design.
Linearity in the log-oddsEach continuous predictor has a straight-line relationship with the log-odds of the event.Add a squared term (for example I(age^2)) and check whether it improves the model.
Enough eventsA common rule of thumb asks for about 10 events per predictor.table(outcome) gives the number of events. With 23 events, about two predictors are supported.
No strong multicollinearityPredictors are not so strongly related that their effects cannot be separated.Correlations among predictors, or variance inflation factors.

The rule of about 10 events per predictor in Table 4.3 matters in the PHAA data, because few participants have hypertension. The rule counts the events, the people with the outcome, not everyone in the sample: table(phaa$hypertension) in Activity 4.1 shows 23 events, enough for about two predictors. The model with age and smoking is therefore close to the limit, and adding more predictors would make the estimates unstable and their intervals wider still.

A model that has been fitted and checked is then reported, usually in a table that also shows how much adjustment changed each estimate.

3.1.3 Crude and Adjusted Odds Ratios

Published papers usually report a regression in a table that sets the crude (unadjusted) estimate for each predictor beside the adjusted estimate from the multivariable model, so that readers can see how much adjustment changed each association. The crude odds ratio for a predictor comes from a logistic model with that predictor alone, such as glm(hypertension ~ smoker, data = phaa, family = binomial), and the adjusted odds ratios come from the model with age and smoking together. Table 4.4 shows this layout for the PHAA example.

Table 4.4. Crude and adjusted odds ratios for hypertension in the PHAA example.

PredictorCrude OR (95% CI)Adjusted OR (95% CI)
Age (per year)1.05 (1.01 to 1.08)1.05 (1.01 to 1.08)
Smoker (yes vs. no)2.76 (1.09 to 6.50)2.65 (1.04 to 6.30)

Odds ratios for hypertension among the 795 PHAA participants with complete data (23 events). The adjusted odds ratios come from one logistic regression that includes age and smoking. The 95% confidence intervals come from confint().

A clear results table states the outcome, the number of people and events, the reference category of each categorical predictor, the unit of each continuous predictor and the variables in the adjusted model. In this example adjustment changes the smoking odds ratio only slightly, from 2.76 to 2.65, because smokers and non-smokers in these data have almost the same average age (45.5 and 45.1 years).

The crude and adjusted odds ratios can differ much more when another predictor is related both to the predictor of interest and to the outcome. Suppose smokers in another study were on average ten years older than non-smokers, and older people had more hypertension. Part of the crude odds ratio for smoking would then reflect age rather than smoking, and adjusting for age would move the odds ratio toward 1. A large change between the crude and adjusted estimates is therefore a sign of confounding by the variables added to the model, and a small change, as here, shows that those variables barely distort the association.

Activity 4.1 puts this review into practice. It shows why a straight line does not suit a yes-or-no outcome, then fits the logistic model for hypertension as a generalized linear model and produces the odds ratios and the crude and adjusted comparison in Table 4.4. Run the script alongside the reading and answer the questions from your own output.

R Activity 4.1: logistic regression as a generalized linear model

Text version of the activity: the code of the run-along script, its console output and notes on reading it.

phaa <- read.csv("https://heal-learn.ca/r-activities/data/phaa_outcomes.csv")   # course data, read from the website
phaa <- na.omit(phaa)                   # keep the 795 people with no missing values
phaa$smoker <- factor(phaa$smoker, levels = c("No", "Yes"))   # "No" = reference
phaa$hypertension <- factor(phaa$hypertension, levels = c("No", "Yes"))   # "Yes" = event
table(phaa$hypertension)     # how many people had the event?
Console output
No Yes 772 23

The table is the first check for a logistic regression: 23 of the 795 people have hypertension, and these events limit how many predictors the model can support.

lin01 <- lm(as.numeric(hypertension == "Yes") ~ age + smoker, data = phaa)
range(fitted(lin01))         # the "probabilities" a straight line predicts
plot(lin01, which = 1)       # Residuals vs Fitted for a 0/1 outcome
Console output
[1] -0.01213627 0.11332896
Residuals versus fitted values for a linear model of hypertension coded 0 and 1: the residuals fall on two parallel bands.

A straight line fitted to the 0/1 outcome predicts values below 0 for some people (64 of them), and its residuals fall on two parallel bands, one for each outcome (the Residuals vs Fitted plot above).

logit <- glm(hypertension ~ age + smoker, data = phaa, family = binomial)
summary(logit)
exp(cbind(OR = coef(logit), confint(logit)))   # odds ratios with 95% CIs
Console output
Call: glm(formula = hypertension ~ age + smoker, family = binomial, data = phaa) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -5.92153 0.85886 -6.895 5.4e-12 *** age 0.04413 0.01556 2.837 0.00456 ** smokerYes 0.97388 0.45401 2.145 0.03195 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 208.30 on 794 degrees of freedom Residual deviance: 195.47 on 792 degrees of freedom AIC: 201.47 Number of Fisher Scoring iterations: 7 Waiting for profiling to be done... OR 2.5 % 97.5 % (Intercept) 0.002681092 0.0004486709 0.01319051 age 1.045122912 1.0141021941 1.07818723 smokerYes 2.648198101 1.0360202694 6.29767121

Reading the output. The Estimate column is on the log-odds scale, so the last line exponentiates the coefficients to give odds ratios. family = binomial gives the outcome a binomial distribution with the logit link, and age and smoking form the linear predictor. The odds ratio for age is 1.045 (95% CI 1.014 to 1.078), and the odds ratio for smoking is 2.65 (95% CI 1.04 to 6.30). The odds ratio for the intercept is the odds of hypertension for a non-smoker aged 0 and is not interpreted.

crude <- glm(hypertension ~ smoker, data = phaa, family = binomial)
exp(cbind(OR = coef(crude), confint(crude)))
Console output
Waiting for profiling to be done... OR 2.5 % 97.5 % (Intercept) 0.02318393 0.01327544 0.03722576 smokerYes 2.76053333 1.09110925 6.49696040

The crude odds ratio for smoking, from a model with smoking alone, is 2.76 (95% CI 1.09 to 6.50).

Files for this activity Data Code Answer key

R Reflect on what you just ran

Answer each question from your own output, as on the final exam: find the number, say what it means, judge the check.

1. Why is logistic regression, rather than linear regression, suitable for hypertension? Use range(fitted(lin01)) and the Residuals vs Fitted plot to give two reasons why a straight line does not suit it.

Model answerA straight line predicts impossible probabilities: the fitted values run from −0.012 to 0.113, and 64 people get a predicted probability below 0. The residuals fall on two parallel bands, one for the people with hypertension and one for those without, so they cannot be normally distributed. Their spread also depends on the predicted probability, so the equal-variance assumption fails as well. Logistic regression avoids these problems: it models the log odds of hypertension with a binomial distribution and a logit link, so its predicted probabilities stay between 0 and 1, and its exponentiated coefficients are odds ratios.

2. Interpret the odds ratio for smokerYes, with its confidence interval. Without adjustment (crude) the odds ratio is 2.76; after adjustment for age it is 2.65. Explain why the two odds ratios are so similar.

Model answerThe adjusted odds ratio is 2.65 (95% CI 1.04 to 6.30). Smokers have about 2.6 times the odds of hypertension of non-smokers of the same age. The interval excludes 1, so the association is statistically significant, but it is wide: the increase could be anything from very small to about six-fold, because there are only 23 events. Adjusting for age moves the odds ratio only from 2.76 to 2.65, so age barely confounds the association: a confounder must be related to both smoking and hypertension, and smokers and non-smokers here have almost the same average age (45.5 and 45.1 years); a large change would point to confounding by the added variable.

3. Run your own code: at the end of the script, type exp(10 * coef(logit)["age"]), exp(10 * confint(logit)["age", ]) and sum(phaa$hypertension == "Yes") / 5 and run them. Interpret the odds ratio for a ten-year difference in age, with its confidence interval. The model has 23 events, and the last line gives the number of events per predictor if BMI, gender and income were added as three more predictors (five in all). Is that enough?

Model answerThe odds ratio for ten years of age is 1.55 (95% CI 1.15 to 2.12). A person ten years older than another with the same smoking status has about 1.55 times the odds of hypertension, or about 55% higher odds. The rule of thumb asks for about 10 events per predictor, and the model's 23 events for two predictors are close to it. No: with BMI, gender and income added, the last line shows only 4.6 events per predictor, well under the rule of thumb, so the estimates would be unstable and their intervals very wide.
Saved.

Your output from Activity 4.1 reproduces the odds ratios in Table 4.4 and the count of 23 events that limits the model. The key takeaways below draw the section together before its knowledge check.

Key Takeaways

  • 1.1 Variables come in different types depending on what their values represent. This lesson uses five main types, continuous, discrete (count), binary, ordinal and nominal, which fall into a numeric family and a categorical family (Table 4.1). You are not always able to tell a variable's type simply from how it is stored. Both continuous and ordinal variables may use numbers (self-rated health might be stored as 1 to 5, yet it is still ordinal, because the distance between "good" and "very good" is unknown), and binary and nominal variables are sometimes stored as numeric codes too. You must consult the data dictionary and the question text to understand what the values stored in a dataset represent. The class() function can tell you what type R has assigned to a variable, but R's label is not always the right type for your analysis.
  • 1.2 Once you know the type of the outcome, the model follows from it, and the predictors play no part in the choice. A continuous outcome calls for linear regression, a binary outcome for logistic regression, ordered categories for ordinal logistic regression, unordered categories for multinomial logistic regression, and a count for Poisson regression, or negative binomial regression when the counts are overdispersed. The model also tells you what its results are called: a linear regression coefficient is a difference in means and is not exponentiated, while the exponentiated coefficients of the other models are odds ratios (logistic and ordinal), relative risk ratios (multinomial) or incidence rate ratios (Poisson and negative binomial). When a question gives you several outcomes, work through Figure 4.1 for each one in turn: decide whether it is numeric or categorical, narrow it to one model, and write the model and the name of its ratio together. Table 4.2 sets out the whole pairing in one place.
  • 2.1 Linear regression rests on four assumptions, often remembered as LINE: linearity, independence, normality of the residuals and equal variance of the residuals. Three of them can be checked from the four plots that plot(model) draws. A flat red line in Residuals vs Fitted supports linearity, points close to the diagonal in Q-Q Residuals support normality, and an even band with no funnel in Scale-Location supports equal variance, while Residuals vs Leverage flags influential points beyond Cook's distance. Independence cannot be read from any plot: you judge it from the study design, so look in the question for the same person measured several times or for people clustered in clinics, schools or households. Remember too that normality concerns the residuals, not the raw outcome, so a skewed outcome does not by itself break the assumption.
  • 2.2 Linear regression suits a continuous outcome, and each of the other outcome types breaks its assumptions in its own way. A straight line fitted to a binary outcome can predict impossible probabilities below 0 or above 1, and its residuals can never be normal. A count cannot be negative, often has many zeros and becomes more variable as its average rises, so its residuals are skewed and their spread grows with the fitted values. An ordinal outcome has an order but no known spacing, so a slope "per category" has no clear meaning, and the numbers attached to a nominal outcome are only labels. When you are shown residual plots for a count, as in Figure 4.3, look for stripes of residuals, a Q-Q plot that bends away from the line and a Scale-Location line that climbs, and name the assumptions they break before you name the better model.
  • 2.3 A generalized linear model (GLM) keeps the familiar linear predictor, β0 + β1X1 + β2X2 + …, and changes two things: the distribution (or family), which describes the kind of values the outcome can take, and the link function, which transforms the average outcome so that it can be set equal to the linear predictor. The link keeps predictions in a sensible range, because the logit keeps probabilities between 0 and 1 and the log keeps expected counts positive. It also decides how you read a coefficient: with a log or logit link, β is on a log scale, so you exponentiate it with exp(coef(model)) to get a ratio, on which 1 means no association. If you are asked to describe a GLM, name all three parts for that model, for example a binomial distribution, a logit link and age plus smoking as the linear predictor for the logistic model of hypertension.
  • 3.1 Logistic regression models the log odds of a binary outcome, so after you fit it with glm(…, family = binomial), the line exp(cbind(OR = coef(logit), confint(logit))) turns its coefficients into odds ratios, each of which multiplies the odds of the event. Read every odds ratio with its 95% confidence interval: smokers in the PHAA data have 2.65 times the odds of hypertension of non-smokers of the same age (95% CI 1.04 to 6.30), and because the interval lies entirely above 1 the data are hard to reconcile with no association, although its width shows that the estimate is imprecise. Then compare the crude odds ratio, from a model with that predictor alone, with the adjusted one: a large change signals confounding by the variables added, while a small change, such as 2.76 to 2.65 here, shows that they barely distort the association. Before you trust the model, count the events with table(outcome) and allow about 10 per predictor, so the 23 cases of hypertension support only about two predictors. In your interpretation, speak of odds rather than risk, and name the comparison group and the variables held constant.
Knowledge check: this section

1. A health unit's survey file stores the four outcomes below as numbers. Which analysis plan matches each outcome to the right model and to the name of its exponentiated coefficient?

VariableStored asWhat the values mean
er_visits0, 1, 2, …Emergency department visits in the past year
food_sec1 to 41 = food secure, 2 = marginally, 3 = moderately, 4 = severely food insecure
transport1 to 4Main way of getting to work: 1 = car, 2 = public transit, 3 = walking, 4 = cycling
flu_vax0 or 1Received an influenza vaccine this season (1 = yes)
er_visits counts events, whole numbers of 0 or more, so it is a count rather than a continuous outcome. Counts are modelled with Poisson regression, which reports incidence rate ratios, not differences in means.
Each outcome is matched by what its values mean: a count for Poisson regression, ordered categories for ordinal logistic, unordered categories for multinomial logistic and two groups for logistic regression.
The codes 1 to 4 are labels, not amounts. Treating them as numbers assumes equal steps for food_sec and invents an order for transport, which has none.
This follows the codes rather than the categories. food_sec has a natural order, so it is ordinal, while transport has no order (cycling is not more than walking), so it is nominal.
The correct plan is Poisson regression for er_visits, ordinal logistic regression for food_sec, multinomial logistic regression for transport and logistic regression for flu_vax. The information needed is what each set of values means, not how it is stored: er_visits counts events (whole numbers of 0 or more), so it is a count and its model reports incidence rate ratios; food_sec has four categories in a natural order with unknown spacing, so it is ordinal; transport has four categories with no order (cycling is not "more" than walking), so it is nominal; and flu_vax has two groups, so it is binary. The tempting plan that uses linear regression for food_sec and transport treats the codes 1 to 4 as amounts when they are only labels, and the plan that swaps the ordinal and multinomial models follows the order of the codes rather than the meaning of the categories. (Section 1, 1.1 Types of Variables, Table 4.1 and the five flip cards, and 1.2 Matching the Outcome to a Model, Figure 4.1; Objectives 1.1 and 1.2)

2. A study measures body mass index (BMI) in 640 adults recruited as couples, two adults from each of 320 households, and fits lm(bmi ~ age + income + smoker). In the plots from plot(model), the red line in Residuals vs Fitted is flat at zero, the points in Q-Q Residuals lie close to the diagonal, the band of points in Scale-Location widens from left to right while its red line climbs, and no point in Residuals vs Leverage lies beyond Cook's distance. Which conclusion is correct?

The plots cannot show independence, which is judged from the study design. Here adults from the same household are likely to resemble each other, and the widening Scale-Location band also signals unequal variance.
A climbing Scale-Location line signals unequal variance, not a linearity problem; linearity is supported by the flat Residuals vs Fitted line. Being measured once does not make two members of a couple independent.
A widening Scale-Location band is the usual sign of unequal variance, and independence is judged from the design: two adults sharing a household are likely to have related outcomes, which no residual plot reveals.
Cook's distance in Residuals vs Leverage measures influence, not independence. Independence comes from the study design, and recruiting couples makes it doubtful.
The correct conclusion is that equal variance and independence are both in doubt. The information needed is which plot checks which assumption, and how the adults were recruited. A Scale-Location band that widens like a funnel is the usual sign of unequal variance, while the flat Residuals vs Fitted line supports linearity, the Q-Q plot supports normality and the leverage plot shows no overly influential point. Independence cannot be read from any of the four plots: it is judged from the study design, and couples who share a household (and often their meals, income and habits) are likely to have related outcomes. The tempting option that accepts independence because no point is influential mixes up two different checks, since Cook's distance measures influence, not independence. (Section 1, 2.1 Linear Regression and Its Assumptions, the accordion panels and Figure 4.2; Objective 2.1)

3. In a study of 600 children with asthma, 62% had no asthma attacks needing urgent care in the past year, a few had as many as 9, and the mean was 0.7. A colleague plans to fit lm(attacks ~ age + smoke_home). Which reply is correct?

Counts break the normality and equal-variance assumptions and can produce negative predictions. A Poisson GLM keeps the linear predictor, uses a Poisson distribution and a log link on the expected count, and reports incidence rate ratios.
A large sample does not make the linear model suitable for a count: it can still predict negative numbers of attacks, and the spread still grows with the mean. The lesson recommends a GLM for counts.
For a count, the lesson recommends a GLM rather than a transformation. A Poisson model applies the log through its link to the expected count, not to each child's observed count.
This mixes up the three parts of a GLM. Poisson regression uses a Poisson distribution, not a normal one, its log link acts on the expected count, and its exponentiated coefficient is an incidence rate ratio, not an odds ratio.
The correct reply names the assumptions that a count breaks and the GLM that fixes them. The information needed is what the counts look like: whole numbers of 0 or more, mostly zeros (62%), with a long right tail. A straight line fitted to such counts gives skewed residuals (normality fails), a spread that grows with the predicted value (equal variance fails) and possibly negative predictions. A GLM keeps the linear predictor β0 + β1X1 + … and changes the other two parts: for Poisson regression the distribution is Poisson and the link is the log of the expected count, so eβ is an incidence rate ratio. The log-transform reply fails because, for a count, the lesson recommends a GLM rather than a transformation (the accordion on normality of the residuals); the last reply mixes up the three parts, since Poisson regression does not assume a normal distribution, its link acts on the expected count rather than on each observed count, and its ratio is not an odds ratio. (Section 1, 2.2 Why Some Outcomes Break These Assumptions and 2.3 The Three Parts of a Generalized Linear Model, Eq 4.2 and Table 4.2; Objectives 2.2 and 2.3)

4. A survey of 900 adults recorded whether each had gone two years without a dental visit (no_dental = 1 for 210 adults). A logistic regression included insured (1 = has dental insurance), income10 (household income per $10,000), age10 (age per 10 years) and female (1 = woman), and gave the odds ratios below. Which interpretation is correct?

> exp(cbind(OR = coef(logit), confint(logit)))[-1, ] OR 2.5 % 97.5 % insured 0.52 0.37 0.73 income10 0.86 0.79 0.94 age10 1.10 0.98 1.23 female 0.88 0.64 1.21
An odds ratio multiplies the odds; it is neither a risk ratio nor the proportion of insured adults with the outcome. The share of insured adults without a visit is a different quantity.
The odds ratio for women is below 1, but its interval includes 1, so the lower odds are not statistically significant. Significance is judged from the interval, not from which side of 1 the estimate falls.
The outcome is binary, so the model reports odds ratios, not differences in years. The odds ratio for income multiplies the odds of going without a visit per $10,000.
An odds ratio below 1 means lower odds, adjusted for the other predictors. Insurance's interval lies entirely below 1, while the interval for women includes 1, so only the insurance association is clear.
The correct interpretation is that insured adults have 0.52 times the odds of going without a dental visit, with an interval that excludes 1, while the interval for women includes 1. The information needed is each odds ratio with its 95% CI, and the fact that the model adjusts for the other predictors. An odds ratio multiplies the odds: 0.52 means odds about half as high (48% lower) for insured adults than for uninsured adults with the same income, age and gender, and because 0.37 to 0.73 lies entirely below 1 the data are hard to reconcile with no association. The tempting option about women ignores the interval: 0.64 to 1.21 includes 1, so 12% lower odds is not statistically significant. An odds ratio is also not the proportion of people with the outcome, and it is not a difference in years. (Section 1, 3.1.1 Reading Odds Ratios and Their Confidence Intervals and the callout Recall: Statistical Foundations; Objective 3.1)

5. In the same survey, insured fitted on its own gave a crude odds ratio of 0.38 (95% CI 0.28 to 0.53), against the adjusted 0.52 in Question 4. Insured adults had higher incomes, and higher income was linked to lower odds of going without a dental visit. R gives the events and the events per predictor for the four-predictor model below. Which statement is correct?

> table(dental$no_dental) 0 1 690 210 > sum(dental$no_dental) / 4 # events per predictor [1] 52.5
Adjusting for a confounder removes bias rather than adding it, so the crude estimate is the distorted one. The events rule also counts the adults with the outcome, not everyone surveyed.
Income is related to both insurance and the outcome, so part of the crude association reflected income, and adjusting moved the odds ratio toward 1. The events per predictor are well above the guide of about 10.
A move toward 1 after adjustment signals confounding, not that insurance should be dropped. Its adjusted odds ratio and interval remain clearly below 1.
The confounding reading holds, but the rule of thumb asks for about 10 events per predictor, not 100. This model has far more than enough.
The correct statement explains the change as confounding by income and finds that the model has enough events. The information needed is how income relates to both insurance and the outcome, and the events per predictor that R prints. Because insured adults had higher incomes and higher income was itself linked to lower odds of going without a visit, part of the crude odds ratio of 0.38 reflected income; adjusting for income moved it to 0.52, toward 1, and a large change of this kind is the sign of confounding by the variable added. For the events check, the events are the 210 adults who went without a visit (the 1s in table()), and R gives 52.5 events for each of the four predictors, far more than about 10, so the estimates should be stable. The tempting first option counts all 900 adults rather than the 210 events, and dropping insurance would be wrong, because its adjusted odds ratio (0.52, 95% CI 0.37 to 0.73) is still clearly below 1. (Section 1, 3.1.2 Assumptions and the Number of Events, Table 4.3, and 3.1.3 Crude and Adjusted Odds Ratios, Table 4.4; Objective 3.1)

6. A cardiac rehabilitation program surveyed 900 adults and recorded angina, the number of episodes of chest pain each adult had in the same four weeks (0 to 15, with most adults at 0 or 1). A colleague fitted lm(angina ~ age + smoker). In the plots from plot(model), the points in Q-Q Residuals bend away from the line at the upper end, and the band of points in Scale-Location widens to the right. Which reply is correct?

Independence is judged from the study design, not from these plots, and a squared term addresses linearity, which the plots described do not question. The problems shown are non-normal residuals and unequal variance.
Estimates can be trusted only if the model's assumptions are reasonable, however small the p-values. The plots show assumptions that a count outcome is expected to break.
The Q-Q plot checks normality and Scale-Location checks equal variance; both fail as expected for a count. Poisson regression, with a Poisson distribution and a log link, suits the outcome and reports incidence rate ratios.
The normality reading holds, but logistic regression is the model for a binary outcome. The number of angina episodes is a count, which calls for Poisson regression.
The correct reply names the assumption that each plot checks and the model that suits a count. The information needed is which plot checks which assumption and what the outcome looks like. Q-Q Residuals checks the normality of the residuals and Scale-Location checks equal variance, and a count of episodes, mostly 0 or 1 with a long right tail, gives skewed residuals whose spread grows with the predicted value, the pattern that Figure 4.3 shows for urgent_visits. A GLM keeps the linear predictor and changes the other two parts: Poisson regression uses a Poisson distribution and a log link, so the expected count stays positive and eβ is an incidence rate ratio. Independence is judged from the study design rather than from these plots, a squared term addresses linearity, which the plots described do not question, and the estimates of a model can be trusted only if its assumptions are reasonable, however small the p-values. Logistic regression is the model for a binary outcome, not a count. (Section 1, 2.1 Linear Regression and Its Assumptions and its accordion panels, 2.2 Why Some Outcomes Break These Assumptions and Figure 4.3, and 2.3 The Three Parts of a Generalized Linear Model, Table 4.2; Objectives 2.1, 2.2 and 2.3)
● Complete the knowledge check to continue.
Section 2 of 4

Ordinal Logistic Regression

⏱ Estimated time: 35 minutes
Lesson 4 · Section 2

Ordinal Logistic Regression

A model for outcomes whose categories have a natural order, such as self-rated health from poor to excellent.

Ordinal outcomes

Ordered categories with unknown spacing

Self-rated health runs from poor to excellent.
Pain is rated none, mild, moderate or severe.
Agreement runs from strongly disagree to strongly agree.
Cancer is staged from I to IV.

The order of the categories is known. The size of the step from one category to the next is unknown and may differ from step to step.

Two shortcuts

Why not linear or binary logistic regression?

Code as 1 to 5 and use lm()

This assumes every step is the same size and that the residuals are normal. Neither assumption fits five ordered categories.

Collapse to two groups and use glm()

This throws away information and depends on where the cut-off is placed.

Ordinal logistic regression

This model uses all of the categories and their order, and it makes no assumption about the size of each step.

The idea

Four splits, one odds ratio per predictor

Split 1PoorFairGoodVery goodExcellent
Split 2PoorFairGoodVery goodExcellent
Split 3PoorFairGoodVery goodExcellent
Split 4PoorFairGoodVery goodExcellent
below the splitat or above the split

Each split compares at or above with below. The model gives each split its own intercept and gives each predictor one odds ratio for all four splits.

Proportional odds

The model in symbols

Ordinal (proportional-odds) logistic regression
\[ \ln\frac{\color{#0B7B6B}{P(Y \ge j)}}{\color{#C2410C}{P(Y < j)}} = \color{#6D28D9}{\beta_{0j}} + \color{#1D4ED8}{\beta_1}\,\text{age} + \color{#1D4ED8}{\beta_2}\,\text{smoker} \]
P(Y ≥ j) at or above category j P(Y < j) below category j β0j one intercept per split β1, β2 one slope per predictor, shared by all splits

R fits this model with polr() from the MASS package, and exp(coef(model)) gives an odds ratio for being in a higher category.

The PHAA example

Self-rated health by smoking

Two horizontal stacked bars showing the percentage of non-smokers and smokers in each self-rated health category. Smokers have more people in Poor and Fair and fewer in Very good and Excellent.
The bars show the percent of non-smokers (n = 662) and smokers (n = 133) in each self-rated health category.
Reading the output

Odds ratios from polr()

0.50
odds ratio for smokers (95% CI 0.36 to 0.70)
0.71
odds ratio for 10 years of age (0.966 per year)

Smokers have about half the odds of reporting a higher health category than non-smokers of the same age, at every split of the scale.

Assumptions and checks

What to check in an ordinal model

AssumptionHow to check it in R
The outcome has a genuine orderReasoning about the categories
Observations are independentStudy design
Enough people in each categorytable(outcome)
No strong multicollinearityCorrelations among the predictors
Proportional oddsbrant(model) from the brant package
The Brant test

Does one odds ratio fit every split?

Test forχ2dfp-valueAssumption holds?
Omnibus (all predictors)6.7160.35Yes
Age4.3030.23Yes
Smoking2.1930.53Yes

If a p-value were below 0.05, the options would be to combine sparse categories, to fit a multinomial model (Section 3), or to fit a partial proportional-odds model.

Carry forward

What to take into the next section

  • Ordinal logistic regression uses the order of the categories by fitting all of the at-or-above splits at once.
  • Each predictor has one odds ratio, read as the odds of being in a higher category.
  • The shared odds ratio is the proportional-odds assumption, and brant() checks it.

Overview

This section presents ordinal logistic regression, the model for an outcome with three or more ordered categories. The running example is self-rated health, a widely used single question in health surveys that asks people to rate their own health as poor, fair, good, very good or excellent. Self-rated health predicts later death even after other measures of health are taken into account (Idler & Benyamini, 1997), which makes it a common outcome in public health research. In the PHAA data, self-rated health is a simulated variable added for this lesson. The section explains why the common shortcuts for such an outcome lose information, shows how the model compares the categories through a series of splits, fits it with age and smoking as predictors, describes its predicted probabilities for two people and checks the assumption that sets it apart.

Learning Objectives

  • 4.1 Recognize an ordinal outcome and explain why linear regression and binary logistic regression are poor choices for it.
  • 4.2 Describe how the ordinal model compares "at or above" with "below" at each split of the outcome.
  • 4.3 Fit an ordinal logistic regression in R with polr(), interpret its odds ratios as applying at every split, and judge their statistical significance from their confidence intervals.
  • 4.4 Describe the predicted probabilities from the model for two people in plain words.
  • 4.5 Check the proportional-odds assumption with the Brant test and name what to do if it fails.

4.1 What Makes an Outcome Ordinal?

An outcome is ordinal when its categories can be ranked but the distances between them are unknown. Self-rated health, pain severity, agreement scales, disease stage and education level are all ordinal. The defining feature is that the order carries information: a move from "good" to "very good" is a move in a known direction. What the order does not say is how large each move is. The step from "poor" to "fair" might reflect a much larger change in health than the step from "very good" to "excellent", and the data offer no way to measure the difference.

Two shortcuts are common in practice, and both lose something. Coding the categories as 1 to 5 and fitting a linear regression treats every step as equal and assumes normal residuals, which a five-category outcome cannot have. Collapsing the categories into two groups and fitting a logistic regression discards the detail within each group and makes the result depend on where the cut-off is placed. Ordinal logistic regression avoids both problems.

Click each of the three cards below to compare the two shortcuts with ordinal logistic regression, and to see what each approach assumes and what it loses.

Treating Categories as NumbersClick to explore
Collapsing to Two GroupsClick to explore
Ordinal Logistic RegressionClick to explore

Ordinal logistic regression keeps every category and uses their order. The next step shows how it does this by fitting a series of splits of the outcome.

4.2 How the Model Works: A Series of Splits

The ordinal model works by turning one ordered outcome into several yes-or-no questions. Imagine drawing a line between two neighbouring categories of self-rated health and asking, for each person, whether their answer falls at or above the line or below it. With five ordered categories there are four places to draw the line, and in general an outcome with K ordered categories has K − 1 such splits. Each split is a yes-or-no comparison, so each one could be handled on its own by a binary logistic regression of the kind reviewed in 3.1. Rather than fitting four separate models and reporting four sets of results, the ordinal model fits the four comparisons together in a single model.

Figure 4.4 shows the four splits for self-rated health.

Split 1PoorFairGoodVery goodExcellent
Split 2PoorFairGoodVery goodExcellent
Split 3PoorFairGoodVery goodExcellent
Split 4PoorFairGoodVery goodExcellent
below the splitat or above the split

Figure 4.4. The four splits of the five categories of self-rated health, each comparing the categories at or above the split with those below it.

Fitting the splits together requires the model to decide what is allowed to differ between them and what is shared. The intercepts differ: the model gives each split its own intercept, because the proportion of people at or above the line changes depending on where the line is drawn. Almost everyone is "fair or better", so the odds at split 1 are high, while only a small share is "excellent", so the odds at split 4 are low. The predictors, however, are shared. Each predictor receives a single coefficient that applies to every split, which means the model assumes that smoking, for example, changes the odds of being above the line by the same amount wherever the line is drawn. Because the odds for smokers and non-smokers stay in the same proportion at every split, the model is called the proportional-odds model. This is a real assumption about the data rather than a mathematical convenience, and it is the assumption that the Brant test checks in 4.5 (McCullagh, 1980).

Equation 4.3 writes the model for self-rated health with age and smoking as predictors.

Ordinal (proportional-odds) logistic regression
\[ \ln\frac{\color{#0B7B6B}{P(Y \ge j)}}{\color{#C2410C}{P(Y < j)}} = \color{#6D28D9}{\beta_{0j}} + \color{#1D4ED8}{\beta_1}\,\text{age} + \color{#1D4ED8}{\beta_2}\,\text{smoker} \]Eq 4.3
For each split j, the log of the odds of being at or above category j, compared with being below it, equals a split-specific intercept plus slopes for age and smoking that are the same at every split.

Worked Example 4.2 shows what the single coefficient replaces. It sets the crude odds ratio for smoking at each of the four splits in Figure 4.4, as R reports it, beside the one odds ratio that the model estimates; watch whether the four values agree.

Worked Example 4.2: The Four Splits Side by Side

Fitting a separate binary logistic regression of each split on smoking alone gives the crude odds ratio at that split. The code below does this for the four splits, the same approach that Activity 4.2 uses with age added, and R prints one odds ratio for each split.

> crude <- sapply(c("Fair", "Good", "Very good", "Excellent"), function(k) + coef(glm(self_rated_health >= k ~ smoker, data = phaa, family = binomial))[["smokerYes"]]) > round(exp(crude), 2) Fair Good Very good Excellent 0.53 0.49 0.58 0.39

Each value compares the odds of being at or above a split for smokers with the same odds for non-smokers. The value of 0.49 printed under Good, for example, is the odds ratio for split 2: smokers have about half the odds of non-smokers of rating their health as good or better rather than poor or fair. A value below 1 at every split means that smokers are less likely than non-smokers to be at or above each split.

The four crude odds ratios are similar, and they all point in the same direction. The ordinal model replaces them with one number, 0.50, which also adjusts for age. The Brant test asks whether the four split-specific values differ by more than chance would produce.

Worked Example 4.2 shows that one odds ratio can summarise all four splits when the split-specific values agree. The next step reads that single odds ratio, and the rest of the output, from the model fitted to the PHAA data.

4.3 Interpreting the Odds Ratios

Before any odds ratio from polr() is read, its direction has to be settled, because textbooks and software do not all write the model the same way. The caution below sets out the convention that R uses.

How R Writes the Ordinal Model

Some textbooks and software write the ordinal model the other way round, as the odds of being at or below a category, which flips the sign of every coefficient. R's polr() is set up so that a positive coefficient means that higher categories are more likely and a negative coefficient means that lower categories are more likely. With self-rated health ordered from Poor to Excellent, an odds ratio below 1 therefore means poorer reported health. The order of the levels in factor() decides which end of the scale counts as "higher", so it is worth checking that order before reading any result. R also prints the intercepts (cut-points) with the opposite sign to β0j in Equation 4.3, so they cannot be substituted into that formula directly.

Fitted to the 795 people in the PHAA data, the ordinal model gives an odds ratio for smoking of 0.50 (95% CI 0.36 to 0.70). Self-rated health is ordered from Poor to Excellent, so a value below 1 points toward poorer reported health. In words, smokers have about half the odds of non-smokers of the same age of reporting a higher category of self-rated health. Because the model applies this one odds ratio at every split, the statement holds wherever the line is drawn: smokers have about half the odds of being fair or better rather than poor, about half the odds of being good or better rather than fair or poor, and so on up to excellent. The interval of 0.36 to 0.70 lies entirely below 1, so the data are hard to reconcile with no association. The odds ratio for age is 0.966 per year (95% CI 0.957 to 0.975). Because one year is a small step, the odds ratio for ten years is easier to picture. R gives it with exp(10 * coef(ord)["age"]), which prints 0.71 (Activity 4.2): a person ten years older has about 29% lower odds of reporting a higher category, for the same smoking status.

Figure 4.5 shows the distribution of self-rated health among non-smokers and smokers that lies behind the odds ratio for smoking.

Two horizontal stacked bars showing the percentage of non-smokers and smokers in each self-rated health category. Non-smokers: 8% poor, 20% fair, 32% good, 23% very good, 17% excellent. Smokers: 14% poor, 30% fair, 28% good, 20% very good, 8% excellent.
Figure 4.5. The bars show self-rated health among non-smokers (n = 662) and smokers (n = 133). The distribution for smokers is shifted toward the poorer categories, which is the pattern summarised by the odds ratio of 0.50.

The output of polr() also lists four intercepts, labelled Poor|Fair, Fair|Good, Good|Very good and Very good|Excellent. These are the cut-points between neighbouring categories, that is, the split-specific intercepts described in 4.2, and each one marks where the line between two categories falls on the log-odds scale. predict() uses them to work out predicted probabilities, but they describe the outcome rather than the effect of any predictor, so they are not usually reported or interpreted. Unlike glm(), polr() prints t values but no p-values. This is not a problem, because the 95% confidence intervals from confint() answer the same question. When an interval for an odds ratio excludes 1, the value that means no association, the association is statistically significant at the 5% level; when the interval includes 1, the data cannot rule out no association.

The odds ratio of 0.50 summarises the shift in Figure 4.5 in a single number, but many readers find odds ratios hard to picture. The next step describes the same model with predicted probabilities.

4.4 Predicted Probabilities for Two People

Odds ratios are hard to picture for many readers, so the model is often also described with predicted probabilities, as Section 3 does for the multinomial model. The predict() function, with type = "probs", gives the probability of each category for a chosen person. Worked Example 4.2b shows them for two 30-year-olds who differ only in smoking status; notice how the description compares the two people category by category rather than restating the odds ratio.

Worked Example 4.2b: Predicted Probabilities for Two People

The table gives the predicted probability of each category of self-rated health for a non-smoker and a smoker aged 30, from the ordinal model.

PersonPoorFairGoodVery goodExcellent
Non-smoker, age 300.050.140.290.280.24
Smoker, age 300.090.220.330.220.14

Each row adds to 1, because every person is in exactly one category. In plain words, the smoker is more likely than the non-smoker of the same age to rate their health as poor or fair (about 9 and 22 per cent, against 5 and 14 per cent) and less likely to rate it as very good or excellent (22 and 14 per cent, against 28 and 24 per cent). About one in seven 30-year-old smokers, but about one in four non-smokers, is predicted to rate their health as excellent. A description of this kind compares the two people category by category, with the probabilities written as percentages. In R, the table comes from predict(ord, newdata = data.frame(age = 30, smoker = c("No", "Yes")), type = "probs").

Worked Example 4.2b shows the predicted probabilities and the odds ratio telling the same story in different forms. Both rest on the assumptions of the model, which the next step sets out.

4.5 Checking the Proportional-Odds Assumption

The ordinal model shares the general assumptions of logistic regression and adds one of its own. Table 4.5 lists each assumption with the way it is checked.

Table 4.5. The assumptions of ordinal logistic regression and how each is checked.

AssumptionWhat it meansHow to check it
Ordered outcomeThe categories have a genuine, meaningful order.Reasoning about the categories; the levels are set in order with factor(…, ordered = TRUE).
IndependenceEach person contributes one independent observation.Judged from the study design.
Enough people in each categoryNo category is nearly empty, overall or within the groups of a categorical predictor.table(outcome) and table(predictor, outcome).
No strong multicollinearityThe predictors are not so strongly related that their effects cannot be separated.Correlations among the predictors.
Proportional oddsEach predictor has the same odds ratio at every split of the outcome.brant(model) from the brant package (Brant, 1990).

The proportional-odds assumption in the last row of Table 4.5 is the one that the ordinal model adds. In plain words, it says that a predictor changes the odds of being higher up the scale by the same factor wherever the line between “at or above” and “below” is drawn. It is checked with the Brant test, whose null hypothesis is that the assumption holds, so a p-value above 0.05 is consistent with the assumption and a p-value below 0.05 is the warning sign. Expand the two panels below to see how the Brant test works and what can be done if the assumption fails.

How the Brant test works

The Brant test fits a separate binary logistic regression at each split and compares the coefficients across the splits. If the proportional-odds assumption holds, the coefficients should be similar apart from chance variation. The test reports an omnibus result for all predictors together and one result for each predictor. Each result is a chi-squared statistic with a p-value. A p-value above 0.05 means that the data are consistent with the assumption, and a p-value below 0.05 means that the predictor's odds ratio appears to change from one split to another.

What to do if the assumption fails

There are three common responses. When a failure is driven by a category with very few people, combining it with a neighbouring category (for example, poor with fair) can solve the problem, provided the combined category still makes sense. When the assumption fails badly, the order can be set aside and a multinomial logistic regression fitted (Section 3), which gives each category its own relative risk ratios. When only one or two predictors fail, a partial proportional-odds model lets those predictors have a different odds ratio at each split while keeping one odds ratio for the others. Partial proportional-odds models are fitted with the vglm() function in the VGAM package and are beyond the scope of this course. In very large samples the Brant test can flag small differences that have no practical importance, so the split-specific odds ratios are worth inspecting before the model is abandoned.

For the PHAA model, the Brant test in Activity 4.2 gives an omnibus p-value of 0.35, so the data are consistent with one odds ratio for each predictor at every split. The card below links to a narrated walkthrough of ordinal logistic regression in R. Activity 4.2 then fits the model of this section to the PHAA data, reads its odds ratios, runs the Brant test and asks you for the predicted probabilities of two people: run the script alongside the reading and answer the questions from your own output.

Learn to do this in R

Narrated R walkthrough: Ordinal Logistic Regression in R

This walkthrough fits an ordinal logistic regression to the course outcomes data. It orders the outcome categories, looks at the data before modelling, converts the results to odds ratios and predicted probabilities, and checks the proportional odds assumption.

Open the Ordinal Logistic Regression in R walkthrough
R Activity 4.2: ordinal logistic regression for self-rated health

Text version of the activity: the code of the run-along script, its console output and notes on reading it.

library(MASS)    # polr() fits the ordinal logistic model
library(brant)   # brant() checks it; if missing, run install.packages("brant") once
phaa <- read.csv("https://heal-learn.ca/r-activities/data/phaa_outcomes.csv")   # course data, read from the website
phaa <- na.omit(phaa)                   # keep the 795 people with no missing values
phaa$smoker <- factor(phaa$smoker, levels = c("No", "Yes"))   # "No" = reference
phaa$self_rated_health <- factor(phaa$self_rated_health,
  levels = c("Poor", "Fair", "Good", "Very good", "Excellent"), ordered = TRUE)
table(phaa$smoker, phaa$self_rated_health)   # people in each category, by smoking
Console output
Poor Fair Good Very good Excellent No 54 132 212 149 115 Yes 19 40 37 27 10

The factor() line sets the order of the categories from Poor to Excellent and marks the variable as ordered, which polr() needs, so a higher category means better reported health. The table is the first check: every category has people in it in both smoking groups, and the smallest cell (10 smokers who rate their health as excellent) is small but not empty. If library(brant) reports that there is no package called brant, run install.packages("brant") once.

ord <- polr(self_rated_health ~ age + smoker, data = phaa, Hess = TRUE)
summary(ord)
Console output
Call: polr(formula = self_rated_health ~ age + smoker, data = phaa, Hess = TRUE) Coefficients: Value Std. Error t value age -0.03421 0.0048 -7.128 smokerYes -0.69598 0.1708 -4.075 Intercepts: Value Std. Error t value Poor|Fair -4.0726 0.2699 -15.0877 Fair|Good -2.5196 0.2414 -10.4392 Good|Very good -1.1291 0.2267 -4.9803 Very good|Excellent 0.1108 0.2275 0.4870 Residual Deviance: 2379.675 AIC: 2391.675

Reading the output. The Coefficients block holds one value per predictor on the log-odds scale. Both are negative, which with polr() means that older people and smokers are more likely to be in the lower (poorer) categories. The Intercepts block holds the four cut-points between neighbouring categories, which are not usually interpreted. The model reports t values but no p-values, so the confidence intervals in the next step are used to judge significance.

exp(cbind(OR = coef(ord), confint(ord)))   # odds ratios with 95% CIs
exp(10 * coef(ord)["age"])                 # odds ratio for ten years of age
exp(10 * confint(ord)["age", ])            # and its 95% CI
Console output
Waiting for profiling to be done... OR 2.5 % 97.5 % age 0.9663676 0.9572778 0.9754655 smokerYes 0.4985846 0.3562932 0.6962966 age 0.7102705 Waiting for profiling to be done... 2.5 % 97.5 % 0.6462194 0.7800439

Exponentiating gives odds ratios for being in a higher category, and the model applies each one at every split of the scale. The odds ratio for smoking is 0.50 (95% CI 0.36 to 0.70). The odds ratio for age is 0.966 per year (95% CI 0.957 to 0.975), or 0.71 (95% CI 0.65 to 0.78) for ten years of age. Both intervals exclude 1.

brant(ord)                                 # H0: the assumption holds
# odds ratios from a separate logistic regression at each split ("k or better")
split_or <- sapply(c("Fair", "Good", "Very good", "Excellent"), function(k)
  coef(glm(self_rated_health >= k ~ age + smoker, data = phaa, family = binomial))[-1])
round(exp(split_or), 3)
Console output
-------------------------------------------- Test for X2 df probability -------------------------------------------- Omnibus 6.71 6 0.35 age 4.3 3 0.23 smokerYes 2.19 3 0.53 -------------------------------------------- H0: Parallel Regression Assumption holds Fair Good Very good Excellent age 0.960 0.969 0.963 0.974 smokerYes 0.545 0.483 0.566 0.382

The Brant test reports an omnibus p-value of 0.35 and p-values of 0.23 for age and 0.53 for smoking. Its null hypothesis, printed on the last line, is that the proportional-odds (parallel regression) assumption holds, so p-values above 0.05 mean that the data are consistent with it. The odds ratios from a separate logistic regression at each of the four splits (Fair or better, Good or better, Very good or better, and Excellent) scatter around the model's single values: 0.38 to 0.57 for smoking against 0.50, and 0.960 to 0.974 for age against 0.966.

Files for this activity Data Code Answer key

R Reflect on what you just ran

Answer each question from your own output, as on the final exam: find the number, say what it means, judge the check.

1. Interpret the odds ratio for smokerYes, with its 95% confidence interval, as the model states it, and interpret the odds ratio for ten years of age from lines 22 and 23. The output gives no p-values: how can you tell whether an odds ratio is statistically significant, and which of the two are?

Model answerThe odds ratio for smoking is 0.50 (95% CI 0.36 to 0.70): smokers have about half the odds (about 50% lower odds) of reporting a higher category of self-rated health than non-smokers of the same age. The comparison applies at every split of the scale (for example Good or better against Fair or Poor, and Excellent against everything below it), because the model estimates one odds ratio for all the splits. For age, the odds ratio is 0.966 per year, or 0.71 (95% CI 0.65 to 0.78) for ten years of age: a person ten years older has about 29% lower odds of reporting a higher category, for the same smoking status. The output gives no p-values, so significance is judged from the confidence intervals: an odds ratio whose 95% CI excludes 1 is statistically significant at the 5% level. Both intervals lie entirely below 1 (0.36 to 0.70 for smoking, and 0.957 to 0.975 per year or 0.65 to 0.78 per ten years for age), so both associations are statistically significant.

2. In plain words, what is the proportional-odds assumption, and is it met here? Use the output of brant(ord) and the odds ratios at each split. What would you do next if the p-value for smoking had been 0.01?

Model answerThe proportional-odds assumption is that each predictor has the same odds ratio at every split of the outcome, so one odds ratio per predictor summarises it. The Brant test checks the assumption, and its null hypothesis is that the assumption holds. Every p-value is above 0.05 (omnibus 0.35, age 0.23 and smoking 0.53), so there is no evidence against the assumption, and the model is a fair summary. The odds ratios at each split agree: for smoking they scatter from 0.38 to 0.57 around the model's 0.50, and for age they stay between 0.960 and 0.974, close to 0.966. If the p-value for smoking had been 0.01, its odds ratio would appear to change across the splits, so the first step would be to inspect the split-specific odds ratios for smoking and judge whether the differences are large enough to matter. The options are then to report those split-specific odds ratios, to fit a partial proportional-odds model that frees only smoking, or to fit a multinomial model that sets the order aside; combining categories helps only when a nearly empty category drives the result, and no category is nearly empty here.

3. Run your own code: at the end of the script, type two <- data.frame(age = 30, smoker = c("No", "Yes")) and round(predict(ord, newdata = two, type = "probs"), 2) and rowSums(predict(ord, newdata = two, type = "probs")) and run them. The two rows are the predicted probabilities of each category for a 30-year-old non-smoker and a 30-year-old smoker, and the last line adds up each row. Use it to check that each row is a complete distribution, and describe in plain words how the two people differ.

Model answerThe last line prints 1 for both people: each row adds to 1, because every person is in exactly one category, so each row is a complete distribution. The smoker is more likely than the non-smoker of the same age to rate their health as poor or fair (about 9% and 22%, against 5% and 14%). The smoker is less likely to rate it as very good or excellent (about 22% and 14%, against 28% and 24%), and good is the most likely answer for both. For example, about one in seven 30-year-old smokers, but about one in four 30-year-old non-smokers, is predicted to rate their health as excellent. The whole distribution shifts toward the poorer end of the scale for the smoker, which is the pattern that the odds ratio of 0.50 summarises; the smoker is not 0.50 times as likely to be in each category, because an odds ratio compares odds at a split, not probabilities.
Saved.

Your output from Activity 4.2 reproduces the odds ratio of 0.50 for smoking, the Brant test results and the predicted probabilities in Worked Example 4.2b. The key takeaways below draw the section together before its knowledge check.

Key Takeaways

  • 4.1 An ordinal outcome, such as self-rated health from poor to excellent, has categories that can be ranked, but the distances between them are unknown. The two common shortcuts both lose something. Coding the categories as 1 to 5 and fitting lm() treats every step as worth exactly one unit, assumes normal residuals that a five-category outcome cannot have, and reports slopes in "points" that are not real units. Collapsing the categories into two groups for a binary logistic regression throws away the detail within each group, and a different cut-off could give a different answer. When a question proposes either shortcut, say what it assumes or loses and recommend ordinal logistic regression, which keeps every category and uses their order.
  • 4.2 The ordinal model splits the outcome into "at or above" versus "below" at every possible place, so five ordered categories give four splits (Figure 4.4). Each split is a yes-or-no comparison that a binary logistic regression could handle on its own, and the ordinal model fits all of them at once. Every split gets its own intercept, because the share of people at or above it changes from one split to the next, but each predictor gets a single coefficient that is shared by all the splits. Worked Example 4.2 sets the crude odds ratios for smoking that R gives at the four splits (0.53, 0.49, 0.58 and 0.39) beside the model's single value of 0.50, and the split-specific odds ratios printed in Activity 4.2 show the same pattern once age is included.
  • 4.3 You fit the ordinal model with polr() from the MASS package, after setting the levels in order with factor(…, ordered = TRUE), and turn its coefficients into odds ratios with exp(cbind(OR = coef(ord), confint(ord))). Each odds ratio is for being in a higher category, and it applies at every split: smokers have about half the odds of non-smokers of the same age of reporting a higher category of self-rated health (OR 0.50, 95% CI 0.36 to 0.70). Because polr() takes "higher" from the order of the levels, check that order before you decide whether an odds ratio below 1 means better or poorer health (see the callout How R Writes the Ordinal Model). The output gives t values but no p-values, so judge significance from the confidence interval: an interval that excludes 1 shows a statistically significant association at the 5% level. The four intercepts, such as Poor|Fair, are cut-points that are not usually interpreted, and for age a ten-year odds ratio is easier to describe: R gives it with exp(10 * coef(ord)["age"]) as 0.71, or about 29% lower odds per decade.
  • 4.4 Odds ratios are hard for many readers to picture, so the model is often also described with predicted probabilities, which predict() with type = "probs" gives for every category for a person you describe in newdata. Each person's probabilities add to 1, because everyone is in exactly one category. To describe two people, compare them category by category in plain words, with the probabilities written as percentages: a 30-year-old smoker is more likely than a 30-year-old non-smoker to rate their health as poor or fair (9% and 22%, against 5% and 14%) and less likely to rate it as very good or excellent (22% and 14%, against 28% and 24%). In an answer, name the two people, say which way the probabilities shift and quote a few of the numbers, rather than restating the odds ratio.
  • 4.5 The proportional-odds assumption says that each predictor has the same odds ratio at every split of the outcome; in plain words, a predictor changes the odds of being higher up the scale by the same factor wherever you draw the line. The Brant test, brant(model) from the brant package, checks it by comparing separate logistic regressions fitted at each split, and it reports an omnibus result and one result for each predictor. Its null hypothesis is that the assumption holds, so a p-value above 0.05 means the data are consistent with it (as in the PHAA model, with an omnibus p-value of 0.35), while a p-value below 0.05 means that the predictor's odds ratio appears to change across the splits. If a predictor fails, inspect its split-specific odds ratios first, especially in a very large sample, and then consider combining a sparse category with a neighbouring one, fitting a multinomial model or fitting a partial proportional-odds model. A common trap is to read a small Brant p-value as good news: here, a small p-value means the assumption is in doubt.
Knowledge check: this section

1. A community survey asked 1,050 adults to rate their mental health as Poor, Fair, Good, Very good or Excellent. One colleague proposes coding the answers 1 to 5 and fitting a linear regression; another proposes grouping them into "Good or better" and "Fair or poor" and fitting a logistic regression. Which response is correct?

The codes are equally spaced only because someone chose them. The categories have a natural order, but the distances between them are unknown, and five values cannot give normal residuals.
Grouping throws away detail, such as the difference between Good and Excellent, and the result depends on where the cut-off is placed. It gives a valid odds ratio for one split only.
Coding 1 to 5 assumes equal steps, and grouping discards detail and depends on the cut-off. An ordinal logistic regression uses the order of the categories without assuming their spacing.
A multinomial model throws away the order, which carries information. Self-rated mental health has a clear order, so an ordinal model is the better match.
The correct response is that both shortcuts lose information and that an ordinal logistic regression should be used. The information needed is what the categories mean: they are ordered (Excellent is better than Very good), but the distances between them are unknown. Coding them 1 to 5 assumes that the step from Poor to Fair is as large as the step from Very good to Excellent, and an outcome with only five values cannot have normal residuals; grouping them gives a valid odds ratio for one split only, ignores the difference between Good and Excellent, and a different cut-off could give a different answer. The tempting first option confuses the codes with the categories, since the codes are equally spaced only because someone chose them; the multinomial option throws away the order, which carries information. (Section 2, 4.1 What Makes an Outcome Ordinal? and the three flip cards; Objective 4.1)

2. The mental health outcome in Question 1 has five ordered categories. How does an ordinal logistic regression compare them?

An ordinal model cuts K ordered categories in K − 1 places, not K, and it gives each predictor one shared odds ratio rather than a separate one at each comparison.
The splits are at-or-above against below, not each category against Poor. Split 3 groups Very good and Excellent together against the three lower categories.
This has the two parts the wrong way round. Each split has its own intercept, because the share at or above it differs, while each predictor has one odds ratio shared by all splits.
Five ordered categories can be cut into at-or-above and below in four places. Each split gets its own intercept, and the proportional-odds assumption gives each predictor one shared odds ratio.
The correct description is four at-or-above versus below splits, each with its own intercept and one shared odds ratio per predictor. The information needed is the number of ordered categories, K = 5, which can be cut into at-or-above and below in K − 1 = 4 places: Fair or better against Poor, Good or better against Poor or Fair, Very good or better against Good or worse, and Excellent against the rest. Each split has its own intercept, because the share of people at or above it differs, but every predictor gets one coefficient for all four splits, which is the proportional-odds assumption. The option that compares each category with Poor does not describe at-or-above splits, since split 3 puts Very good and Excellent together against the three lower categories, and the option with one intercept and split-specific odds ratios has the two parts the wrong way round. (Section 2, 4.2 How the Model Works: A Series of Splits, Figure 4.4 and Eq 4.3; Objective 4.2)

3. The survey team fitted polr(mh ~ lonely + exercise + age10, Hess = TRUE), where mh is ordered from Poor to Excellent, lonely is 1 for adults who often feel lonely, exercise is the number of days a week with at least 30 minutes of exercise (0 to 7) and age10 is age in decades. The output gives no p-values. Which statement is correct?

> exp(cbind(OR = coef(ord), confint(ord))) OR 2.5 % 97.5 % lonely 0.42 0.33 0.54 exercise 1.12 1.06 1.18 age10 0.96 0.88 1.05
This reverses the direction. With polr(), an odds ratio below 1 favours the lower categories, so lonely adults are more likely, not less likely, to rate their mental health as Poor.
With polr(), an odds ratio below 1 means lower odds of a higher category at every split, adjusted for the other predictors, and a 95% CI that excludes 1 shows significance at the 5% level.
Significance can be judged without p-values: a 95% confidence interval that excludes 1 shows significance at the 5% level. Here two intervals exclude 1 and one includes it.
An ordinal model reports odds ratios for a higher category, not changes in a category score. The categories have no numeric spacing to change by fractions.
The correct statement reads the odds ratio for loneliness as the odds of a higher category at every split and judges significance from the intervals. The information needed is the direction that polr() uses (an odds ratio above 1 favours higher categories and one below 1 favours lower categories), the odds ratios and their 95% CIs. An odds ratio of 0.42 means 0.42 times the odds, or 58% lower odds, of rating mental health in a higher category, for example Good or better rather than Poor or Fair, and the same at the other splits. A 95% CI that excludes 1 shows significance at the 5% level: 0.33 to 0.54 and 1.06 to 1.18 exclude 1, while 0.88 to 1.05 includes it. The tempting first option reverses the direction: with polr(), an odds ratio below 1 means that lonely adults are more likely, not less likely, to be in the poorer categories such as Poor. (Section 2, 4.3 Interpreting the Odds Ratios and the callout How R Writes the Ordinal Model; Objective 4.3)

4. From the model in Question 3, the predicted probabilities below are for two 40-year-olds who exercise three days a week, one who does not often feel lonely and one who does. Which description is correct?

PersonPoorFairGoodVery goodExcellent
Not often lonely0.0690.2000.3770.2450.109
Often lonely0.1500.3170.3460.1380.049
Reading the two rows category by category shows the lonely adult shifted toward the poorer ratings and away from the better ones, with Good the most likely answer for both.
An odds ratio compares odds at a split, not probabilities in each category. The lonely adult is in fact more likely to be in the Poor and Fair categories.
The largest probability in both rows is Good. The two adults differ in how probability shifts between categories, not in sitting at opposite ends.
The chances of Good are similar, but the other categories differ clearly: the lonely adult has higher chances of Poor and Fair and lower chances of Very good and Excellent.
The correct description compares the two adults category by category. The information needed is each row of probabilities, and each row adds to 1. Reading across, the lonely adult has the higher probability of Poor (0.150 against 0.069) and Fair (0.317 against 0.200) and the lower probability of Very good (0.138 against 0.245) and Excellent (0.049 against 0.109), with Good the largest value in both rows (0.346 and 0.377); written as proportions, about one in seven lonely adults, but one in fourteen of the others, is predicted to rate their mental health as Poor. The tempting second option applies the odds ratio of 0.42 to the probabilities, but an odds ratio compares odds at a split, not probabilities, and the lonely adult is in fact more likely to be in the Poor and Fair categories. (Section 2, 4.4 Predicted Probabilities for Two People, Worked Example 4.2b; Objective 4.4)

5. A Brant test for the model in Question 3 gave the results below. Separate logistic regressions at the four splits gave odds ratios for lonely of 0.70 (Fair or better against Poor), 0.52, 0.38 and 0.29 (Excellent against the rest). Is the proportional-odds assumption met, and what should be done next?

> brant(ord) Test for X2 df probability Omnibus 21.8 9 0.01 lonely 16.9 3 0 exercise 1.4 3 0.71 age10 2.2 3 0.53 H0: Parallel Regression Assumption holds
This reads the Brant test backwards. Its null hypothesis is that the assumption holds, so a small p-value is evidence against the assumption, not a sign of good fit.
The Brant test is read one predictor at a time. Exercise and age pass; only loneliness fails, so removing every predictor discards valid results.
Coding the categories 1 to 5 treats every step as equal and assumes normal residuals, the problems the ordinal model was chosen to avoid. A failed assumption calls for freeing the predictor, not abandoning order.
The Brant test fails only for loneliness, whose split-specific odds ratios fall steadily. A partial proportional-odds model can free that predictor alone, with a multinomial model as the alternative.
The correct answer is that the assumption fails for loneliness only, and that the next step is to look at its split-specific odds ratios and free that predictor. The information needed is each Brant p-value (a value above 0.05 is consistent with the assumption) and the four split-specific odds ratios. The omnibus p-value (0.01) and the p-value for loneliness (printed as 0) are below 0.05, while exercise (0.71) and age (0.53) pass; the odds ratios for loneliness fall steadily from 0.70 to 0.29, so loneliness matters more for reaching the higher categories than the single value of 0.42 suggests. The options are a partial proportional-odds model that lets only loneliness differ by split, a multinomial model that sets the order aside, or combining categories if a nearly empty category were driving the result. The tempting first option reads the test backwards: its null hypothesis is that the assumption holds, so a small p-value is evidence against the assumption, not a sign of good fit. (Section 2, 4.5 Checking the Proportional-Odds Assumption, Table 4.5 and the accordion panels "How the Brant test works" and "What to do if the assumption fails"; Objective 4.5)

6. An occupational health survey asked 1,150 warehouse workers how much back pain had limited their work in the past month. The outcome limit was stored as an ordered factor from Not at all (263 workers) through A little (387) and Moderately (312) to A lot (188), so a higher category means more limitation. The predictors are lifting (1 = lifts loads over 20 kg on most shifts), age_dec (age in decades) and female (1 = woman). Separate logistic regressions at the three splits gave odds ratios for age_dec of 1.04 (A little or more against Not at all), 1.19 and 1.56 (A lot against the rest). Which summary of the output is correct?

> exp(cbind(OR = coef(ord), confint(ord))) OR 2.5 % 97.5 % lifting 1.919970 1.5526703 2.376735 age_dec 1.199801 1.1015819 1.307206 female 1.072336 0.8617034 1.334519 > brant(ord) Test for X2 df probability Omnibus 28.9 6 0 lifting 1.5 2 0.47 age_dec 26.73 2 0 female 0.61 2 0.74 H0: Parallel Regression Assumption holds
With levels ordered from Not at all to A lot, an odds ratio above 1 favours more limitation. The Brant test is read per predictor, and age's rising split-specific odds ratios show why freeing only age is the next step.
With polr(), an odds ratio above 1 makes the higher categories more likely, and here higher means more limitation. The direction comes from the level order, not from a rule that above 1 is better.
The omnibus test signals a failure somewhere, but the predictor rows show it is age alone; lifting and sex pass. A linear regression on the codes would treat every step as equal.
Combining categories helps when a nearly empty category drives the failure, but the smallest category here holds 188 workers. Freeing age in a partial proportional-odds model, or reporting its split-specific odds ratios, fits the problem.
The correct summary reads the direction from the order of the levels and reads the Brant test one predictor at a time. The information needed is the level order (Not at all to A lot, so a higher category means more limitation), the odds ratios with their intervals and the Brant p-values. With polr(), an odds ratio above 1 makes the higher categories more likely, so 1.92 means higher odds of a more limiting category at every split, and its interval excludes 1. The Brant null hypothesis is that the assumption holds: lifting (0.47) and female (0.74) are consistent with it, while age and the omnibus test, both printed as 0, are below 0.05, and the split-specific odds ratios for age rise steadily from 1.04 to 1.56. Combining categories helps when a nearly empty category drives the failure, but the smallest category here has 188 workers, and a linear regression on the codes would treat every step as equal. (Section 2, 4.3 Interpreting the Odds Ratios and the callout How R Writes the Ordinal Model, and 4.5 Checking the Proportional-Odds Assumption with the accordion panels "How the Brant test works" and "What to do if the assumption fails"; Objectives 4.3 and 4.5)
● Complete the knowledge check to continue.
Section 3 of 4

Multinomial Logistic Regression

⏱ Estimated time: 35 minutes
Lesson 4 · Section 3

Multinomial Logistic Regression

A model for outcomes with three or more categories that have no natural order, such as usual place of care.

Nominal outcomes

Categories with no order

People name one usual place of care.
Each cancer is diagnosed as one type.
Commuters have one main way of travelling to work.
Nicotine users choose a type of product.

No category is higher or lower than another, so each category is allowed its own relationship with the predictors.

The idea

Each category is compared with a reference

Walk-in clinicversusFamily doctor
Emergency departmentversusFamily doctor
No usual placeversusFamily doctor

With K categories there are K − 1 comparisons. Each comparison has its own intercept and its own slope for every predictor.

The PHAA example

Usual place of care by smoking

Grouped bar chart of usual place of care for non-smokers and smokers. Family doctor: 60% and 42%. Walk-in clinic: 23% and 27%. Emergency department: 6% and 12%. No usual place: 11% and 19%.
The bars show the percent of non-smokers (n = 662) and smokers (n = 133) in each category of usual place of care.
Reading the output

Relative risk ratios for smoking

Comparison (versus Family doctor)RRR for smokers95% CI
Walk-in clinic1.721.08 to 2.74
Emergency department3.011.57 to 5.75
No usual place2.661.54 to 4.61

The relative risk ratio (RRR) compares the chance of one category against the reference for smokers and non-smokers of the same age.

Reading the output

Relative risk ratios for age (per year)

Comparison (versus Family doctor)RRR per year95% CIRRR per 10 years
Walk-in clinic0.9770.96 to 0.990.79
Emergency department0.9830.96 to 1.000.84
No usual place0.9600.94 to 0.980.66

One predictor can have a clear association in one comparison and none in another. The ten-year values come from the unrounded coefficients.

Predicted probabilities

The model in plain numbers: two 30-year-olds

Family doctorWalk-in clinicEmergency departmentNo usual place
Non-smoker, age 3051%28%6%15%
Smoker, age 3032%30%12%26%

Each row adds to 100%, apart from rounding. predict(mn, newdata, type = "probs") produces these values.

Assumptions and checks

What to check in a multinomial model

AssumptionHow to check it
Categories have no order and do not overlapReasoning about the categories
Observations are independentStudy design
Enough people in every categorytable(outcome, predictor)
No strong multicollinearityCorrelations among the predictors
Independence of irrelevant alternatives (IIA)Reasoning: are any two categories close substitutes?
Choosing between the two

Ordinal or multinomial?

Ordered categories

Start with ordinal logistic regression. If the Brant test fails, a multinomial model is a reasonable fallback.

Unordered categories

Use multinomial logistic regression. The ordinal model does not apply.

For five categories and two predictors, the ordinal model estimates 2 slopes and a multinomial model estimates 8.

Carry forward

What to take into the next section

  • A multinomial model compares each category with a reference category, giving K − 1 comparisons.
  • Each relative risk ratio belongs to one comparison, and predicted probabilities are often the clearest summary.
  • The model needs enough people in every category and assumes the categories are distinct alternatives.

Overview

This section presents multinomial logistic regression, the model for an outcome with three or more categories that have no natural order. The running example is the usual place of care, a question asked in many Canadian health surveys because having a regular source of primary care is linked to better access to preventive services and continuity of care. In the PHAA data, usual place of care is a simulated variable added for this lesson, with four categories: family doctor, walk-in clinic, emergency department and no usual place. The section explains why such an outcome needs a model of its own, shows how the model compares each category with a reference category, fits it with age and smoking as predictors, interprets its relative risk ratios and predicted probabilities, and sets out the assumptions to check.

Learning Objectives

  • 5.1 Recognize a nominal outcome and explain why the ordinal model does not suit it.
  • 5.2 Explain the role of the reference category, why a K-category outcome gives K − 1 comparisons, and what changes when a different reference category is chosen.
  • 5.3 Fit a multinomial logistic regression in R with multinom() and interpret its relative risk ratios with their confidence intervals, naming both categories in each comparison.
  • 5.4 Use predicted probabilities from the model to describe the overall chance of each category.
  • 5.5 List the assumptions of the multinomial model and explain why two categories that are close substitutes make the independence of irrelevant alternatives doubtful.

5.1 What Makes an Outcome Nominal?

An outcome is nominal when its categories are simply different from one another, with no ranking. A family doctor, a walk-in clinic and an emergency department are different kinds of places, and none of them is "more" than the others. Type of cancer, main mode of travel to work, type of nicotine product and reason for missing a vaccination are other examples. Because there is no order to use, a model for a nominal outcome must let each category have its own relationship with every predictor.

A smoker might be more likely than a non-smoker to use an emergency department and also more likely to have no usual place, and the two increases need not be the same size. An ordinal model, which gives each predictor a single odds ratio for "moving up the scale", cannot describe this pattern, because there is no scale to move along.

The order of the categories therefore decides between the two models for categorical outcomes. When the categories of an outcome have no order, multinomial logistic regression is the appropriate choice. When the categories are ordered, ordinal logistic regression (Section 2) is the place to start, because it uses the order and summarizes each predictor with a single odds ratio. If the proportional-odds assumption fails, a multinomial model is a reasonable alternative, because it makes no assumption about order. The trade-off is that the multinomial model estimates many more coefficients and its results take longer to describe.

The next step shows how the multinomial model gives each category its own coefficients by comparing it with a reference category.

5.2 Comparisons With a Reference Category

The multinomial model chooses one category as the reference category and compares every other category with it. In R, the reference is set with relevel(), and this lesson uses family doctor, the most common answer. Figure 4.6 sets out the comparisons that follow from this choice. With four categories, the model makes three comparisons:

Walk-in clinicversusFamily doctor
Emergency departmentversusFamily doctor
No usual placeversusFamily doctor

Figure 4.6. The three comparisons that the multinomial model makes for usual place of care, each with family doctor as the reference category.

In general, an outcome with K categories gives K − 1 comparisons, because the reference category is not compared with itself. Each comparison is written like a small logistic regression, with its own intercept and its own slope for every predictor (Hosmer, Lemeshow & Sturdivant, 2013). This is the key difference from the ordinal model in Section 2, where each predictor had one coefficient shared by every split. Here smoking has three separate coefficients, one for each comparison, so its association with walk-in clinic use can differ in size from its association with emergency department use. Although the comparisons look like separate logistic regressions, the model fits all of them at the same time. Fitting them together ensures that, for any person, the predicted probabilities of the four categories always add to 1, which separate models could not guarantee.

Equation 4.4 writes the model for each comparison with the reference category, with age and smoking as predictors.

Multinomial logistic regression (one equation per comparison)
\[ \ln\frac{\color{#0B7B6B}{P(Y = k)}}{\color{#C2410C}{P(Y = \text{Family doctor})}} = \color{#6D28D9}{\beta_{0k}} + \color{#1D4ED8}{\beta_{1k}}\,\text{age} + \color{#1D4ED8}{\beta_{2k}}\,\text{smoker} \]Eq 4.4
For each category k other than the reference, the log of the ratio of the probability of category k to the probability of the reference category equals an intercept for that comparison plus slopes for that comparison. Every symbol carries the label k, because every comparison has its own coefficients.

The choice of reference category changes how the results are presented, but it does not change the model itself. How well the model fits and the predicted probability of each category for each person stay exactly the same whichever category is chosen, because the same information is simply being described from a different starting point. A different reference (for example, walk-in clinic) would give a different set of comparisons from the same fitted model. A good reference category is a large group that is a natural point of comparison for the research question.

Each comparison has its own coefficients, and the next step shows how their exponentiated values are read.

5.3 Interpreting Relative Risk Ratios

The exponentiated coefficients of a multinomial model are called relative risk ratios (RRRs). The name can mislead, so it helps to build the idea in two steps. First, within any one group of people, the model looks at the chance of naming a particular category relative to the chance of naming the reference category. For non-smokers, for example, this is the probability of naming an emergency department divided by the probability of naming a family doctor, written P(emergency department) ÷ P(family doctor). Second, the RRR compares that ratio between two groups. The RRR for smoking in the emergency department comparison therefore says how many times larger the ratio P(emergency department) ÷ P(family doctor) is for smokers than for non-smokers of the same age. Because each RRR describes only one comparison with the reference, a model with three comparisons has three RRRs for every predictor. An RRR above 1 means that the predictor is associated with a higher chance of the category relative to the reference, and an RRR below 1 means that it is associated with a lower chance of the category relative to the reference. An RRR of 1 means that the predictor makes no difference to that comparison.

Worked Example 4.3 applies this reading to the crude RRRs for smoking that R gives from the PHAA data and compares them with the RRRs from the model; watch how each number is read as a comparison with family doctor.

Worked Example 4.3: Crude and Adjusted Relative Risk Ratios

A multinomial model with smoking as its only predictor gives the crude RRRs, which exp(coef(mn0)) prints.

> mn0 <- multinom(usual_care ~ smoker, data = phaa, trace = FALSE) > round(exp(coef(mn0)), 2) (Intercept) smokerYes Emergency department 0.10 2.92 No usual place 0.18 2.54 Walk-in clinic 0.39 1.67

R reports the crude RRR for smoking in the Emergency department row as 2.92. It is read as a ratio of two ratios: the ratio of naming an emergency department to naming a family doctor is 2.92 times as large among smokers as among non-smokers. The (Intercept) column gives that ratio for the reference group, non-smokers, so its value of 0.10 means that about one non-smoker names an emergency department for every ten who name a family doctor. The cross-table at the start of Activity 4.3 shows where the pattern comes from: relative to the number who have a family doctor, more smokers than non-smokers name an emergency department (16 smokers against 56 with a family doctor, compared with 39 non-smokers against 399). R turns these counts into the RRR, and it is the RRR that is interpreted.

The model with age and smoking gives an RRR of 3.01 for this comparison (Table 4.6). It differs slightly from the crude value because the model also adjusts for age. The crude RRRs of 2.54 for no usual place and 1.67 for a walk-in clinic are read in the same way, each comparing the ratio of that category to family doctor among smokers with the same ratio among non-smokers.

Worked Example 4.3 shows that every RRR belongs to one comparison with the reference category. Table 4.6 gives the RRRs from the fitted model for smoking and for age in each of the three comparisons.

Table 4.6. Relative risk ratios for usual place of care from the multinomial model, with family doctor as the reference category.

Comparison (versus Family doctor)RRR for smokers (95% CI)RRR per year of age (95% CI)RRR per 10 years of age
Walk-in clinic1.72 (1.08 to 2.74)0.977 (0.96 to 0.99)0.79
Emergency department3.01 (1.57 to 5.75)0.983 (0.96 to 1.00)0.84
No usual place2.66 (1.54 to 4.61)0.960 (0.94 to 0.98)0.66

Smoking is associated with all three comparisons: among people of the same age, smokers are more likely than non-smokers to name a walk-in clinic, an emergency department or no usual place, each compared with a family doctor. Age is clearly associated with two of the comparisons. Older people are less likely to use a walk-in clinic (RRR 0.79 per ten years) or to have no usual place (RRR 0.66 per ten years), each compared with having a family doctor. The interval for the emergency department comparison includes 1, so the data do not show a clear age difference for that comparison. R gives the ten-year values from the unrounded coefficients with exp(10 * coef(mn)[, "age"]) (Activity 4.3).

Because each RRR compares a category only with the reference, it is easy to misread it as the overall chance of a category, a common trap that the caution below sets out.

An RRR Is a Ratio of Two Ratios

An RRR compares one category with the reference only. The RRR of 3.01 describes the ratio of emergency department to family doctor, which is three times as large for smokers as for non-smokers of the same age. It does not mean that smokers are three times as likely to name an emergency department. The overall chance that a smoker names an emergency department is a different quantity, and the predicted probabilities in Table 4.7 show it.

The next step turns to these predicted probabilities.

5.4 Predicted Probabilities

The predict() function converts the fitted model into the probability of each category for any chosen combination of predictor values. Predicted probabilities are often the clearest way to present a multinomial model to readers who are not statisticians. Table 4.7 shows them for two 30-year-olds who differ only in smoking status.

Table 4.7. Predicted probabilities of each usual place of care for a non-smoker and a smoker aged 30.

PersonFamily doctorWalk-in clinicEmergency departmentNo usual place
Non-smoker, age 300.510.280.060.15
Smoker, age 300.320.300.120.26

For the 30-year-old smoker, the probability of naming an emergency department (0.12) is twice that for the non-smoker (0.06), and the probability of having no usual place rises from 0.15 to 0.26. These numbers can be stated directly in a report: in this population, about one in four 30-year-old smokers has no usual place of care.

Figure 4.7 shows the observed percentages in each category by smoking status, for all ages combined, which can be set beside the predicted probabilities in Table 4.7.

Grouped bar chart of usual place of care for non-smokers and smokers. Family doctor 60% and 42%; walk-in clinic 23% and 27%; emergency department 6% and 12%; no usual place 11% and 19%.
Figure 4.7. The bars show the observed percentages in each category by smoking status, for all ages combined. Smokers are less often attached to a family doctor and more often in each of the other three categories.

The relative risk ratios and predicted probabilities can be trusted only if the assumptions of the model hold, and the next step sets them out.

5.5 Assumptions and the Independence of Irrelevant Alternatives

Table 4.8 lists the assumptions of the multinomial model with the way each is checked. The first four resemble the assumptions of the ordinal model in Table 4.5 in Section 2, and the last, the independence of irrelevant alternatives (IIA), is new.

Table 4.8. The assumptions of multinomial logistic regression and how each is checked.

AssumptionWhat it meansHow to check it
Nominal, mutually exclusive categoriesThe categories have no meaningful order, and each person belongs to exactly one.Reasoning about the categories and the survey question.
IndependenceEach person contributes one independent observation.Judged from the study design.
Enough people in every categoryEach comparison is estimated separately, so a small category gives unstable estimates and wide intervals.table(outcome) and table(outcome, predictor). Very small categories can sometimes be combined with a similar category.
No strong multicollinearityThe predictors are not so strongly related that their effects cannot be separated.Correlations among the predictors.
Independence of irrelevant alternatives (IIA)The comparison between any two categories does not depend on which other categories are available.Reasoning about whether any two categories are close substitutes. Formal tests exist but are beyond the scope of this course.

The last assumption in Table 4.8 is judged by reasoning rather than by a test in this course: it asks whether any two categories are close substitutes for each other. Expand the first panel below for an example of the independence of irrelevant alternatives and how to judge it, and the second for why the multinomial model needs more data than the ordinal model.

The independence of irrelevant alternatives, explained

The IIA assumption says that the odds of choosing one category over another stay the same whether or not other categories are on offer. A classic illustration involves travel to work. Suppose people choose between a car and a red bus, with even odds. If a blue bus that is identical to the red bus is added, common sense says that the new bus takes riders mainly from the red bus, while the multinomial model assumes that it takes riders evenly from both the car and the red bus. The assumption fails because the two buses are near-perfect substitutes. In the PHAA example, a family doctor, a walk-in clinic, an emergency department and no usual place are distinct kinds of care, so the assumption is reasonable. It would be less reasonable if the categories included two very similar options, such as two walk-in clinics run by the same provider.

The same reasoning can be applied to any outcome by imagining that one category disappeared. If the walk-in clinics in a city closed, the multinomial model assumes that their former users would spread across a family doctor, an emergency department and no usual place in proportion to the existing odds. If most of them would in fact go to the emergency department, because both give care without an appointment, then the walk-in clinic and the emergency department are partly substitutes, and the assumption is doubtful. Judging the assumption therefore means asking, in plain words, whether any two categories are close substitutes for each other.

Why the multinomial model needs more data

The multinomial model estimates a separate set of coefficients for every comparison. In this example, two predictors and three comparisons give six slopes and three intercepts, nine numbers in all (R reports # weights: 16 (9 variable) when trace = TRUE). An ordinal model for an outcome with the same number of categories would estimate two slopes and three cut-points. Each extra number is estimated with less information, so small categories produce wide confidence intervals. The emergency department category, with 55 people, has the widest intervals in this example.

For usual place of care, the categories are distinct kinds of care, although a walk-in clinic and an emergency department may be partly substitutes. The card below links to a narrated walkthrough of multinomial logistic regression in R. Activity 4.3 then fits the model of this section to the PHAA data, reproduces the RRRs in Table 4.6 and the predicted probabilities in Table 4.7, and changes the reference category: run the script alongside the reading and answer the questions from your own output.

Learn to do this in R

Narrated R walkthrough: Multinomial Logistic Regression in R

This walkthrough fits a multinomial logistic regression to the course outcomes data. It chooses a reference category, converts the results to relative risk ratios and calculates predicted probabilities for each category.

Open the Multinomial Logistic Regression in R walkthrough
R Activity 4.3: multinomial logistic regression for usual place of care

Text version of the activity: the code of the run-along script, its console output and notes on reading it.

library(nnet)                           # multinom() fits the multinomial model
phaa <- read.csv("https://heal-learn.ca/r-activities/data/phaa_outcomes.csv")   # course data, read from the website
phaa <- na.omit(phaa)                   # keep the 795 people with no missing values
phaa$smoker <- factor(phaa$smoker, levels = c("No", "Yes"))   # "No" = reference
phaa$usual_care <- relevel(factor(phaa$usual_care), ref = "Family doctor")   # reference category
table(phaa$usual_care, phaa$smoker)     # enough people in every category?
Console output
No Yes Family doctor 399 56 Emergency department 39 16 No usual place 70 25 Walk-in clinic 154 36

The relevel() line makes Family doctor the reference category, so it is listed first and every other category is compared with it; the other categories follow in alphabetical order. The cross-table is the first check: each comparison is estimated separately, so every category needs enough people. Every cell has people in it, and the smallest (16 smokers who name an emergency department) is small but workable. A model with smoking as its only predictor gives a crude RRR of 2.92 for smoking in the emergency department comparison (Worked Example 4.3).

mn <- multinom(usual_care ~ age + smoker, data = phaa, trace = FALSE)
summary(mn)
Console output
Call: multinom(formula = usual_care ~ age + smoker, data = phaa, trace = FALSE) Coefficients: (Intercept) age smokerYes Emergency department -1.52390041 -0.01764088 1.1007138 No usual place 0.04144969 -0.04101336 0.9801218 Walk-in clinic 0.08517528 -0.02306164 0.5441957 Std. Errors: (Intercept) age smokerYes Emergency department 0.5008633 0.010669347 0.3307714 No usual place 0.3875545 0.008856940 0.2792029 Walk-in clinic 0.3057325 0.006581199 0.2362170 Residual Deviance: 1701.721 AIC: 1719.721

Reading the output. The Coefficients block has one row for each comparison with the reference: the Emergency department row is Emergency department versus Family doctor, and so on. Four categories give K − 1 = 3 comparisons, each with its own intercept and its own slopes for age and smoking (nine numbers in all), on the log scale. The Std. Errors block gives a standard error for each coefficient; they are largest for the emergency department, the smallest category. Setting trace = FALSE hides the messages that multinom() otherwise prints while it fits the model.

round(exp(coef(mn)), 2)                 # relative risk ratios
round(exp(confint(mn)), 2)              # 95% CIs, one block per comparison
round(exp(10 * coef(mn)[, "age"]), 2)   # RRRs for ten years of age
Console output
(Intercept) age smokerYes Emergency department 0.22 0.98 3.01 No usual place 1.04 0.96 2.66 Walk-in clinic 1.09 0.98 1.72 , , Emergency department 2.5 % 97.5 % (Intercept) 0.08 0.58 age 0.96 1.00 smokerYes 1.57 5.75 , , No usual place 2.5 % 97.5 % (Intercept) 0.49 2.23 age 0.94 0.98 smokerYes 1.54 4.61 , , Walk-in clinic 2.5 % 97.5 % (Intercept) 0.60 1.98 age 0.96 0.99 smokerYes 1.08 2.74 Emergency department No usual place Walk-in clinic 0.84 0.66 0.79

The first table holds the relative risk ratios, and the three blocks that follow hold their 95% confidence intervals, one block per comparison. For smoking, the RRRs are 3.01 for an emergency department (1.57 to 5.75), 2.66 for no usual place (1.54 to 4.61) and 1.72 for a walk-in clinic (1.08 to 2.74), each compared with a family doctor. Each RRR is a ratio of two ratios: for example, the ratio of emergency department to family doctor is about three times as high for smokers as for non-smokers of the same age. The last line gives the RRRs for ten years of age (0.84, 0.66 and 0.79). R works them out from the unrounded coefficients, so read the ten-year values from this line rather than from the rounded per-year RRRs in the first table.

new_people <- data.frame(age = 30, smoker = c("No", "Yes"))   # a non-smoker and a smoker
round(predict(mn, newdata = new_people, type = "probs"), 2)
Console output
Family doctor Emergency department No usual place Walk-in clinic 1 0.51 0.06 0.15 0.28 2 0.32 0.12 0.26 0.30

Row 1 is a 30-year-old non-smoker and row 2 is a 30-year-old smoker. Each row adds to 1 (apart from rounding), because the predicted probabilities give the overall chance of each category. The smoker's probability of having a family doctor is 0.32, compared with 0.51 for the non-smoker, and the probability of naming an emergency department is 0.12, compared with 0.06.

Files for this activity Data Code Answer key

R Reflect on what you just ran

Answer each question from your own output, as on the final exam: find the number, say what it means, and name both categories in every comparison.

1. How many comparisons does the model make, and what does each one compare? Interpret the relative risk ratio (RRR) for smokerYes in the No usual place row, with its 95% confidence interval, naming both categories. Is age clearly associated with all three comparisons? Explain using the confidence intervals.

Model answerThe model makes three comparisons, each of one category against the reference, family doctor: emergency department, no usual place and walk-in clinic, each compared with family doctor. For smoking in the No usual place row, the RRR is 2.66 (95% CI 1.54 to 4.61). Among people of the same age, the ratio of having no usual place of care to having a family doctor is about 2.7 times as high for smokers as for non-smokers. The interval excludes 1, so the association is statistically significant; the RRR compares no usual place with family doctor only, as a ratio of two ratios, and is not the overall chance of having no usual place. Age is clearly associated with two comparisons: its intervals exclude 1 for a walk-in clinic (0.96 to 0.99) and for no usual place (0.94 to 0.98), so older people are less likely to name a walk-in clinic (RRR 0.79 per ten years) or to have no usual place (RRR 0.66 per ten years), each compared with a family doctor. The interval for the emergency department comparison (0.96 to 1.00) includes 1, so the data do not show a clear age difference for that comparison.

2. A colleague writes: “The RRR of 3.01 shows that smokers are three times as likely as non-smokers to use an emergency department.” Use the predicted probabilities for the two 30-year-olds to correct this statement. Then describe the difference between the two people in a way a health planner could use.

Model answerThe RRR of 3.01 compares an emergency department with a family doctor only: it is a ratio of two ratios, which says that the ratio of emergency department to family doctor is about three times as high for smokers as for non-smokers of the same age. The overall chance of naming an emergency department comes from the predicted probabilities: 0.12 for a 30-year-old smoker against 0.06 for a 30-year-old non-smoker, about twice as high (about 6 percentage points more), not three times. The ratio of two ratios is larger because the smoker is also less likely to name a family doctor (0.32 against 0.51). For a health planner: about one in four 30-year-old smokers (0.26) has no usual place of care, against about 15 in 100 non-smokers (0.15), and only about one in three smokers (0.32) names a family doctor. Predicted probabilities are easier to follow because they give the share of people in each category directly and add to 100%, whereas each RRR compares one category with the reference and takes more explaining.

3. Run your own code: at the end of your script, type and run these four lines, which make Walk-in clinic the reference category and fit the same model again.
phaa$care2 <- relevel(phaa$usual_care, ref = "Walk-in clinic")
mn2 <- multinom(care2 ~ age + smoker, data = phaa, trace = FALSE)
round(exp(coef(mn2)), 2)
AIC(mn, mn2)
What is the same in the two models, and what has changed? Then explain in plain words what the independence of irrelevant alternatives (IIA) assumes, and use walk-in clinics and emergency departments to say why it might not hold here.

Model answerBoth models have an AIC of 1719.721, so the fit is the same, and every person's predicted probabilities are the same too. Only the comparisons that are reported have changed: each row of mn2 now compares a category with walk-in clinic, so its RRRs answer different questions. For smoking, the Family doctor row shows 0.58, the walk-in clinic comparison of the first model (1.72) turned around, and the Emergency department row shows 1.74, the ratio of emergency department to walk-in clinic for smokers compared with non-smokers. The IIA assumption says that the odds of choosing one category over another stay the same whatever other categories are available: if walk-in clinics closed, their users would spread across the other options in proportion to the existing odds. A walk-in clinic and an emergency department may be close substitutes, because both give care without an appointment, so most walk-in users would probably move to an emergency department, and the assumption may not hold.
Saved.

Your output from Activity 4.3 reproduces the relative risk ratios in Table 4.6 and the predicted probabilities in Table 4.7, and the refit with walk-in clinic as the reference shows that only the reported comparisons change. The key takeaways below draw the section together before its knowledge check.

Key Takeaways

  • 5.1 A nominal outcome, such as usual place of care, has categories that are simply different from one another, with no ranking: a family doctor is not "more" than a walk-in clinic. Because there is no scale to move along, each category needs its own relationship with every predictor. Smoking, for example, could raise the chance of using an emergency department and the chance of having no usual place by different amounts. The ordinal model cannot describe this, because it summarises each predictor with a single odds ratio for moving up the scale. When you choose a model, first ask whether the categories have a genuine order; if they do not, the answer is multinomial logistic regression, whatever numbers the categories happen to be stored as.
  • 5.2 The multinomial model picks one category as the reference and compares every other category with it, so an outcome with K categories gives K − 1 comparisons, each with its own intercept and its own slopes. With family doctor as the reference, the four places of care give three comparisons: walk-in clinic, emergency department and no usual place, each compared with family doctor. In R, the reference is set with relevel(), and a good choice is a large group that is a natural point of comparison for the research question. Changing the reference changes which comparisons are reported, but it does not change how well the model fits or its predicted probabilities. In any question, find the reference category first, because every number in the output is read against it.
  • 5.3 You fit the model with multinom() from the nnet package and get relative risk ratios (RRRs) and their intervals from exp(coef(mn)) and exp(confint(mn)), with one row or block for each comparison. An RRR is a ratio of two ratios that belongs to one comparison only: the RRR of 3.01 for smoking in the emergency department row means that the ratio of emergency department to family doctor is about three times as large for smokers as for non-smokers of the same age. Every interpretation should therefore name both categories (for example, "emergency department compared with family doctor") as well as the groups being compared. A confidence interval that excludes 1 shows a clear association for that comparison only, so check each comparison on its own: the age interval for the emergency department comparison (0.96 to 1.00) includes 1, while the age intervals for the other two comparisons do not. For age, a ten-year RRR is easier to describe, and exp(10 * coef(mn)[, "age"]) gives it from the unrounded coefficients.
  • 5.4 Predicted probabilities from predict(mn, newdata = new_people, type = "probs") give the overall chance of each category for the people you choose, and each person's probabilities add to 1. They are often the clearest way to present a multinomial model, because they answer the question readers usually ask: how likely is this kind of person to be in each category? For a 30-year-old smoker, the predicted chance of naming an emergency department is 0.12, twice the 0.06 for a non-smoker of the same age, and the chance of having no usual place rises from 0.15 to 0.26. A common trap is to read an RRR as "times as likely": the RRR of 3.01 compares a ratio of two categories, whereas the overall chance of a category comes from the predicted probabilities (see the callout An RRR Is a Ratio of Two Ratios). If a claim says that one group is "three times as likely" to be in a category, check it against the predicted probabilities before you accept it.
  • 5.5 The multinomial model needs nominal, mutually exclusive categories (each person in exactly one), independent observations, enough people in every category and no strong multicollinearity. Check the numbers with table(outcome, predictor): each comparison is estimated separately, so a small category gives unstable estimates and wide intervals, which is why the emergency department category has the widest intervals in this example. The model also assumes the independence of irrelevant alternatives (IIA): the odds of choosing one category over another stay the same whether or not other categories are on offer. To judge it, imagine that one category disappeared and ask where its members would go; if most of them would move to one particular category, as walk-in clinic users might move to the emergency department, those two categories are close substitutes and the assumption is doubtful. In an answer, explain IIA in plain words first and then apply it to the two categories in the question that look most alike.
Knowledge check: this section

1. A provincial survey asked 1,200 adults for their main source of health information: Family doctor, Pharmacist, Health websites, or Friends and family, stored in the file as 1 to 4. A colleague proposes an ordinal logistic regression, "because the codes give the categories an order and the model needs fewer coefficients". Which response is correct?

How an outcome is stored does not make it ordinal; what the categories mean does. These sources have no natural order, and fewer coefficients are not better when they misdescribe the outcome.
Collapsing into two groups throws away the differences between the other three sources. A model for all four categories keeps that information.
The model is right but the reason is not. Ordered outcomes with more than two categories use an ordinal model; it is the lack of order, not the number of categories, that calls for a multinomial model.
The sources are nominal, so a predictor can shift the chance of each source by a different amount. A multinomial model gives each category its own relationship with every predictor.
The correct response is that the outcome is nominal and needs a multinomial model. The information needed is what the categories mean, not their codes: the four sources are simply different, and none is higher or lower than another. Living in a rural area might, for example, raise the chance of relying on friends and family and the chance of relying on a pharmacist by different amounts, and an ordinal model, which gives each predictor one odds ratio for "moving up the scale", cannot describe that, because there is no scale. The option that names the right model for the wrong reason is tempting, but ordered outcomes with more than two categories, such as self-rated health, are analysed with an ordinal model, so it is the lack of order, not the number of categories, that calls for the multinomial model; collapsing into two groups throws away the differences between the other three sources. (Section 3, 5.1 What Makes an Outcome Nominal?; Objective 5.1)

2. The analyst fitted multinom() twice to the outcome in Question 1, first with Family doctor as the reference category and then with Health websites as the reference. The two models fit the data equally well. Which statement is correct?

With four categories, each model makes K − 1 = 3 comparisons against its own reference. The reference category is the baseline for the comparisons, not an extra comparison.
Changing the reference changes which comparisons are reported, so the relative risk ratios differ, but the fitted model is the same, so the fit and predicted probabilities are unchanged.
Each relative risk ratio belongs to one comparison with the reference. A new reference means new comparisons, so the ratios answer different questions and take different values.
The fitted model is the same whichever reference is used, so predicted probabilities and fit do not change. A good reference is a large, natural point of comparison, not one chosen by fit.
The correct statement is that each model makes K − 1 = 3 comparisons with its own reference category, and that only the comparisons reported change. The information needed is the number of categories (K = 4) and the fact that the two models fit equally well. With Family doctor as the reference, the comparisons are Pharmacist, Health websites and Friends and family, each against Family doctor; with Health websites as the reference, they are the other three sources, each against Health websites, so the relative risk ratios answer different questions and take different values. The fitted model is the same, which is why the fit is identical and the predicted probabilities do not change. The tempting option that keeps the same relative risk ratios forgets that each ratio belongs to one comparison, and a good reference is a large group that is a natural point of comparison, not one chosen by the fit. (Section 3, 5.2 Comparisons With a Reference Category, Figure 4.6 and the paragraph on choosing the reference; Objective 5.2)

3. With Family doctor as the reference, the relative risk ratios (RRRs) for living in a rural area (rural = 1), adjusted for age, were as follows. Which interpretation is correct?

Comparison (versus Family doctor)RRR for rural adults (95% CI)
Pharmacist1.62 (1.15 to 2.28)
Health websites1.10 (0.84 to 1.44)
Friends and family2.40 (1.65 to 3.49)
An RRR compares each category only with the reference, Family doctor, so it is not an overall chance. The Health websites interval also includes 1, so that comparison is not clear.
Each RRR compares one source with the reference, Family doctor. These ratios do not compare two non-reference categories such as friends and family against health websites.
An RRR is a ratio of two ratios: here, how the chance of one source relative to a family doctor differs between rural and urban adults. Each interval is judged on its own against 1.
An estimate above 1 is not enough; each comparison is judged by its interval. The Health websites interval includes 1, so the data are compatible with no difference there.
The correct interpretation names both categories in the comparison and judges each interval on its own. The information needed is the reference category (Family doctor) and the three RRRs with their intervals. An RRR is a ratio of two ratios: here, the ratio P(friends and family) ÷ P(family doctor) is 2.40 times as large for rural as for urban adults of the same age, and its interval (1.65 to 3.49) excludes 1, as does the Pharmacist interval (1.15 to 2.28); the Health websites interval (0.84 to 1.44) includes 1, so the data are compatible with no difference for that comparison. The tempting first option reads the RRR as an overall chance ("2.40 times as likely"), which it is not, because it compares each category only with the reference, and the second option compares two non-reference categories, which these RRRs do not do. (Section 3, 5.3 Interpreting Relative Risk Ratios, Table 4.6 and the callout An RRR Is a Ratio of Two Ratios; Objective 5.3)

4. A colleague writes: "The RRR of 2.40 shows that rural adults are 2.4 times as likely as urban adults to rely on friends and family, and the RRR of 1.10 shows that they are more likely to use health websites." The predicted probabilities for two 45-year-olds are below. Which correction is right?

PersonFamily doctorPharmacistHealth websitesFriends and family
Urban, age 450.480.140.280.10
Rural, age 450.380.180.250.19
RRRs compare each source with a family doctor only, so overall chances come from the predicted probabilities. The website chance can fall even with an RRR above 1, because the family-doctor chance also falls.
The two are not the same comparison. An RRR is a ratio of two ratios against the reference, while predicted probabilities give the overall chance of each category.
An RRR is a ratio, not a difference in percentage points. Changes in the overall chance of each source are read from the predicted probabilities.
An RRR above 1 does not imply a majority. The predicted probabilities show that the family doctor is still the most common source for rural adults.
The correct correction uses the predicted probabilities, which give the overall chance of each category. The information needed is the two rows of probabilities, each of which adds to 1. For friends and family, the predicted probability nearly doubles, from 0.10 to 0.19, so the overall chance is read from these probabilities rather than from the RRR of 2.4; for health websites the probability falls from 0.28 to 0.25 even though the RRR is above 1, because the RRR compares websites with a family doctor, and the chance of a family doctor also falls (0.48 to 0.38). The family doctor is still the most common source for rural adults (0.38 against 0.19 for friends and family), so the option claiming that most rural adults rely on friends and family misreads an RRR above 1 as a majority. (Section 3, 5.3, the callout An RRR Is a Ratio of Two Ratios, and 5.4 Predicted Probabilities, Table 4.7; Objective 5.4)

5. Suppose the survey had split Health websites into two categories, Government health websites and Other health websites, giving five sources in all. Which statement about the independence of irrelevant alternatives (IIA) is correct?

This describes the independence of the observations, a different assumption judged from the study design. IIA concerns how choices among categories depend on which alternatives are available.
IIA assumes that if one category disappeared, its members would spread over the others in proportion to the existing odds. Two kinds of health website are close substitutes, which breaks this.
Mutually exclusive categories are needed too, but they do not settle IIA. The question for IIA is whether any two categories are close substitutes.
This describes multicollinearity among the predictors. IIA is about the outcome categories, specifically whether any two are close substitutes.
The correct statement defines IIA and applies it to the two kinds of website. The information needed is whether any two categories are close substitutes for each other. The multinomial model assumes that if one category disappeared, its members would spread over the remaining categories in proportion to the existing odds; two kinds of website that offer the same kind of information break this, in the same way that a blue bus identical to a red bus takes its riders mainly from the red bus. The tempting first option describes the independence of the observations, a different assumption that is judged from the study design; mutually exclusive categories are needed too but do not settle IIA, and the last option describes multicollinearity. (Section 3, 5.5 Assumptions and the Independence of Irrelevant Alternatives, Table 4.8 and the accordion panel on the independence of irrelevant alternatives; Objective 5.5)

6. A perinatal survey asked 1,400 pregnant people where they planned to give birth (place): Hospital (the reference category), Birth centre or Home. The predictors are rural (1 = lives more than 50 km from a hospital with a maternity unit) and first (1 = a first birth). The last lines of the output are the predicted probabilities for an urban and a rural resident who have given birth before. A colleague writes: "Rural residents are three times as likely as urban residents to plan a home birth, and they are also more likely to plan a birth-centre birth." Which response is correct?

> round(exp(coef(mn)), 2) (Intercept) rural first Birth centre 0.18 1.34 0.86 Home 0.05 2.97 0.51 > round(exp(confint(mn)), 2)["rural", , ] Birth centre Home 2.5 % 0.98 1.82 97.5 % 1.83 4.85 > round(predict(mn, newdata = two_people, type = "probs"), 3) Hospital Birth centre Home urban, not first 0.809 0.149 0.042 rural, not first 0.713 0.176 0.111
An RRR compares one category with the reference only, so it does not give how many times as likely. The birth-centre interval also includes 1, so that comparison is not clear.
Both RRRs compare a category with the reference, Hospital. Neither compares a home birth with a birth centre directly.
An RRR above 1 does not imply a majority. The predicted probabilities show that most rural residents still plan a hospital birth.
Each RRR keeps its own comparison with Hospital, the overall chance of each place comes from the predicted probabilities, and the birth-centre interval including 1 means no clear rural difference there.
The correct response keeps each RRR for its own comparison, uses the predicted probabilities for the overall chance and judges the birth-centre comparison from its interval. The information needed is the reference category (Hospital), the RRRs for rural with their intervals and the two rows of predicted probabilities. An RRR is a ratio of two ratios: 2.97 says that P(home) ÷ P(hospital) is about three times as high for rural as for urban residents with the same birth history, and its interval excludes 1. The overall chance of planning a home birth comes from the predicted probabilities, about 4 in 100 urban residents against about 11 in 100 rural residents, so the colleague's sentence should be written with these chances rather than with the RRR, and a hospital birth remains by far the most likely plan in both rows. The birth-centre RRR of 1.34 is above 1, but its interval includes 1, so it does not show a clear association, and neither RRR compares a home birth with a birth centre directly. (Section 3, 5.3 Interpreting Relative Risk Ratios and the callout An RRR Is a Ratio of Two Ratios, and 5.4 Predicted Probabilities, Table 4.7; Objectives 5.3 and 5.4)
● Complete the knowledge check to continue.
Section 4 of 4

Poisson and Negative Binomial Regression Modelling

⏱ Estimated time: 45 minutes
Lesson 4 · Section 4

Poisson and Negative Binomial Regression Modelling

Two models for outcomes that count how many times something happened.

Count outcomes

What counts look like

  • Counts are whole numbers: 0, 1, 2, 3, and so on.
  • Counts can never be negative.
  • Counts are usually skewed, with many zeros and a few large values.
464
people (58%) with no urgent care visits
0.80
average number of visits per person
The Poisson distribution

One number describes it: the mean

Three Poisson distributions with means 0.8, 3 and 8. With mean 0.8 most counts are 0 or 1; with mean 8 the distribution is centred near 8 and roughly symmetric.
The panels show Poisson distributions with means of 0.8, 3 and 8, and in each one the variance equals the mean.
Poisson regression

A log link and incidence rate ratios

Poisson regression
\[ \ln\big(\color{#0B7B6B}{\text{expected visits}}\big) = \color{#6D28D9}{\beta_0} + \color{#1D4ED8}{\beta_1}\,\text{age} + \color{#1D4ED8}{\beta_2}\,\text{smoker} \qquad \color{#C2410C}{\text{IRR}} = e^{\beta} \]
expected visits the average count β0 intercept β1, β2 slopes on the log scale IRR incidence rate ratio
1.44
IRR for smokers (95% CI 1.19 to 1.73)
1.13
IRR for 10 years of age (1.0126 per year)
Different follow-up times

The offset turns counts into rates

Poisson regression with an offset
\[ \ln\big(\color{#0B7B6B}{\text{expected count}}\big) = \color{#C2410C}{\ln(\text{follow-up time})} + \color{#6D28D9}{\beta_0} + \color{#1D4ED8}{\beta_1}\,\text{age} + \color{#1D4ED8}{\beta_2}\,\text{smoker} \]
ln(follow-up time) the offset, coefficient fixed at 1 expected count over each person's follow-up

glm(gp_visits ~ age + smoker + offset(log(fu_years)), family = poisson)

Use an offset whenever people (or places) are observed for different amounts of time or have different population sizes.

Checking the Poisson model

Is the variance close to the mean?

CheckWhat a good Poisson fit looks likePHAA urgent care visits
Mean and variance of the countsAbout equalMean 0.80, variance 1.76
Dispersion ratioClose to 12.05
Zeros: observed versus expectedAbout equal464 observed, 363 expected

All three checks point to overdispersion: the counts are more spread out than the Poisson model allows.

Why it matters

Overdispersion makes the Poisson model overconfident

Two panels comparing observed counts of urgent care visits with predictions. Panel A, Poisson: 464 zeros observed, 363 predicted, with too many ones predicted. Panel B, negative binomial: 464 zeros observed, 463 predicted, with close agreement across all counts.
The grey bars show the observed counts and the lines show the counts expected by each model; panel A is the Poisson model and panel B is the negative binomial model.
Negative binomial regression

One extra number lets the variance exceed the mean

Variance of a negative binomial count
\[ \text{variance} = \color{#0B7B6B}{\mu} + \frac{\color{#0B7B6B}{\mu}^2}{\color{#C2410C}{\theta}} \]
μ the expected count θ theta: small values mean extra spread
SmokingIRR95% CIp-value
Poisson1.441.19 to 1.730.0001
Negative binomial (θ = 0.77)1.441.08 to 1.910.012
Comparing the two models

Three checks favour the negative binomial model

CheckPoissonNegative binomial
AIC (lower is better)21551954
Dispersion ratio (close to 1 is good)2.050.99
Zeros expected (464 observed)363463

A difference in AIC of 10 or more points is usually taken as strong support for the model with the lower value.

Assumptions and checks

Count models: what to check

AssumptionPoissonNegative binomialHow to check it
Whole-number counts of 0 or moreYesYestable(outcome)
Independent observationsYesYesStudy design
Predictors multiply the expected countYesYesLog link (built in)
Offset if follow-up time differsYesYesoffset(log(time))
Variance equals the meanYesNo (variance can be larger)Dispersion ratio, AIC, zeros
Lesson summary

Outcome type, model and main check

OutcomeModelMain check
ContinuousLinear regressionResidual plots: plot(model)
BinaryLogistic regressionAbout 10 events per predictor
OrdinalOrdinal logistic regressionBrant test: brant(model)
NominalMultinomial logistic regressionPeople in every category; distinct categories
CountPoisson regressionDispersion ratio close to 1
Overdispersed countNegative binomial regressionLower AIC; expected zeros

Overview

This section presents the two standard models for counts, Poisson regression and negative binomial regression. The running example is the number of urgent care visits each PHAA participant made in the past 12 months, a simulated variable added for this lesson. The section describes the features of count data and the Poisson distribution, fits a Poisson regression and interprets its incidence rate ratios, explains when an offset is needed, checks the model for overdispersion, and then fits a negative binomial regression and compares the two models.

Learning Objectives

  • 6.1 Describe the features of count outcomes and the Poisson distribution, including its mean-equals-variance property.
  • 6.2 Fit a Poisson regression in R and interpret its incidence rate ratios (IRRs), including an IRR given for a ten-year difference in age.
  • 6.3 Explain when an offset is needed and how it turns a count model into a rate model.
  • 7.1 Check a Poisson model for overdispersion with the dispersion ratio and the count of zeros, and explain what overdispersion does to its standard errors, confidence intervals and p-values.
  • 7.2 Fit a negative binomial regression in R and choose between the two models with the AIC, the dispersion ratio and the expected zeros.

6.1 Count Outcomes and the Poisson Distribution

A count records how many times an event happened to a person, or in a place, over a period of time. Counts are whole numbers, they cannot be negative, and their distribution is usually skewed to the right, with many zeros and small values and a long tail of larger values. In the PHAA data, the 795 participants made between 0 and 12 urgent care visits in the past year: 464 (58%) made none, 174 made one and 84 made two, and only 4 made eight or more. The average was 0.80 visits per person.

A linear regression of these counts would break several assumptions at once. Its residuals would be skewed (not normal), their spread would grow with the predicted value (unequal variance), and the model could predict a negative number of visits. Figure 4.3 in Section 1, which showed a linear model fitted to urgent_visits, illustrates the first two problems.

Counts therefore need a distribution suited to whole numbers of zero or more, and the Poisson distribution is the one on which Poisson regression is built.

The Poisson distribution describes the number of events in a fixed period when events happen independently of one another at a constant average rate. It is named after the French mathematician Siméon-Denis Poisson. The whole distribution is defined by one number, its mean (written μ, the Greek letter mu), and its most important property is that its variance equals its mean. A Poisson count with a mean of 3 has a variance of 3, and a Poisson count with a mean of 0.8 has a variance of 0.8.

Figure 4.8 shows how the shape of the distribution changes as its mean increases.

Three bar charts of Poisson probabilities for means of 0.8, 3 and 8. With mean 0.8, zero is the most likely count; with mean 3, counts of 2 and 3 are most likely; with mean 8, the distribution is nearly symmetric around 8.
Figure 4.8. The panels show Poisson distributions with means of 0.8, 3 and 8. With a small mean the distribution is piled up at zero, and with a larger mean it moves to the right and becomes more symmetric. In each case the variance equals the mean.

The mean-equals-variance property is what makes the Poisson distribution simple, and it is also what most often goes wrong when it is applied to real health data. The checks for overdispersion in 7.1 are built around it.

Poisson regression, the subject of the next step, uses this distribution to model how the expected count changes with the predictors.

6.2 Poisson Regression and Incidence Rate Ratios

Poisson regression is the GLM with a Poisson distribution and a log link. The log of the expected count is set equal to the linear predictor, as Equation 4.5 shows for urgent care visits with age and smoking as predictors.

Poisson regression for urgent care visits
\[ \ln\big(\color{#0B7B6B}{\mu}\big) = \color{#6D28D9}{\beta_0} + \color{#1D4ED8}{\beta_1}\,\text{age} + \color{#1D4ED8}{\beta_2}\,\text{smoker} \]Eq 4.5
The natural log of the expected number of visits μ equals an intercept plus slopes for age and smoking. Exponentiating both sides gives μ = eβ0 × eβ1age × eβ2smoker, so each predictor multiplies the expected count.

The log link changes how a predictor affects the outcome. In linear regression, a predictor adds a fixed amount to the average outcome. In Poisson regression, because the straight line is drawn on the log scale, a predictor instead multiplies the expected count by a fixed factor. That factor is the exponentiated coefficient eβ, and since it describes how many times larger one expected count is than another, it is a ratio of expected counts, called the incidence rate ratio (IRR). An IRR of 1 means no association, because the expected count is multiplied by 1 and does not change. An IRR above 1 means more events, and an IRR below 1 means fewer events. In the PHAA data, the Poisson model gives an IRR for smoking of 1.44 (95% CI 1.19 to 1.73): smokers make about 44% more urgent care visits than non-smokers of the same age. The IRR for age is 1.013 per year (95% CI 1.007 to 1.018). For ten years of age, exp(10 * coef(pois)["age"]) gives 1.13 from the unrounded coefficient (Activity 4.4), or about 13% more visits for each decade of age. Because the effects multiply, the ten-year IRR is not simply ten times the one-year percentage. Each extra year multiplies the expected count again, so the small yearly increases compound in the way that interest compounds in a savings account. For this reason the ten-year IRR is read from the line that R prints rather than worked out from the per-year value.

The same template reads every IRR. Subtract 1 from the IRR and express the result as a percentage: an IRR of 1.20 means a rate 20% higher, and an IRR of 0.85 means a rate 15% lower. Each of these describes a one-unit difference in the predictor, such as one year of age or being a smoker rather than a non-smoker, with the other predictors held constant. When an IRR is reported for a larger difference, such as ten years of age, it is read in the same way for that larger difference. Some predictors are log-transformed before they enter the model, as in a variable such as the natural log of hours + 1. For these, a one-unit difference on the log scale does not mean one more hour. It means that the original quantity is about 2.7 times as large (e1 ≈ 2.72), so the IRR compares people whose original values differ by that factor rather than by a fixed amount.

Worked Example 4.4 shows the crude rate ratio for smoking that R gives and compares it with the IRR from the model; watch what the intercept and the ratio each describe.

Worked Example 4.4: Crude and Adjusted Rate Ratios

A Poisson model with smoking as its only predictor gives the crude rate ratio, which exp(coef()) prints.

> round(exp(coef(glm(urgent_visits ~ smoker, data = phaa, family = poisson))), 3) (Intercept) smokerYes 0.745 1.454

With smoking as the only predictor, the intercept, 0.745, is the average number of visits among non-smokers (n = 662), and the crude IRR of 1.45 says that the average among smokers (n = 133) is 1.45 times as high: smokers made about 45% more visits. The Poisson model’s IRR of 1.44 is almost the same, because it also adjusts for age, which is only weakly related to smoking in these data.

As Worked Example 4.4 shows, an IRR compares expected counts between groups. The next step shows how the same model is adapted when the length of follow-up differs from person to person.

6.3 Different Follow-Up Times: The Offset

Every PHAA participant reported urgent care visits over the same 12 months, so their counts can be compared directly. Many studies instead follow people for different lengths of time, or count events in places with different population sizes. A person followed for ten years has more time to accumulate visits than a person followed for one year, and a city of a million people has more cases than a town of ten thousand. Comparing raw counts in these situations would be unfair, because a higher count might reflect nothing more than a longer time or a larger population. What we want to compare is the rate, the number of events per unit of time or per person. Poisson regression handles this with an offset. The log of each unit's follow-up time (or population size) is added to the model as an extra term, but unlike a predictor its coefficient is not estimated; it is fixed at 1. Fixing the coefficient at 1 means that the expected count rises in exact proportion to the time observed, so doubling the follow-up time doubles the expected count. In effect, the offset divides each count by its follow-up time, turning the model for counts into a model for rates, such as visits per person-year. This is why the exponentiated coefficients are called incidence rate ratios (Frome, 1983).

Two consequences of the offset are worth stating plainly. First, a model with an offset describes a rate, so the expected number of events for a person is that rate multiplied by the time observed: a person followed for six months is expected to have half as many visits as an identical person followed for a year. Second, leaving the offset out can change a comparison completely. If one group is followed for much less time than another, it can have fewer events in total even though its events happen more often per year. Without the offset, the model compares the totals and the group looks like a light user of care; with the offset, it compares the rates and shows the group's true, higher rate. An offset is not needed when every person's count covers the same period, as in the urgent care example.

Activity 4.4, at the end of this section, fits a Poisson model with offset(log(fu_years)) to the PHAA follow-up file, in which the length of follow-up differs from person to person, and shows how its IRRs are then read as ratios of rates.

An offset accounts for differences in follow-up time or population size. The next step is the main check of a Poisson model, which concerns its assumption that the variance equals the mean.

7.1 Checking the Poisson Model for Overdispersion

The Poisson model assumes that the variance of the counts equals their mean, after the predictors are taken into account. When the variance is larger than the mean, the data are overdispersed. Overdispersion is common in health data, because people differ in ways the predictors do not capture: some people use health care much more than others of the same age and smoking status. Three checks reveal it.

Table 4.9 sets out the three checks, with the result of each for the PHAA data.

Table 4.9. Three checks for overdispersion in a Poisson model, with the results for urgent care visits in the PHAA data.

CheckHow R gives itRule of thumbPHAA result
Mean and variance of the countsmean(y) and var(y)A variance much larger than the mean is a warning sign (a first look only, because it ignores the predictors).Mean 0.80, variance 1.76
Dispersion ratiosum(residuals(model, type = "pearson")^2) / df.residual(model): the sum of squared Pearson residuals ÷ the residual degrees of freedomClose to 1 supports the Poisson model; clearly above 1 (for example, above about 1.5) signals overdispersion.2.05
Observed and expected zerossum(y == 0) and sum(dpois(0, fitted(model)))The two numbers should be similar.464 observed, 363 expected

All three checks point to overdispersion. The variance of 1.76 is more than twice the mean of 0.80, the dispersion ratio of 2.05 says that the residuals vary about twice as much as the Poisson model expects, and there are about 100 more people with no visits than the model predicts. The consequence is that the Poisson model is overconfident. The model calculates its standard errors from the variance it assumes, and it assumes a smaller variance than the data actually have, so it believes its estimates are more precise than they really are. As a result its standard errors are too small, its confidence intervals are too narrow and its p-values are too small. Notice that the estimates themselves, such as the IRR for smoking, are not necessarily wrong; it is the stated certainty around them that is wrong. An analysis that ignored the problem could therefore report an association as more certain than the data justify, or call an association statistically significant when it is not.

Figure 4.9 compares the observed numbers of people with each count of visits with the numbers expected by the Poisson model and by the negative binomial model introduced in 7.2.

Two panels comparing observed counts of urgent care visits with model predictions. Panel A shows the Poisson model predicting 363 zeros against 464 observed and too many people with one visit. Panel B shows the negative binomial model predicting 463 zeros and matching the observed bars closely.
Figure 4.9. The grey bars show the observed numbers of people with each count of urgent care visits, and the lines show the numbers expected by each model. The Poisson model (panel A) expects too few zeros, too many ones and almost no counts above four. The negative binomial model (panel B) matches the observed counts closely.

Before the Poisson model is replaced, one source of apparent overdispersion should be ruled out, as the caution below explains.

Apparent Overdispersion

Sometimes a Poisson model looks overdispersed because the model itself is incomplete: an important predictor is missing, or an offset for follow-up time has been left out. Before switching to a negative binomial model, it is worth asking whether the model includes the predictors and the offset that the study design calls for.

In the PHAA data every count covers the same 12 months, so a missing offset does not explain the extra spread. When the model includes the predictors and offset that it needs and the checks still show overdispersion, a model that allows the variance to exceed the mean is required, and the next step introduces it.

7.2 Negative Binomial Regression and Choosing Between the Models

Negative binomial regression keeps the log link and the IRR interpretation of Poisson regression and adds one extra parameter, θ (theta), that allows the variance to exceed the mean. The variance of a negative binomial count is μ + μ²/θ. The first part of this expression, μ, is the Poisson variance, and the second part, μ²/θ, is the extra variation that the Poisson model left out. Because θ sits underneath the extra term, the two move in opposite directions. A small θ makes the extra term large, which means a lot of extra variation. As θ becomes very large, the extra term shrinks toward zero, the variance returns to μ, and the model becomes a Poisson model. The negative binomial model can therefore be thought of as a Poisson model with an adjustable allowance for extra spread, which it estimates from the data (Hilbe, 2011). In R, the model is fitted with glm.nb() from the MASS package, and the output reports θ as Theta.

For the urgent care visits, θ is 0.77. The negative binomial model gives an IRR for smoking of 1.44 (95% CI 1.08 to 1.91), almost the same point estimate as the Poisson model. The confidence interval, however, is wider (it was 1.19 to 1.73 under the Poisson model), and the p-value rises from 0.0001 to 0.012. The IRR for age is 1.012 per year (95% CI 1.004 to 1.020). The associations remain, and the negative binomial model reports them with appropriate uncertainty.

Table 4.10 sets the results of the two models side by side.

Table 4.10. Results of the Poisson and negative binomial models for urgent care visits.

ResultPoissonNegative binomial
IRR for smoking (95% CI)1.44 (1.19 to 1.73)1.44 (1.08 to 1.91)
p-value for smoking0.00010.012
IRR per year of age (95% CI)1.013 (1.007 to 1.018)1.012 (1.004 to 1.020)
AIC (lower is better)2154.91954.3
Dispersion ratio2.050.99
Expected zeros (464 observed)363463

The comparison favours the negative binomial model on every check. The AIC (Akaike information criterion) measures how well a model fits the data, with a penalty for each parameter it estimates. The penalty matters because a model with more parameters will almost always fit a little better simply because it is more flexible, so the AIC asks whether the better fit is large enough to justify the extra complexity. A lower value is better. Here the negative binomial model estimates one more parameter than the Poisson model (θ), and the AIC shows whether that addition earns its place. A difference of about 10 points or more is usually taken as strong support for the model with the lower AIC (Burnham & Anderson, 2004), and here the negative binomial AIC is lower by far more than that (1954.3 against 2154.9). The dispersion ratio of the negative binomial model is 0.99, and it expects 463 zeros against the 464 observed.

The negative binomial model fits these counts well, but some data have even more zeros. Expand the panel below for the models used when the counts contain many more zeros than even a negative binomial model expects.

When even the negative binomial model has too few zeros

In some data the number of zeros is much larger than even a negative binomial model expects. This often happens when part of the population cannot have the event at all, for example people who never use a particular service. Zero-inflated and hurdle models handle this situation by combining a model for "any events versus none" with a model for the number of events. They are fitted with the pscl package and are beyond the scope of this lesson. In the PHAA example, the negative binomial model already predicts the zeros well, so no further model is needed.

The two count models share most of their assumptions. Table 4.11 lists the assumptions of the Poisson and negative binomial models, whether each model requires them and how each is checked; the two models differ only in the assumption about the variance.

Table 4.11. The assumptions of the Poisson and negative binomial models and how each is checked.

AssumptionPoissonNegative binomialHow to check it
The outcome is a count (whole numbers of 0 or more)RequiredRequiredtable(outcome) or summary(outcome)
Independent observationsRequiredRequiredJudged from the study design
Each predictor multiplies the expected count (log link)RequiredRequiredBuilt into the model; for a continuous predictor, a squared term can test for curvature
Different follow-up times are accounted forOffset neededOffset neededoffset(log(time)) in the formula
The variance equals the meanRequiredRelaxed: variance may be largerDispersion ratio; observed versus expected zeros; AIC comparison

With the count models complete, the five types of outcome in this lesson can be set side by side.

Additional Context

This summary is background that draws the lesson together rather than a separate objective. The four sections of this lesson apply the same approach to five types of outcome. The type of the outcome is identified first, and it points to a model. The model is fitted with the same linear predictor (here, age and smoking), its exponentiated coefficients are read as the ratio that its link function implies, and its own assumptions are checked before the results are reported.

Table 4.12 summarises the five PHAA examples, with the model, the effect of smoking and the main check for each.

Table 4.12. The five types of outcome in the PHAA examples, with the model and R function, the effect of smoking (95% CI) and the main check for each.

Outcome type (PHAA example)Model and R functionEffect of smokingMain check
Continuous (systolic blood pressure)Linear, lm()+6.06 mmHg (4.33 to 7.79)Residual plots
Binary (hypertension)Logistic, glm(family = binomial)OR 2.65 (1.04 to 6.30)Events per predictor
Ordinal (self-rated health)Ordinal logistic, polr()OR 0.50 for a higher category (0.36 to 0.70)Brant test
Nominal (usual place of care)Multinomial logistic, multinom()RRR 3.01 for emergency department versus family doctor (1.57 to 5.75)People per category; IIA
Count (urgent care visits)Negative binomial, glm.nb()IRR 1.44 (1.08 to 1.91)Dispersion ratio, AIC, zeros

The card below links to a narrated walkthrough of count models in R. Activity 4.4, after the card, fits the Poisson model for urgent care visits, adds an offset for the follow-up data, runs the overdispersion checks in Table 4.9 and fits the negative binomial model to reproduce the comparison in Table 4.10: run the script alongside the reading and answer the questions from your own output.

Learn to do this in R

Narrated R walkthrough: Poisson and Negative Binomial Regression in R

This walkthrough models a count outcome. It compares the mean and the variance of the counts, fits a Poisson regression and reads its rate ratios, checks for overdispersion, fits a negative binomial regression and compares the two models.

Open the Poisson and Negative Binomial Regression in R walkthrough
R Activity 4.4: Poisson and negative binomial regression for counts

Text version of the activity: the code of the run-along script, its console output and notes on reading it.

library(MASS)                           # glm.nb() fits the negative binomial model (part 5)
phaa <- read.csv("https://heal-learn.ca/r-activities/data/phaa_outcomes.csv")   # course data, read from the website
phaa <- na.omit(phaa)                   # keep the 795 people with no missing values
phaa$smoker <- factor(phaa$smoker, levels = c("No", "Yes"))   # "No" = reference
table(phaa$urgent_visits)    # how many people had 0, 1, 2, ... visits
mean(phaa$urgent_visits)     # the average count
var(phaa$urgent_visits)      # the variance (spread) of the counts
Console output
0 1 2 3 4 5 6 8 9 10 12 464 174 84 38 17 10 4 1 1 1 1 [1] 0.8012579 [1] 1.75894

The table shows the shape of a typical count: 464 people with no visits, 174 with one visit and a long tail up to 12 visits. The mean (0.80) and the variance (1.76) give a first warning, because a Poisson count would have a variance close to its mean. It is only a first look, because it ignores the predictors.

pois <- glm(urgent_visits ~ age + smoker, data = phaa, family = poisson)
summary(pois)
exp(cbind(IRR = coef(pois), confint(pois)))   # IRRs with 95% CIs
exp(10 * coef(pois)["age"])                   # IRR for ten years of age
Console output
Call: glm(formula = urgent_visits ~ age + smoker, family = poisson, data = phaa) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -0.873914 0.143284 -6.099 1.07e-09 *** age 0.012522 0.002871 4.361 1.29e-05 *** smokerYes 0.365671 0.094766 3.859 0.000114 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 (Dispersion parameter for poisson family taken to be 1) Null deviance: 1379.7 on 794 degrees of freedom Residual deviance: 1346.2 on 792 degrees of freedom AIC: 2154.9 Number of Fisher Scoring iterations: 6 Waiting for profiling to be done... IRR 2.5 % 97.5 % (Intercept) 0.4173148 0.3143328 0.5512326 age 1.0126011 1.0069141 1.0183125 smokerYes 1.4414811 1.1931932 1.7304884 age 1.133402

Reading the output. The Estimate column is on the log scale, so the third line exponentiates it to give incidence rate ratios. The IRR for smoking is 1.44 (95% CI 1.19 to 1.73): smokers make about 44% more urgent care visits than non-smokers of the same age. The IRR for age is 1.013 per year (95% CI 1.007 to 1.018), and the last line gives the IRR for ten years of age from the unrounded coefficient, 1.13, or about 13% more visits for each decade of age. The line (Dispersion parameter for poisson family taken to be 1) is a reminder that the model assumes that the variance equals the mean.

fu <- read.csv("https://heal-learn.ca/r-activities/data/phaa_followup.csv")   # course data, read from the website
fu$smoker <- factor(fu$smoker, levels = c("No", "Yes"))   # GP visits over 0 to 10 years
gp <- glm(gp_visits ~ age + smoker + offset(log(fu_years)), data = fu, family = poisson)
round(exp(cbind(IRR = coef(gp), confint(gp))), 3)
Console output
Waiting for profiling to be done... IRR 2.5 % 97.5 % (Intercept) 0.685 0.632 0.741 age 1.018 1.017 1.020 smokerYes 1.235 1.170 1.301

The PHAA follow-up file (phaa_followup.csv) records the number of GP visits each participant made during follow-up, which ranges from a few days to ten years (fu_years). Because follow-up time differs, the model needs offset(log(fu_years)). With the offset in place, the IRRs compare rates of GP visits per year of follow-up. Smokers have a GP visit rate 1.23 times that of non-smokers of the same age (95% CI 1.17 to 1.30), and the rate rises by about 1.8% for each year of age. The intercept (0.685) is the visit rate per year for a non-smoker aged 0 and is not interpreted. Without the offset, a person followed for ten years would appear to use far more care than a person followed for one year, simply because of the extra time.

sum(residuals(pois, type = "pearson")^2) / df.residual(pois)   # dispersion ratio
sum(phaa$urgent_visits == 0)                                   # zeros observed
sum(dpois(0, fitted(pois)))                                    # zeros expected
Console output
[1] 2.052913 [1] 464 [1] 362.7775

The dispersion ratio is 2.05, about twice the value of 1 that a Poisson model assumes. The data contain 464 people with zero visits, but the Poisson model expects only about 363. Both checks show overdispersion, so the confidence intervals from this model are too narrow and its p-values are too small.

nb <- glm.nb(urgent_visits ~ age + smoker, data = phaa)
summary(nb)
exp(cbind(IRR = coef(nb), confint(nb)))       # IRRs with 95% CIs
sum(dnbinom(0, mu = fitted(nb), size = nb$theta))   # zeros expected by NB
Console output
Call: glm.nb(formula = urgent_visits ~ age + smoker, data = phaa, init.theta = 0.7652230036, link = log) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -0.831728 0.202977 -4.098 4.17e-05 *** age 0.011626 0.004175 2.785 0.00536 ** smokerYes 0.362850 0.144744 2.507 0.01218 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 (Dispersion parameter for Negative Binomial(0.7652) family taken to be 1) Null deviance: 729.42 on 794 degrees of freedom Residual deviance: 714.24 on 792 degrees of freedom AIC: 1954.3 Number of Fisher Scoring iterations: 1 Theta: 0.7652 Std. Err.: 0.0981 2 x log-likelihood: -1946.2840 Waiting for profiling to be done... IRR 2.5 % 97.5 % (Intercept) 0.4352965 0.2953335 0.6396434 age 1.0116936 1.0037461 1.0197705 smokerYes 1.4374195 1.0837566 1.9120698 [1] 463.4569

Reading the output. The coefficients look much like those of the Poisson model, but their standard errors are larger (0.145 for smoking, compared with 0.095). Theta (0.77) is the extra parameter that lets the variance exceed the mean. The IRR for smoking is 1.44 (95% CI 1.08 to 1.91), and its p-value is 0.012, compared with 0.0001 under the Poisson model. The last line shows that the negative binomial model expects about 463 zeros, against the 464 observed. Question 3 asks you to finish the comparison yourself with AIC(pois, nb) and the dispersion ratio of nb.

Files for this activity Data Follow-up data Code Answer key

R Reflect on what you just ran

Answer each question from your own output, as on the final exam: find the number, say what it means, judge the check.

1. The urgent care counts all cover the same 12 months, but the GP visits in fu were counted over follow-up times from a few days to ten years. What does offset(log(fu_years)) do in the model gp, why is it needed there but not in pois, and what do the incidence rate ratios (IRRs) from gp therefore compare? Interpret the IRR for smokerYes from gp, with its 95% confidence interval.

Model answerEvery PHAA participant reported urgent care visits over the same 12 months, so those counts can be compared directly and need no offset, but the GP visits in fu were counted over follow-up times from a few days to ten years. The offset adds the log of each person’s follow-up time to the model with its coefficient fixed at 1, which turns the model for counts into a model for rates, GP visits per year of follow-up. Without it, a person followed for ten years would appear to use far more care than a person followed for one year, simply because of the extra time; with it, a person’s expected number of visits is the rate multiplied by the time observed. The IRRs therefore compare visit rates, not total visits, between people who differ by one unit of a predictor, with the other predictors held constant. The IRR for smoking is 1.23 (95% CI 1.17 to 1.30): smokers have a GP visit rate about 1.23 times (23% higher than) that of non-smokers of the same age, and the interval excludes 1.

2. Is the Poisson model pois adequate? Use the dispersion ratio and the observed and expected numbers of zeros. A colleague argues that the overdispersion does not matter, because the IRR for smoking is clearly above 1. Do you agree? Explain what overdispersion does to the standard errors, confidence intervals and p-values.

Model answerNo: the dispersion ratio is 2.05, about twice the value of 1 that a Poisson model assumes and well above the rough guide of about 1.5, so the counts are overdispersed. The data have 464 people with no visits, but the Poisson model expects only about 363 (Figure 4.9), a second sign of more variation than the model allows. Every count covers the same 12 months, so a missing offset does not explain the extra spread (the "Apparent Overdispersion" caution in 7.1). I disagree with the colleague: the IRR of 1.44 may be a reasonable estimate, but because the Poisson model assumes too little variation, its standard errors are too small, its confidence intervals too narrow and its p-values too small. The model is overconfident and can make an association look more certain than it is, so a model that lets the variance exceed the mean, such as negative binomial regression, is needed to report the uncertainty correctly.

3. Run your own code: at the end of the script, type AIC(pois, nb) and run it, then type sum(residuals(nb, type = "pearson")^2) / df.residual(nb) (line 28 with pois changed to nb) and run it. Which model would you report? Justify your choice with the three checks (AIC, dispersion ratio and expected zeros). Then compare the IRR for smoking and its 95% confidence interval in the two models, and say what the difference means for the conclusions.

Model answerReport the negative binomial model: its AIC is 1954.3 against 2154.9 for the Poisson model, lower by far more than the 10 points usually taken as strong support. Its dispersion ratio is 0.99, close to 1 (the Poisson ratio was 2.05), and it expects about 463 zeros against the 464 observed (the Poisson model expected 363). The IRR for smoking is 1.44 in both models, but the 95% CI widens from 1.19 to 1.73 under the Poisson model to 1.08 to 1.91 under the negative binomial model, because the standard error rises from 0.095 to 0.145 (and the p-value from 0.0001 to 0.012). The negative binomial model’s extra parameter, theta, lets the variance exceed the mean, so the association remains but is reported with more honest uncertainty; the Poisson interval was too narrow. In a results section: “In a negative binomial regression adjusted for age, smokers made 1.44 times as many urgent care visits in the past year as non-smokers (IRR 1.44, 95% CI 1.08 to 1.91).”
Saved.

Your output from Activity 4.4 reproduces the overdispersion checks in Table 4.9 and the model comparison in Table 4.10, and shows how an offset turns counts into rates. The key takeaways below draw the section together before its knowledge check.

Key Takeaways

  • 6.1 A count records how many times something happened over a period, so it is a whole number of zero or more, and it is usually skewed to the right, with many zeros and a long tail (464 of the 795 PHAA participants made no urgent care visits). The Poisson distribution describes counts of this kind and is defined by a single number, its mean μ. Its key property is that its variance equals its mean, so a Poisson count with a mean of 0.8 should have a variance of about 0.8. When you are given a count, look first at table(y), mean(y) and var(y): a variance much larger than the mean is an early warning that the Poisson model may not fit, although it is only a first look, because it ignores the predictors.
  • 6.2 Poisson regression is the GLM with a Poisson distribution and a log link, fitted with glm(urgent_visits ~ age + smoker, data = phaa, family = poisson), and each predictor multiplies the expected count. The exponentiated coefficients from exp(cbind(IRR = coef(pois), confint(pois))) are incidence rate ratios (IRRs), on which 1 means no association, a value above 1 means more events and a value below 1 means fewer. Use one template for every IRR: an IRR of 1.44 means a rate 44% higher, and an IRR of 0.85 means a rate 15% lower, for a one-unit difference in the predictor with the other predictors held constant. When an IRR is given for a larger difference, such as ten years of age, read it for that difference: exp(10 * coef(pois)["age"]) gives it from the unrounded coefficient as 1.13, or about 13% more visits per decade. If a predictor has been log-transformed, one unit on its log scale means that the original value is about 2.7 times as large (e1 ≈ 2.72), so its IRR compares people whose original values differ by that factor. Finish every interpretation by naming the comparison group, the variables held constant and the confidence interval.
  • 6.3 An offset is needed when people (or places) are observed for different lengths of time or have different population sizes, because a person followed for ten years has more time to accumulate events than a person followed for one. It is the log of each unit's follow-up time, added to the model with its coefficient fixed at 1, and it is written as offset(log(fu_years)) in the model formula. With the offset in place, the model describes rates, such as visits per person-year, so the IRRs compare rates rather than total counts, and a person's expected number of events is that rate multiplied by the time they were observed. Leaving the offset out can distort or even reverse a comparison, because a group followed for less time can have fewer events in total even though its events happen more often per year. In any question, check whether everyone was observed for the same period: if they were (as with urgent care visits over the same 12 months), no offset is needed.
  • 7.1 The Poisson model assumes that the variance equals the mean once the predictors are taken into account, and overdispersion, a variance larger than the mean, is common in health data because people differ in ways the predictors do not capture. Two checks after fitting tell you whether it is present. The dispersion ratio, sum(residuals(pois, type = "pearson")^2) / df.residual(pois), should be close to 1, and a value clearly above 1 (above about 1.5) signals overdispersion; the observed zeros, sum(y == 0), should also be close to the zeros the model expects, sum(dpois(0, fitted(pois))). In the PHAA data, a ratio of 2.05 and 464 observed zeros against 363 expected both point to overdispersion, which makes the Poisson model overconfident: its standard errors are too small, its confidence intervals too narrow and its p-values too small, even when the IRR itself looks reasonable. Before you switch models, rule out apparent overdispersion caused by a missing predictor or a missing offset (see the callout Apparent Overdispersion).
  • 7.2 Negative binomial regression, fitted with glm.nb() from the MASS package, keeps the log link and the IRR interpretation and adds one parameter, theta (θ), that lets the variance exceed the mean; a small theta means a lot of extra variation. It usually gives IRRs close to the Poisson ones with larger standard errors and wider confidence intervals, as for smoking in the PHAA data (an IRR of 1.44 in both models, with intervals of 1.19 to 1.73 and 1.08 to 1.91). Choose between the two models with three checks: the AIC from AIC(pois, nb), where lower is better and a difference of about 10 points or more is strong support, provided both models are fitted to the same people; a dispersion ratio close to 1; and expected zeros that match the observed zeros. When you justify your choice, quote the numbers for all three checks, and remember that the change you should expect is in the uncertainty, not in the size of the IRR.
Knowledge check: this section

1. A falls-prevention study recorded the number of falls that each of 900 adults aged 65 and over had in the same 12 months. Of the 900, 520 (58%) had no falls and the largest count was 10; the mean was 0.83 and the variance was 1.94. Which statement is correct?

Falls are counts, and for a Poisson count the variance equals the mean. A variance well above the mean is a first warning of overdispersion, confirmed with the checks after the predictors are added.
An average that is not a whole number does not make a count continuous. Each person's number of falls is still a whole number of 0 or more.
A Poisson distribution with a small mean is itself piled up at zero and skewed, as Figure 4.8 shows. Many zeros alone do not rule out a Poisson model.
The raw variance and mean ignore the predictors, so they are only a first look. Overdispersion is confirmed with the dispersion ratio and the observed and expected zeros after fitting, not proved in advance.
The correct statement describes the counts and compares their variance with the Poisson property that the variance equals the mean. The information needed is the shape of the counts (58% zeros and a long tail up to 10) and their mean and variance. For a Poisson count the variance equals the mean, so with a mean of 0.83 the variance should be about 0.83; the observed 1.94 is more than twice as large, which is a warning sign. It is only a first look, because it ignores the predictors, so it is confirmed with the dispersion ratio and the observed and expected zeros after the model is fitted, which is why the option claiming the Poisson model is "proved" wrong goes too far. A Poisson distribution with a small mean is itself piled up at zero and skewed (Figure 4.8), so zeros alone do not rule it out, and an average that is not a whole number does not make a count continuous. (Section 4, 6.1 Count Outcomes and the Poisson Distribution, Figure 4.8, and 7.1 Checking the Poisson Model for Overdispersion, Table 4.9; Objective 6.1)

2. A Poisson regression of the number of falls gave the incidence rate ratios (IRRs) below, where lives_alone is 1 for adults living alone, exercise is 1 for adults who attend a weekly exercise class and age is in years. The last two lines give the IRR for a ten-year difference in age, which R calculates from the unrounded coefficient. Which interpretation is correct?

> exp(cbind(IRR = coef(pois), confint(pois)))[-1, ] IRR 2.5 % 97.5 % lives_alone 1.28 1.12 1.46 exercise 0.78 0.67 0.91 age 1.03 1.02 1.04 > round(exp(10 * coef(pois)["age"]), 2) age 1.34 > round(exp(10 * confint(pois)["age", ]), 2) 2.5 % 97.5 % 1.22 1.48
An IRR is a ratio, a multiplier of the expected number of falls, not a difference in falls per year.
An IRR is neither a proportion of people who fell nor an odds ratio. It multiplies the expected number of falls.
Each IRR multiplies the expected number of falls for the difference it is given for, with the other predictors held constant, so values below 1 mean fewer falls and above 1 mean more.
IRRs multiply rather than add, so the ten-year value cannot be found by scaling the per-year percentage. R computes it from the unrounded coefficient, which is why it differs from this reading.
The correct interpretation reads each IRR as a multiplier of the expected number of falls, for the difference that the IRR is given for. The information needed is the IRR for exercise (0.78, 95% CI 0.67 to 0.91) and the ten-year IRR (1.34, 95% CI 1.22 to 1.48); everyone was followed for the same 12 months, so the IRRs compare expected numbers of falls in a year. An IRR of 0.78 means 0.78 times as many falls, or 22% fewer, and the ten-year IRR of 1.34 means 34% more falls, each with the other predictors held constant, and both intervals exclude 1. The tempting last option multiplies 3% by 10, but IRRs multiply rather than add, which is why the ten-year value that R gives, exp(10 * coef(pois)["age"]), is 1.34 rather than 1.30. IRRs are ratios, not differences in the number of falls, and they are neither proportions nor odds ratios. (Section 4, 6.2 Poisson Regression and Incidence Rate Ratios, Eq 4.5 and the paragraph on reading any IRR; Objective 6.2)

3. A home-care program counts each client's emergency department visits while enrolled. New clients (n = 180) were enrolled for 4 months on average and made 0.9 visits; other clients (n = 620) were enrolled for 12 months and made 1.5 visits. A Poisson model without an offset gives an IRR for new clients of 0.60 (95% CI 0.50 to 0.72); with offset(log(months)) it gives 1.80 (95% CI 1.50 to 2.16). Why do the two models disagree, and which one shows how often each group uses the emergency department?

Without an offset, the model compares total visits, and new clients had much less time to make them. The offset does not inflate anything; it turns the comparison into one of rates.
The offset does not drop anyone. It adds each client's log follow-up time with its coefficient fixed at 1, keeping all clients in the model.
A missing offset can make counts look overdispersed, but a negative binomial model without the offset would still compare total visits rather than rates.
Without an offset the model compares totals, which penalises clients enrolled for less time. With offset(log(months)) it compares visits per month enrolled, which is the question of how often each group uses the emergency department.
The correct answer is that the offset changes the comparison from total counts to rates, and the rate comparison is the one that answers the question. The information needed is how long each group was enrolled and what each model compares. Without the offset, the IRR of 0.60 compares total visits, so new clients look like light users only because they were enrolled for about 4 months rather than 12; with offset(log(months)), the IRR of 1.80 compares visits per month enrolled, which shows that new clients use the emergency department more often. A person's expected count is then the rate multiplied by the time observed, and the offset does not drop anyone: it adds each person's log follow-up time with its coefficient fixed at 1. A missing offset can make counts look overdispersed (the callout Apparent Overdispersion), but a negative binomial model without the offset would still compare totals. (Section 4, 6.3 Different Follow-Up Times: The Offset, the paragraph on the two consequences of the offset, and question 1 of Activity 4.4; Objective 6.3)

4. The Poisson model of falls from Question 2 was checked with the output below. Which conclusion is correct?

> sum(residuals(pois, type = "pearson")^2) / df.residual(pois) [1] 2.10 > sum(dat$falls == 0) [1] 520 > sum(dpois(0, fitted(pois))) [1] 415.3
The dispersion ratio should be close to 1 for a Poisson model, not close to the raw variance. A ratio near 2 and far fewer expected than observed zeros both signal overdispersion.
A dispersion ratio well above 1 and too few expected zeros show overdispersion, so the Poisson model's uncertainty is understated. With equal follow-up for everyone, a missing offset is not the cause.
This reverses the direction. The Poisson model assumes a smaller variance than the data have, so its standard errors and intervals are too small, not too large.
Many zeros do not make the outcome binary. Turning counts into fell or did not fall would throw away how many times people fell.
The correct conclusion is that the counts are overdispersed and the Poisson model is overconfident. The information needed is the dispersion ratio (close to 1 supports the Poisson model, and a value above about 1.5 signals overdispersion) and the observed and expected zeros, which should be similar. Here 2.10 is about twice the assumed value of 1, and the model expects far fewer zeros (415) than the 520 observed; because the Poisson model assumes a smaller variance than the data have, its standard errors, confidence intervals and p-values are all too small, so associations look more certain than they are. The callout Apparent Overdispersion asks first whether an offset or an important predictor is missing, and no offset is needed here, because every count covers the same 12 months. The tempting option that calls the intervals too wide reverses the direction of the problem, and turning the counts into a binary outcome would throw away how many times people fell. (Section 4, 7.1 Checking the Poisson Model for Overdispersion, Table 4.9 and the callout Apparent Overdispersion; Objective 7.1)

5. A negative binomial model was fitted to the same falls data, with the results below. Which model should be reported, and why?

ResultPoissonNegative binomial
IRR for exercise (95% CI)0.78 (0.67 to 0.91)0.79 (0.63 to 0.99)
p-value for exercise0.0010.04
AIC2410.62236.2
Dispersion ratio2.101.03
Expected zeros (520 observed)415517
The Poisson interval is narrower only because the model wrongly assumes the variance equals the mean. Its precision is overstated, not real.
For AIC, lower is better. The Poisson model's higher AIC shows a poorer fit, not more variation explained.
The three checks agree: a much lower AIC, a dispersion ratio close to 1 and expected zeros matching those observed. The IRR barely changes, but the wider interval reflects the real uncertainty.
Overdispersion mainly affects the uncertainty, not the estimate, so a near-identical IRR is expected. The reason to prefer the negative binomial model is its fit and honest interval, not a corrected bias.
The correct answer is the negative binomial model, chosen with the three checks. The information needed is the AIC of each model (lower is better, and a difference of about 10 points or more is strong support), the dispersion ratios and the expected zeros. The negative binomial AIC (2236.2) is lower than the Poisson AIC (2410.6) by far more than 10 points, its dispersion ratio of 1.03 is close to 1, and it expects 517 zeros against the 520 observed. The IRRs are almost identical (0.78 and 0.79), as is usual, so the important change is the wider interval (0.63 to 0.99) and larger p-value (0.04), which reflect the extra variation that the parameter theta allows. The tempting first option treats the Poisson interval as more precise, but it is narrower only because the Poisson model wrongly assumes that the variance equals the mean. (Section 4, 7.2 Negative Binomial Regression and Choosing Between the Models, Table 4.10; Objective 7.2)

6. A city health unit counted paramedic calls for suspected opioid overdose in each of its 60 neighbourhoods over the same year. The neighbourhoods have between 3,100 and 24,400 residents (pop). The predictors are income10 (median household income per $10,000) and shelter (1 = the neighbourhood has an emergency shelter). A colleague says: "Every neighbourhood was observed for the same year, so the offset can be left out." Which response is correct?

> nb <- glm.nb(calls ~ income10 + shelter + offset(log(pop)), data = nbhd) > exp(cbind(IRR = coef(nb), confint(nb)))[-1, ] IRR 2.5 % 97.5 % income10 0.7534887 0.7048155 0.8045235 shelter 2.1683807 1.3553041 3.5780672
An offset is needed whenever the counts come from different amounts of exposure, whether time or population size. Neighbourhoods of very different sizes have different numbers of calls at the same rate.
offset(log(pop)) adds the log of each population with its coefficient fixed at 1, so the model compares call rates per resident, and each IRR is a ratio of rates.
The offset is needed, but an IRR is a ratio of rates, not a difference in the number of calls.
A negative binomial model allows extra variation but still compares total calls unless the offset is included. It does not replace the offset.
The correct response explains that the offset here allows for population size rather than time, and reads the IRRs as ratios of rates. The information needed is the range of neighbourhood sizes and the term offset(log(pop)). A neighbourhood of 24,400 people would have more calls than one of 3,100 at the same rate of calls per resident, simply because more people live there, as a city has more cases than a town; the offset turns the model for counts into a model for rates, so 2.17 is a ratio of call rates per resident, with income held constant, and its interval excludes 1, as does the interval for income10 (0.70 to 0.80). An IRR is a ratio, not a difference in calls, and a negative binomial model allows extra variation but still compares total calls unless the offset is included (the callout Apparent Overdispersion). (Section 4, 6.2 Poisson Regression and Incidence Rate Ratios, 6.3 Different Follow-Up Times: The Offset, and the callout Apparent Overdispersion in 7.1; Objectives 6.2 and 6.3)
● Complete the knowledge check to continue.
Final Assessment

Lesson 4: Final Assessment

16 questions • 100% required to pass

Bringing It All Together

This lesson presented one regression model for each common type of outcome. Section 1 sorted variables into numeric (continuous or discrete) and categorical (binary, ordinal or nominal) types, reviewed the four assumptions of linear regression (linearity, independence, normality and equal variance of the residuals) and the plots that check them, and introduced the generalized linear model, which keeps the linear predictor and changes the distribution and the link function. It also reviewed logistic regression for binary outcomes and its requirement of enough events per predictor.

Section 2 fitted ordinal logistic regression to self-rated health. The model fits every at-or-above split of the outcome at once and gives each predictor one odds ratio for being in a higher category, an assumption that the Brant test checks. Section 3 fitted multinomial logistic regression to usual place of care. The model compares each category with a reference category, reports relative risk ratios for each comparison, and is often clearest when presented as predicted probabilities. Section 4 fitted Poisson regression to urgent care visits, found that the counts were overdispersed (a dispersion ratio of 2.05 and too few expected zeros), and fitted a negative binomial model that matched the data and gave wider confidence intervals that reflect the extra variation in the counts.

Across the lesson, the same two predictors were used with five different outcomes, and the same steps were followed each time: the outcome type was identified, the matching model was fitted, the exponentiated coefficients were read as the ratio that the link function implies, and the model's own assumptions were checked before the results were reported. The final assessment asks for these steps to be applied to new outcomes. One assumption is shared by every model in this lesson, and none of them can check it from its own output: the independence of the observations.

Key Takeaways from this lesson

  1. You can now classify an outcome as continuous, count, binary, ordinal or nominal from what its values mean, and choose its model and the name of its result: a difference in means for linear regression, an odds ratio for logistic and ordinal logistic regression, a relative risk ratio for multinomial logistic regression and an incidence rate ratio for Poisson and negative binomial regression. For the exam, classify the outcome before you do anything else, using the question text and the data dictionary rather than the way the values are stored, because a rating stored as 1 to 5 is still ordinal.
  2. You can now explain why binary, categorical and count outcomes break the assumptions of linear regression, say which plot from plot(model) checks linearity, normality and equal variance (independence is judged from the study design), and describe a GLM by its distribution, linear predictor and link function. When you are shown residual plots, name the assumption each plot tests before you say whether it holds, and remember that the link function is what decides how a coefficient is read.
  3. You can now interpret an odds ratio from a logistic regression with its confidence interval, explain why the crude and adjusted odds ratios can differ, and judge whether a model has enough events per predictor. Count the events first and allow about 10 per predictor, and treat a large gap between the crude and adjusted odds ratios as a sign of confounding by the variables that were added.
  4. You can now explain why an ordinal outcome is analysed with ordinal logistic regression rather than a linear regression on its codes or a logistic regression on two collapsed groups, read its odds ratio as the odds of a higher category at every split, describe its predicted probabilities for two people in plain words and judge the proportional-odds assumption from a Brant test. Check the order of the levels before you read any odds ratio, judge significance from the confidence intervals because polr() gives no p-values, and remember that a Brant p-value below 0.05 is the warning sign.
  5. You can now explain why a nominal outcome is analysed with multinomial logistic regression, interpret each relative risk ratio as a ratio of two ratios for one comparison with the reference category, use predicted probabilities for the overall chance of each category, and judge the independence of irrelevant alternatives by asking whether two categories are close substitutes. Always name both categories in an interpretation, remember that changing the reference changes only the comparisons reported, and check any "times as likely" claim against the predicted probabilities rather than the RRR.
  6. You can now describe count outcomes and the Poisson distribution, whose variance equals its mean, interpret incidence rate ratios from a Poisson regression (including one given for a ten-year difference in age), and explain when an offset is needed and that the IRRs then compare rates. Ask first whether everyone was observed for the same length of time: if not, the model needs offset(log(time)), and each IRR compares rates per unit of time rather than total counts.
  7. You can now check a Poisson model for overdispersion with the dispersion ratio and the observed and expected zeros, explain that overdispersion makes its standard errors, confidence intervals and p-values too small, and choose between Poisson and negative binomial regression with these checks and the AIC. Justify your choice with the numbers for all three checks, rule out a missing offset or predictor first, and expect the negative binomial model to change the uncertainty far more than the IRRs themselves.

The final assessment covers all four sections. All 16 questions must be answered correctly (100%) to finish the lesson.

Final Knowledge Assessment

Final assessment: the 16 questions

1. A health authority followed 1,000 adults with type 2 diabetes for 6 to 24 months. A colleague's plan for four of the outcomes is shown below. Which response is correct?

OutcomeStored asPlanned model
hba1c (HbA1c, %)Values such as 6.8 or 9.1Linear regression
distress (diabetes distress)0 = none, 1 = mild, 2 = moderate, 3 = severeLinear regression, "because it is stored as numbers"
care_site (main place of diabetes care)1 = family doctor, 2 = nurse practitioner, 3 = diabetes clinic, 4 = no regular providerOrdinal logistic regression, "because its codes run from 1 to 4"
ed_visits (emergency department visits during follow-up)0, 1, 2, …Poisson regression
How a value is stored does not set its type. distress codes stand for ordered categories with unknown spacing, and care_site codes are only labels for places with no order.
Whole numbers of 0 or more counting events make ed_visits a count, not ordered categories. Counts are modelled with Poisson regression, which the plan already uses.
hba1c is continuous and ed_visits is a count, so those are matched. distress has ordered categories with unknown spacing, so it is ordinal, and care_site is nominal, so it is multinomial.
This reads the codes rather than the categories. distress has a natural order and place of care does not, so the ordinal model belongs with distress and the multinomial model with care_site.
The correct response keeps the models for hba1c (continuous, linear regression) and ed_visits (a count, Poisson regression) and corrects the other two. The information needed is what each stored value means. The distress codes 0 to 3 stand for ordered categories whose spacing is unknown, so a linear regression would treat each step as exactly one unit; the care_site codes 1 to 4 are labels for places with no order, so an ordinal model would invent a scale that does not exist. The tempting swap reads the codes rather than the categories, since distress has a natural order and place of care does not. ED visits are counts of events rather than ordered categories, and their model reports incidence rate ratios. (Section 1, 1.1 Types of Variables, Table 4.1, 1.2 Matching the Outcome to a Model and Table 4.2; Objectives 1.1 and 1.2)

2. For the same study, a colleague proposes the four analyses below. Which proposal is appropriate as written?

ProposalOutcomePlanned analysis
1ed_visitsPoisson regression on program completion, age and living alone, with no offset, because every person has a count
2distressGroup None and Mild against Moderate and Severe, then fit a logistic regression
3care_siteMultinomial logistic regression with Family doctor, the largest group, as the reference category
4a1c_high (1 = HbA1c above 8%)Linear regression of the 0/1 outcome on program completion, age and living alone
Proposal 3 matches a nominal outcome with a multinomial model and a natural reference. The others break a rule: a missing offset with unequal follow-up, a lossy cut-off and a straight line for a binary outcome.
Poisson regression is the right model for a count, but follow-up ran from 6 to 24 months, so without offset(log(months)) the model compares totals rather than rates.
Collapsing distress throws away detail and makes the answer depend on the cut-off. An ordinal model uses every split of the ordered categories.
A straight line fitted to a binary outcome can predict probabilities below 0 or above 1 and cannot have normal residuals. Logistic regression is the model for a 0/1 outcome.
The correct choice is proposal 3, the multinomial model for care_site with a large, natural reference category. The information needed is the type of each outcome and the study design. ED visits are counts, but people were followed for 6 to 24 months, so proposal 1 needs offset(log(months)) to compare rates rather than totals; proposal 2 discards the difference between none and mild and between moderate and severe, and its answer depends on where the cut-off is placed, whereas an ordinal model uses every split; and proposal 4 fits a straight line to a binary outcome, which can predict impossible probabilities and cannot have normal residuals, so logistic regression is the model to use. The tempting proposal 1 names the right model but leaves out the offset that the unequal follow-up requires. (Section 1, 1.2 Matching the Outcome to a Model and Table 4.2; Section 2, 4.1 What Makes an Outcome Ordinal?; Section 4, 6.3 Different Follow-Up Times: The Offset; Objectives 1.2, 4.1 and 6.3)

3. A colleague fitted lm(ed_visits ~ program + age10 + lives_alone) and drew plot(model). In Residuals vs Fitted, the residuals lie in parallel diagonal stripes with a long upper tail; in Q-Q Residuals, the points bend far above the line at the upper end; and in Scale-Location, the red line climbs from left to right. Which reading is correct?

Each stripe holds people with the same number of visits, not a group of related people. Independence is judged from the study design rather than from a residual plot.
The stripes reflect the whole-number counts, not a curve. The Q-Q bend and the climbing Scale-Location line point to non-normal residuals and unequal variance, which a squared term does not fix.
Frequent users are genuine data, and removing them discards real information. The patterns are what a count outcome produces, so a model that suits counts is needed.
The Q-Q plot shows non-normal residuals and the climbing Scale-Location line shows unequal variance, the patterns expected when a linear model is fitted to a count.
The correct reading is that normality and equal variance fail, as expected for a count. The information needed is which plot checks which assumption: Q-Q Residuals checks normality, and Scale-Location (with Residuals vs Fitted) checks equal variance. Each stripe holds the people with the same number of visits (0, 1, 2 and so on), the long upper tail and the bend in the Q-Q plot show skewed residuals, and the climbing line shows a spread that grows with the predicted count, which are the problems that Figure 4.3 shows for urgent_visits. The stripes are not groups of related people, since independence is judged from the design rather than from a plot, and removing genuine frequent users would discard real data instead of fitting a model that suits counts. (Section 1, 2.1 Linear Regression and Its Assumptions and 2.2 Why Some Outcomes Break These Assumptions, Figure 4.3; Objectives 2.1 and 2.2)

4. In the same study, 300 of the 1,000 adults had an HbA1c above 8% (a1c_high = 1). A logistic regression gave the odds ratios below, where program is 1 for adults who completed a self-management program and age10 is age in decades. Which interpretation is correct?

> exp(cbind(OR = coef(logit), confint(logit)))[-1, ] OR 2.5 % 97.5 % program 0.62 0.46 0.84 age10 0.84 0.75 0.94 lives_alone 1.22 0.90 1.65
An odds ratio is not the proportion of completers with the outcome. The lives_alone interval also includes 1, so its higher odds are not statistically significant.
An odds ratio below 1 means lower odds after adjustment, and the program's interval lies below 1. The lives_alone interval includes 1, so the data are compatible with no association there.
The outcome is binary, so the model reports odds ratios, which multiply the odds of a high HbA1c. They are not differences in HbA1c percentage points.
A 95% confidence interval that excludes 1 shows significance at the 5% level even without printed p-values. The program's interval excludes 1, so its association can be judged.
The correct interpretation reads the odds ratio for program as a multiplier of the odds and judges each association from its interval. The information needed is each odds ratio, its 95% CI and the other predictors in the model. An odds ratio of 0.62 means 0.62 times the odds, or 38% lower odds, of a high HbA1c for completers than for non-completers of the same age and living arrangement, and 0.46 to 0.84 lies below 1; the interval for lives_alone (0.90 to 1.65) includes 1, so its 22% higher odds are not statistically significant. The tempting first option reads the odds ratio as a proportion and ignores the interval. An odds ratio is also not a difference in HbA1c, and a confidence interval that excludes 1 shows significance at the 5% level even when no p-values are printed. (Section 1, 3.1.1 Reading Odds Ratios and Their Confidence Intervals and the callout Recall: Statistical Foundations; Objective 3.1)

5. Fitted on its own, program gave a crude odds ratio of 0.50 (95% CI 0.38 to 0.66), against the adjusted 0.62 in Question 4. Completers were older on average, and older adults were less likely to have a high HbA1c. R gives the events per predictor for the three-predictor model below. Which statement is correct?

> sum(diab$a1c_high) / 3 # events per predictor [1] 100
Age is related to both program completion and the outcome, so part of the crude association reflected age, and adjusting moved the odds ratio toward 1. The events per predictor are far above about 10.
Adjusting for a confounder removes bias rather than adding it, so the crude estimate is the distorted one and the adjusted estimate is the one to report.
The confounding reading holds, but the events rule counts the events, here the adults with a high HbA1c, not all 1,000 people.
A change between crude and adjusted estimates signals confounding. Showing that the effect differs between age groups would need an interaction, not a comparison of crude and adjusted values.
The correct statement explains the change as confounding by age and counts the events correctly. The information needed is how age relates to both the program and the outcome, and the events per predictor that R prints. Completers were older, and older adults had lower odds of a high HbA1c (an odds ratio of 0.84 per decade in Question 4), so part of the crude odds ratio of 0.50 reflected age; adjusting for age moved it to 0.62, toward 1. The events-per-predictor rule counts the events, here the 300 adults with a high HbA1c, not all 1,000 people, and R gives 100 events for each of the three predictors, far above about 10, so the option that counts every adult uses the wrong number. A change between the crude and adjusted estimates does not show that the effect differs between age groups. (Section 1, 3.1.2 Assumptions and the Number of Events, Table 4.3, and 3.1.3 Crude and Adjusted Odds Ratios; Objective 3.1)

6. Diabetes distress was stored as an ordered factor (None, Mild, Moderate, Severe) and modelled with polr(), giving the odds ratios below. Which statement is correct?

> exp(cbind(OR = coef(ord), confint(ord))) OR 2.5 % 97.5 % program 0.58 0.46 0.73 age10 0.91 0.82 1.01 lives_alone 1.48 1.13 1.94
With polr(), an odds ratio above 1 makes the higher categories more likely, and here higher means more distress. Whether that is better or worse depends on the level order.
An odds ratio compares odds of a higher category at each split; it is not a percentage of people. Age's interval includes 1, so its odds ratio below 1 is not statistically significant.
With levels ordered from None to Severe, an odds ratio above 1 favours more severe distress at every split, and an interval that excludes 1 shows significance at the 5% level.
A 95% confidence interval that excludes 1 shows significance at the 5% level, so the polr() output can be judged without p-values and without refitting.
The correct statement reads the direction from the order of the levels and judges significance from the intervals. The information needed is the level order (None to Severe, so a higher category means more distress), the odds ratios and their 95% CIs. With polr(), an odds ratio above 1 makes the higher categories more likely, so 1.48 means 1.48 times the odds of a more severe category (for example, Moderate or Severe rather than None or Mild) at each split; program (0.46 to 0.73) and lives_alone (1.13 to 1.94) exclude 1, while age10 (0.82 to 1.01) includes it. The tempting first option forgets that "higher" here means more distress, and an odds ratio below 1 is not significant on its own when its interval includes 1. (Section 2, 4.3 Interpreting the Odds Ratios and the callout How R Writes the Ordinal Model; Objective 4.3)

7. The Brant test for the distress model gave the results below. Separate logistic regressions at the three splits gave odds ratios for program of 0.61 (Mild or worse against None), 0.57 and 0.55 (Severe against the rest). Which statement is correct?

> brant(ord) Test for X2 df probability Omnibus 5.9 6 0.43 program 1.2 2 0.55 age10 3.1 2 0.21 lives_alone 1.4 2 0.5 H0: Parallel Regression Assumption holds
This reverses the test. The Brant null hypothesis is that the assumption holds, so p-values above 0.05 are consistent with it rather than rejecting it.
The proportional-odds assumption concerns the predictors, not the size of the categories. It says each predictor has the same odds ratio at every split.
Small differences between split-specific odds ratios are expected even when the assumption holds. The Brant test gives no evidence that these differences exceed chance.
The assumption says each predictor has one odds ratio at every split. With every Brant p-value above 0.05 and similar split-specific values, one odds ratio summarises the program.
The correct statement defines the proportional-odds assumption and reads the Brant test in the right direction. The information needed is the null hypothesis printed under the output (that the assumption holds), the p-values and the split-specific odds ratios. Because every p-value (0.43, 0.55, 0.21 and 0.50) is above 0.05, there is no evidence that any odds ratio changes from split to split, and the three split-specific values for program differ only by amounts that chance would produce. The tempting first option reverses the test, since a small p-value, not a large one, is evidence against the assumption, and small differences between split-specific odds ratios are expected even when the assumption holds. (Section 2, 4.2 How the Model Works: A Series of Splits and 4.5 Checking the Proportional-Odds Assumption, the accordion panel "How the Brant test works"; Objectives 4.2 and 4.5)

8. The predicted probabilities below, from the distress model, are for two 60-year-olds who live with others: one who did not complete the program and one who did. Which description is correct?

PersonNoneMildModerateSevere
Did not complete0.290.420.210.08
Completed0.410.400.140.05
An odds ratio compares odds at a split, not probabilities in each category. The completer is in fact more likely than the non-completer to report no distress.
Comparing the two rows category by category shows the completer shifted toward None and away from Moderate and Severe, with little change in Mild.
The completer's largest predicted probability is not Severe, and the model's predictions come from its coefficients, not from how the program is offered.
An odds ratio is not a difference in probabilities, and the two rows differ by different amounts in each category.
The correct description compares the two adults category by category, with the probabilities read as percentages. The information needed is the two rows, each of which adds to 1. The completer has a higher probability of None (0.41 against 0.29) and lower probabilities of Moderate (0.14 against 0.21) and Severe (0.05 against 0.08), while Mild changes little (0.42 and 0.40). The tempting first option applies the odds ratio to the probabilities, but the completer is more likely, not less likely, to be in the None category, because an odds ratio compares odds at a split rather than probabilities. (Section 2, 4.4 Predicted Probabilities for Two People, Worked Example 4.2b; Objective 4.4)

9. Main place of diabetes care (care_site: Family doctor, Nurse practitioner, Diabetes clinic, No regular provider) was modelled with multinom(), with Family doctor as the reference category. For living alone, the relative risk ratio in the No regular provider row is 2.05 (95% CI 1.35 to 3.11). Which statement is correct?

With four categories, there are three comparisons, each against Family doctor. The RRR compares the ratio of no regular provider to a family doctor between those living alone and with others.
The reference category is the baseline, not a comparison, so there are three comparisons. An RRR is not an overall chance; that comes from predicted probabilities.
Each comparison is against the reference category, Family doctor, not against the next category in the list. This RRR compares No regular provider with Family doctor.
An RRR is a ratio of two ratios, not a percentage difference. Differences in overall chances come from predicted probabilities.
The correct statement gives K − 1 = 3 comparisons and names both categories in the interpretation. The information needed is the number of categories (K = 4), the reference category and the RRR with its interval. Each non-reference category is compared with Family doctor, so the No regular provider row describes how the ratio P(no regular provider) ÷ P(family doctor) differs between adults living alone and adults living with others: it is 2.05 times as high, and 1.35 to 3.11 excludes 1. The tempting second option counts the reference category as a comparison and reads the RRR as an overall chance, which the predicted probabilities, not the RRRs, show. (Section 3, 5.2 Comparisons With a Reference Category and 5.3 Interpreting Relative Risk Ratios, with the callout An RRR Is a Ratio of Two Ratios; Objectives 5.2 and 5.3)

10. In the same model, the RRR for program in the Diabetes clinic row is 3.20 (95% CI 2.25 to 4.55). A colleague writes that "completers are 3.2 times as likely as non-completers to receive their diabetes care at a diabetes clinic". The predicted probabilities for two 60-year-olds who live with others are below. Which response is correct?

PersonFamily doctorNurse practitionerDiabetes clinicNo regular provider
Did not complete0.580.150.120.15
Completed0.450.160.300.09
An RRR compares one category with the reference, and the reference chance also changes, so the RRR is not the ratio of the overall chances. Those come from the predicted probabilities.
A large RRR does not imply a majority. The predicted probabilities show that completers still most often receive care from a family doctor.
An RRR is a ratio, not a difference in percentage points. The change in the overall chance is read directly from the predicted probabilities.
The RRR keeps its own comparison of diabetes clinic with family doctor, while the overall chance of each place of care comes from the predicted probabilities.
The correct response uses the predicted probabilities for the overall chance and keeps the RRR for its own comparison. The information needed is the two rows of probabilities, each adding to 1. The RRR of 3.20 says that the ratio P(diabetes clinic) ÷ P(family doctor) is 3.2 times as high for completers; because the chance of a family doctor also changes (from 0.58 to 0.45), this ratio of two ratios is not the ratio of the overall chances, so the colleague's sentence should be written with the predicted probabilities of a diabetes clinic, 0.12 and 0.30, rather than with the RRR. The option about percentage points reads the RRR as a difference, which it is not. Completers are still more likely to see a family doctor than to attend a diabetes clinic (0.45 against 0.30), so the option claiming that most of them now use a clinic misreads a large RRR as a majority. (Section 3, 5.3, the callout An RRR Is a Ratio of Two Ratios, and 5.4 Predicted Probabilities, Table 4.7; Objective 5.4)

11. A colleague says that the independence of irrelevant alternatives (IIA) assumption is met for care_site "because each adult names exactly one main place of care". Which response is correct?

Mutually exclusive categories are a separate requirement. IIA asks whether the odds of one category over another depend on which alternatives are available, which fails when two categories are close substitutes.
This describes the independence of the observations, which is judged from the study design. IIA concerns how choices among the outcome categories behave when one is removed.
IIA is doubtful when two categories are close substitutes. A family doctor and a nurse practitioner both give ongoing primary care, so removing one would send most patients to the other.
The Brant test checks the proportional-odds assumption of the ordinal model. IIA is judged by asking whether any two categories are close substitutes.
The correct response separates IIA from mutually exclusive categories and judges it by asking whether two categories are close substitutes. The information needed is what each category offers: a family doctor and a nurse practitioner both give ongoing primary care by appointment, so they are near substitutes, in the way that two identical buses would be. The multinomial model assumes that if one category were removed, its members would spread over the others in proportion to the existing odds, which is unlikely here. The tempting second option confuses IIA with the independence of the observations, which is judged from the study design, and the Brant test checks the proportional-odds assumption of the ordinal model, not IIA. (Section 3, 5.5 Assumptions and the Independence of Irrelevant Alternatives, Table 4.8 and the accordion panel on the independence of irrelevant alternatives; Objective 5.5)

12. ED visits during follow-up (6 to 24 months) were modelled with glm(ed_visits ~ program + age10 + lives_alone + offset(log(months)), family = poisson), giving the incidence rate ratios below. Which statement is correct?

> exp(cbind(IRR = coef(pois), confint(pois)))[-1, ] IRR 2.5 % 97.5 % program 0.74 0.67 0.82 age10 1.12 1.06 1.18 lives_alone 1.31 1.20 1.43
The offset keeps everyone in the analysis. It changes the comparison from total visits to visits per month of follow-up, and an IRR is a ratio of rates, not a difference in visits.
The offset adds log months with a coefficient fixed at 1, so the model compares visit rates per month, and an IRR below 1 means a lower rate among comparable adults.
The offset is not a predictor like age; it accounts for follow-up time. An IRR is a ratio of rates, not the proportion of completers who made a visit.
Adding an offset does not change a Poisson model into a logistic one. The exponentiated coefficients remain incidence rate ratios, comparing rates of visits.
The correct statement describes what the offset does and reads the IRR as a ratio of rates. The information needed is the term offset(log(months)) and the IRR for program with its interval (0.67 to 0.82). Because follow-up ran from 6 to 24 months, the offset turns the model for counts into a model for visits per month, so 0.74 means that completers' rate of ED visits is 0.74 times, or 26% lower than, that of comparable non-completers, and the interval excludes 1; the expected number of visits for a person is then that rate multiplied by their months of follow-up. The tempting first option misdescribes the offset, which keeps everyone in the analysis; the offset is not a predictor like age, and an IRR is a ratio of rates, not a difference in visits, a proportion or an odds ratio. (Section 4, 6.2 Poisson Regression and Incidence Rate Ratios, 6.3 Different Follow-Up Times: The Offset and question 1 of Activity 4.4; Objectives 6.2 and 6.3)

13. A second model adds log_inc, the natural logarithm of household income (in thousands of dollars). Its IRR is 0.85 (95% CI 0.77 to 0.94). Which interpretation is correct?

This reads the IRR as if income had been entered in dollars. Because log_inc is a natural log, one unit corresponds to multiplying income by about 2.72.
One unit of a natural-log predictor is a multiplication of income by about 2.72, not a 1% increase.
An IRR is a ratio of rates, not a difference in the number of visits, and one unit of log_inc is not a fixed dollar amount.
A one-unit difference in a natural-log predictor means income is multiplied by about 2.72, so the IRR compares the visit rate of adults whose incomes differ by that factor.
The correct interpretation translates one unit of the log scale back into income. The information needed is that log_inc is a natural log, so a difference of 1 in log_inc means that income is multiplied by e1 ≈ 2.72. An IRR of 0.85 therefore compares adults whose incomes differ by that factor: the one with the higher income has a rate of ED visits 0.85 times as high, or 15% lower, and 0.77 to 0.94 excludes 1. The tempting first option reads the IRR per $1,000, as it would be read if income had been entered without the log, and the third option reads the IRR as a difference in visits rather than a ratio. (Section 4, 6.2 Poisson Regression and Incidence Rate Ratios, the paragraph on reading any IRR; Objective 6.2)

14. The dispersion ratio of the ED-visits Poisson model was 3.40 without the offset and 2.62 with it. With the offset, the model expected 262 adults with no ED visits, while 380 were observed. A colleague says: "The extra spread was only there because the offset was missing, so the Poisson model is fine now." Which response is correct?

Including the offset was right, but a dispersion ratio still well above about 1.5 and far fewer expected than observed zeros show that overdispersion remains, so a negative binomial model with the offset is needed.
The ratio fell with the offset but stayed well above about 1.5, and the expected zeros still fall short of those observed. The offset removed only part of the extra spread.
This reverses the direction. Overdispersion makes the Poisson standard errors and intervals too small, so the results look more certain than they are.
Overdispersion mainly affects the uncertainty, not the rate ratios, which usually change little in a negative binomial model. The standard errors are what change.
The correct response accepts the offset but shows that the overdispersion remains. The information needed is both dispersion ratios and the observed and expected zeros. A missing offset can create apparent overdispersion, so it is right to include the offset first, but the ratio with the offset (2.62) is still far above 1, and many more adults had no visits (380) than the model expects (262); the Poisson model therefore understates the variance, so its standard errors, intervals and p-values are too small. The tempting second option notices that the ratio fell but not that it stayed well above 1.5, and overdispersion mainly affects the uncertainty rather than the IRRs, which usually change little in a negative binomial model. (Section 4, 7.1 Checking the Poisson Model for Overdispersion, Table 4.9 and the callout Apparent Overdispersion; Objective 7.1)

15. A negative binomial model with the same offset was fitted. The results for lives_alone, and the model checks, are below. Which statement is correct?

ResultPoissonNegative binomial
Coefficient for lives_alone (SE)0.270 (0.045)0.262 (0.082)
IRR for lives_alone (95% CI)1.31 (1.20 to 1.43)1.30 (1.11 to 1.53)
AIC3412.83051.6
Dispersion ratio2.621.04
Expected zeros (380 observed)262377
The Poisson standard error is smaller only because the model ignores the extra variation. That precision is overstated, not real.
For AIC, lower is better, so the Poisson model's higher AIC shows a poorer fit.
The coefficients barely differ, but the negative binomial model allows the variance to exceed the mean, so its larger standard error reflects the real uncertainty. A much lower AIC, a ratio near 1 and matching zeros all favour it.
The coefficients are almost the same; overdispersion mainly affects the uncertainty, not the estimate. The reason to report the negative binomial model is its fit, not a corrected bias.
The correct statement compares the two models' estimates and their uncertainty and chooses between them with the three checks. The information needed is the coefficient and standard error in each model, and the AIC, dispersion ratios and expected zeros. The coefficients (0.270 and 0.262) give almost the same IRR, but the standard error is nearly twice as large (0.082 against 0.045), because the negative binomial model adds the parameter theta so that the variance can be larger than the mean, which widens the interval to 1.11 to 1.53. The negative binomial AIC (3051.6) is lower than the Poisson AIC (3412.8) by far more than about 10 points, the dispersion ratio is 1.04 and the expected zeros match the data, so the negative binomial model is reported. The tempting first option treats the Poisson standard error as a sign of precision, but it is too small, because the Poisson model ignores the extra variation. (Section 4, 7.2 Negative Binomial Regression and Choosing Between the Models, Table 4.10; Objective 7.2)

16. A health authority followed 1,200 adults aged 65 and over who live at home, each for one full year, and modelled three outcomes on alone (1 = lives alone), age and gender. The estimates for alone are below. Which statement is correct?

OutcomeModel and checkEstimate for alone (95% CI)
Number of falls in the year (0 to 9; 61% had none)Negative binomial (the Poisson dispersion ratio was 2.4)1.38 (1.13 to 1.68)
Fear of falling: not afraid, somewhat afraid, very afraidOrdinal logistic (Brant omnibus p = 0.38)1.52 (1.23 to 1.88)
Main help at home: paid home care, compared with noneMultinomial logistic (reference: none)2.10 (1.48 to 2.98)
Main help at home: community program, compared with noneMultinomial logistic (reference: none)1.20 (0.80 to 1.80)
Each model gives a different ratio: counts give incidence rate ratios, ordinal outcomes odds ratios for a higher category, and nominal outcomes relative risk ratios. None of these is read as times as likely.
Each estimate is named by its model and read with its interval: an IRR for falls, an odds ratio for a more afraid category, and RRRs against no help. Equal follow-up means no offset is needed.
An offset is needed when follow-up time or population size differs, not because of many zeros. A Brant p-value above 0.05 is consistent with the proportional-odds assumption.
An estimate above 1 is not enough; the community-program interval includes 1. An RRR is a ratio against the reference, not a percentage difference.
The correct statement names each ratio from its model and reads each estimate with its interval. The information needed is the type of each outcome, the length of follow-up and the checks. Falls are counts, so the negative binomial estimate (used because a Poisson dispersion ratio of 2.4 signals overdispersion) is an incidence rate ratio; fear of falling is ordinal, so 1.52 is an odds ratio for a more afraid category, and a Brant p-value above 0.05 is consistent with one odds ratio at both splits; main help at home is nominal, so each estimate is a relative risk ratio for one category compared with the reference, no help. The community-program interval (0.80 to 1.80) includes 1, so that comparison does not show a clear association. An offset is needed when follow-up time or population size differs, and here every adult was followed for the same year, so the many zeros do not call for one. (Section 1, 1.2 Matching the Outcome to a Model and Table 4.2; Section 2, 4.3 Interpreting the Odds Ratios and 4.5 Checking the Proportional-Odds Assumption; Section 3, 5.3 Interpreting Relative Risk Ratios; Section 4, 6.2 Poisson Regression and Incidence Rate Ratios, 6.3 Different Follow-Up Times: The Offset and 7.1 Checking the Poisson Model for Overdispersion; Objectives 1.2, 4.3, 4.5, 5.3, 6.2, 6.3 and 7.1)

✦ Before submitting, pass every section knowledge check (100%).

🏆 Congratulations!

You have successfully completed this lesson: Generalized Linear Models.

Your responses have been downloaded automatically.