Tutorials › Generalized Linear Models › Worked Example With A Three-Category Logit

Multinomial Logit Models · Tutorial 505 of 981

Worked Example With A Three-Category Logit

Work through a fitted three-category baseline-logit model, from predicted probabilities and odds contrasts to a joint test of predictor effects.

Intermediate 10 min read

What You'll Learn

  • Convert baseline-category linear predictors into normalized category probabilities using the softmax formula
  • Calculate category-specific odds ratios and interpret them while holding other predictors fixed
  • Form pairwise category odds contrasts by subtracting category-specific coefficients
  • Test a predictor’s effects across nonbaseline categories with a joint Wald test
  • Distinguish probability changes from odds-ratio interpretations and joint from separate tests

From Fitted Logits to Category Probabilities

A baseline-category logit model describes a response with three nominal categories by comparing each nonbaseline category with a selected reference category. Its coefficients are log-odds coefficients, but a fitted model can also answer practical questions about the probability of each outcome at specified predictor values. This worked example connects those views: we calculate probabilities, interpret category-specific and pairwise odds ratios, and test a predictor’s effects jointly.

Let the response \(Y\) take values \(1,2,3\), with category 1 as the baseline. Let \(x\) be a quantitative predictor and \(z\) a binary indicator. The model has one linear predictor for each nonbaseline category:

$$ \log\left(\frac{P(Y=2\mid x,z)}{P(Y=1\mid x,z)}\right) =\eta_2(x,z)=\beta_{20}+\beta_{2x}x+\beta_{2z}z, \qquad \log\left(\frac{P(Y=3\mid x,z)}{P(Y=1\mid x,z)}\right) =\eta_3(x,z)=\beta_{30}+\beta_{3x}x+\beta_{3z}z. $$

Suppose model fitting produces the following coefficient estimates:

$$ \hat{\eta}_2(x,z)=-0.4+0.8x+0.5z, \qquad \hat{\eta}_3(x,z)=0.2-0.3x+0.7z. $$

Here \(x\) increases by one unit when the quantitative predictor increases by one unit, and \(z=1\) denotes the group coded as present. The intercepts are the fitted baseline-category log-odds when \(x=z=0\). These estimates specify two log-odds relative to category 1; neither is itself a probability.

Definition: In a baseline-category logit model with category 1 as the reference, the fitted category probabilities are obtained by normalizing the baseline weight \(1\) and the nonbaseline weights \(\exp(\hat{\eta}_2)\) and \(\exp(\hat{\eta}_3)\). Thus $$ \hat{p}_1=\frac{1}{1+\exp(\hat{\eta}_2)+\exp(\hat{\eta}_3)},\qquad \hat{p}_2=\frac{\exp(\hat{\eta}_2)}{1+\exp(\hat{\eta}_2)+\exp(\hat{\eta}_3)},\qquad \hat{p}_3=\frac{\exp(\hat{\eta}_3)}{1+\exp(\hat{\eta}_2)+\exp(\hat{\eta}_3)}. $$

The denominator is essential: exponentiating each linear predictor gives odds relative to the baseline, not the category probabilities themselves. The normalization makes the three probabilities add to one.

Worked Example: Predicted Probabilities at a Specified Profile

Calculate the fitted category probabilities for an individual with \(x=1\) and \(z=0\).

First evaluate both linear predictors:

$$ \hat{\eta}_2(1,0)=-0.4+0.8(1)+0.5(0)=0.4, \qquad \hat{\eta}_3(1,0)=0.2-0.3(1)+0.7(0)=-0.1. $$

The corresponding exponentiated weights are \(\exp(0.4)\approx1.4918\) and \(\exp(-0.1)\approx0.9048\). Including the baseline weight, the denominator is

$$ D=1+1.4918+0.9048=3.3966. $$

Therefore,

$$ \hat{p}_1=\frac{1}{3.3966}\approx0.2944,\qquad \hat{p}_2=\frac{1.4918}{3.3966}\approx0.4392,\qquad \hat{p}_3=\frac{0.9048}{3.3966}\approx0.2664. $$

The rounded probabilities sum to \(0.2944+0.4392+0.2664=1.0000\). Category 2 has the largest fitted probability at this profile, but that statement is different from saying that its odds relative to category 1 equal \(0.4392\). In fact, those odds are \(\exp(0.4)\approx1.4918\).

Category-Specific and Pairwise Odds Ratios

A one-unit increase in \(x\), with \(z\) held fixed, changes the category-2-versus-category-1 log odds by \(\beta_{2x}\). Exponentiating that coefficient gives the corresponding multiplicative change in the odds. The same calculation applies to category 3 versus category 1, using its own coefficient.

Worked Example: Category-Specific Odds Ratios

For the fitted model, calculate and interpret the odds ratios for a one-unit increase in \(x\), separately for categories 2 and 3 against the baseline.

For category 2 versus category 1, the coefficient of \(x\) is \(0.8\), so the odds ratio is

$$ \exp(\hat{\beta}_{2x})=\exp(0.8)\approx2.226. $$

Holding \(z\) fixed, a one-unit increase in \(x\) multiplies the odds of category 2 rather than category 1 by about \(2.226\). For category 3 versus category 1, the coefficient is \(-0.3\), giving

$$ \exp(\hat{\beta}_{3x})=\exp(-0.3)\approx0.741. $$

Thus, holding \(z\) fixed, a one-unit increase in \(x\) multiplies the odds of category 3 rather than category 1 by about \(0.741\), a reduction of about \(25.9\%\) in those odds. The two odds ratios differ because they compare different categories with the baseline.

The same fitted model also gives odds for comparing two nonbaseline categories directly. The pairwise comparison follows by subtracting their baseline log odds: the baseline terms cancel. This is useful when the scientific question concerns category 2 versus category 3 rather than either category versus category 1.

Result: For any covariate values in a baseline-category logit model, $$ \log\left(\frac{P(Y=2\mid x,z)}{P(Y=3\mid x,z)}\right) =\eta_2(x,z)-\eta_3(x,z). $$ Consequently, the coefficient of \(x\) in the category-2-versus-category-3 log odds is \(\beta_{2x}-\beta_{3x}\), and the odds ratio for a one-unit increase in \(x\) is \(\exp(\beta_{2x}-\beta_{3x})\), holding other predictors fixed.

To verify the result, write \(P(Y=2\mid x,z)=\exp(\eta_2)/D\) and \(P(Y=3\mid x,z)=\exp(\eta_3)/D\), where \(D=1+\exp(\eta_2)+\exp(\eta_3)\). Dividing these probabilities cancels the common denominator, so their ratio is \(\exp(\eta_2-\eta_3)\). Taking logarithms gives the stated log-odds identity. In the linear predictors, subtracting \(\eta_3\) from \(\eta_2\) subtracts the corresponding coefficients, including the slopes. Exponentiating the slope difference gives the odds ratio for a one-unit increase. \(\square\)

Worked Example: A Pairwise Category Contrast

Find the fitted odds ratio for category 2 versus category 3 for a one-unit increase in \(x\), holding \(z\) fixed.

The two fitted slopes are \(0.8\) and \(-0.3\). Their difference is

$$ \hat{\beta}_{2x}-\hat{\beta}_{3x}=0.8-(-0.3)=1.1. $$

Therefore, the pairwise odds ratio is

$$ \exp(1.1)\approx3.004. $$

A one-unit increase in \(x\) multiplies the odds of category 2 rather than category 3 by about \(3.004\), conditional on \(z\). This is a contrast between two slopes; it is not either of the category-specific odds ratios against category 1.

For another check, at \(x=1,z=0\), the fitted category-2-versus-category-3 odds are \(\exp(0.4)/\exp(-0.1)=\exp(0.5)\). At \(x=2,z=0\), they are \(\exp(1.2)/\exp(-0.4)=\exp(1.6)\). Their ratio is \(\exp(1.6-0.5)=\exp(1.1)\), as required.

Testing a Predictor Jointly Across Categories

A predictor with category-specific slopes contributes more than one coefficient. To test whether \(x\) has any linear-predictor effect in the model, test both of its nonbaseline slopes together:

$$ H_0:\ \beta_{2x}=0\ \text{and}\ \beta_{3x}=0 \qquad\text{versus}\qquad H_A:\ \text{at least one of these coefficients is nonzero}. $$

This is a joint Wald test. It uses the covariance between coefficient estimates as well as their individual estimated variances. In general, treating the two coefficient tests as unrelated does not give the same test.

Theorem: Let \(\hat{\boldsymbol{\beta}}\) estimate a parameter vector \(\boldsymbol{\beta}\). Suppose the model is identifiable and regular, the true parameter is an interior point, the relevant information matrix is nonsingular, and the usual asymptotic normal approximation and a consistent covariance estimator \(\widehat{\operatorname{Var}}(\hat{\boldsymbol{\beta}})\) hold. For a fixed \(q\)-row matrix \(C\) of rank \(q\), to test \(H_0:C\boldsymbol{\beta}=\boldsymbol{0}\), the Wald statistic is $$ W=(C\hat{\boldsymbol{\beta}})^\mathsf{T} \left\{C\widehat{\operatorname{Var}}(\hat{\boldsymbol{\beta}})C^\mathsf{T}\right\}^{-1} (C\hat{\boldsymbol{\beta}}). $$ Under \(H_0\), \(W\xrightarrow{d}\chi^2_q\).

For the justification, the asymptotic normality assumption gives the null limit of the scaled contrast as a mean-zero normal vector with covariance matrix \(\Sigma=CVC^\mathsf{T}\), where \(V\) is the relevant asymptotic covariance matrix. The rank and nonsingularity assumptions make \(\Sigma\) positive definite. Consistency of the covariance estimator and Slutsky’s theorem allow its estimated version in the quadratic form without changing the limiting distribution. If \(Z\) is a mean-zero normal vector with covariance \(\Sigma\), then \(\Sigma^{-1/2}Z\) is a \(q\)-dimensional standard normal vector. Its squared Euclidean length is the sum of squares of \(q\) independent standard normal variables, which has a \(\chi^2_q\) distribution. Hence the quadratic form has the stated asymptotic null distribution. \(\square\)

Worked Example: Joint Wald Test for the Effect of \(x\)

Suppose the fitted estimates of the two \(x\) slopes are \(\hat{\boldsymbol{\beta}}_x=(0.8,-0.3)^\mathsf{T}\), and their estimated covariance matrix is

$$ \widehat{\operatorname{Var}}(\hat{\boldsymbol{\beta}}_x) = \begin{pmatrix} 0.16 & 0.04\\ 0.04 & 0.09 \end{pmatrix}. $$

Test \(H_0:\beta_{2x}=\beta_{3x}=0\). The determinant of the covariance matrix is \(0.16(0.09)-0.04^2=0.0128\), so its inverse is

$$ \begin{pmatrix} 0.16 & 0.04\\ 0.04 & 0.09 \end{pmatrix}^{-1} = \frac{1}{0.0128} \begin{pmatrix} 0.09 & -0.04\\ -0.04 & 0.16 \end{pmatrix}. $$

The joint statistic is therefore

$$ W= \begin{pmatrix}0.8&-0.3\end{pmatrix} \frac{1}{0.0128} \begin{pmatrix}0.09&-0.04\\-0.04&0.16\end{pmatrix} \begin{pmatrix}0.8\\-0.3\end{pmatrix} = \frac{0.09(0.8)^2-2(0.04)(0.8)(-0.3)+0.16(-0.3)^2}{0.0128} =\frac{0.0912}{0.0128}=7.125. $$

There are \(q=2\) restrictions, so the reference distribution is \(\chi^2_2\). The upper-tail probability is \(P(\chi^2_2\ge7.125)=\exp(-7.125/2)\approx0.0284\). At the 5% level, reject the joint null: the fitted data provide evidence that at least one of the two category-specific \(x\) slopes is nonzero. This conclusion does not say that both slopes are individually significant.

Common Pitfall: A Coefficient Is Not a Probability Effect

A frequent error is to interpret \(0.8\), the category-2 slope, as an increase of \(0.8\) in the probability of category 2 for each unit increase in \(x\). That coefficient is a change in log odds relative to category 1. Its exponent, \(\exp(0.8)\), is a multiplicative odds ratio. The probability effect depends on the full set of fitted probabilities, including both nonbaseline linear predictors, and therefore on the starting values of the predictors.

For example, at \(x=0,z=0\), the linear predictors are \(-0.4\) and \(0.2\). The weights are approximately \(0.6703\) and \(1.2214\), giving denominator \(1+0.6703+1.2214=2.8917\). The probabilities are approximately \(0.3458, 0.2318,\) and \(0.4224\). These are not obtained by adding \(0.8\) to any probability. To describe a probability change, calculate the probabilities at both predictor profiles and compare them.

A second important distinction is between a pairwise contrast and a joint test. The pairwise slope contrast \(\beta_{2x}-\beta_{3x}\) describes how category-2-versus-category-3 odds change. The joint test of \(\beta_{2x}=\beta_{3x}=0\) asks whether \(x\) contributes to either baseline logit. They answer different questions, so the contrast should be chosen to match the scientific interpretation of interest.

Check Your Understanding

Use the fitted model and calculations in this tutorial to answer the following.

  1. At \(x=0,z=0\), calculate the two linear predictors and explain why their exponentials are not themselves the category probabilities.
  2. What is the odds ratio for category 3 versus category 1 for a one-unit increase in \(x\), holding \(z\) fixed?
  3. Write the slope contrast for category 3 versus category 2 and calculate its odds ratio for a one-unit increase in \(x\).
  4. In the joint Wald test for \(x\), why are there two restrictions and two degrees of freedom?
  5. Explain why rejecting the joint null does not imply that both category-specific slopes are individually significant.
Clinical Biostats