Tutorials › Generalized Linear Models › Computing Fitted Risks for Covariate Profiles

Binary Logistic Regression · Tutorial 357 of 981

Computing Fitted Risks for Covariate Profiles

Work from a profile’s covariate values to its linear predictor and fitted event probability, with careful attention to coding and interactions.

Intermediate 9 min read

What You'll Learn

  • Construct the design vector for a specified covariate profile
  • Calculate a logistic linear predictor from estimated coefficients
  • Convert a linear predictor into a fitted event probability
  • Compute profiles involving binary and continuous predictors
  • Include interaction terms correctly in profile-specific predictions
  • Check predictions for coding, arithmetic, and interpretation errors

From a Covariate Profile to a Fitted Risk

A logistic-regression table reports estimated coefficients, but a coefficient is not itself an event probability. To answer a question such as “What event probability does the fitted model assign to a 60-year-old patient receiving treatment?”, first translate that profile into the model’s covariates, calculate its linear predictor, and then apply the inverse-logit function. This tutorial focuses on that calculation for specified profiles; it does not quantify uncertainty in the resulting predictions.

For a binary response \(Y\), let \(p(x)=P(Y=1\mid x)\), where \(x\) denotes the covariate information for a profile. In logistic regression, the log odds of the event are modeled as a linear predictor. When the fitted coefficient vector is \(\hat\beta\), the fitted event probability at profile \(x\) is obtained by evaluating that predictor at the profile and transforming it back to the probability scale.

Definition: For a covariate profile represented by a design vector \(x\), the fitted linear predictor is \(\hat\eta(x)=x^\mathsf{T}\hat\beta\). The fitted risk, or fitted event probability, is \(\hat p(x)=\exp\{\hat\eta(x)\}/[1+\exp\{\hat\eta(x)\}]\). The design vector includes the intercept, the profile’s coded predictor values, and any terms required by the specified model, such as interactions.

The design vector is the bridge between a description in context and the coefficient estimates. If a model has an intercept, a binary predictor \(A\), and a continuous predictor \(z\), with no interaction, then \(x=(1,A,z)^\mathsf{T}\). The value \(A=0\) or \(A=1\) must follow the model’s coding, and \(z\) must be expressed in the units used to fit the model. A profile is not fully specified until every required predictor value is known.

Why the Inverse-Logit Calculation Works

The logistic model writes the event probability’s log odds as the linear predictor. The fitted probability formula is not a separate modeling assumption: it follows by solving that equation for the probability.

Result: If \(\operatorname{logit}\{p(x)\}=\eta(x)\), where \(\operatorname{logit}(p)=\log\{p/(1-p)\}\), then \(p(x)=\exp\{\eta(x)\}/[1+\exp\{\eta(x)\}]\). Replacing the unknown coefficients by their estimates gives the fitted risk formula above.

To verify the result, start with the defining logit equation and exponentiate both sides. Then collect the terms involving \(p(x)\).

$$ \begin{aligned} \log\left\{\frac{p(x)}{1-p(x)}\right\}&=\eta(x)\\ \frac{p(x)}{1-p(x)}&=\exp\{\eta(x)\}\\ p(x)&=\exp\{\eta(x)\}\{1-p(x)\}\\ p(x)\{1+\exp\{\eta(x)\}\}&=\exp\{\eta(x)\}\\ p(x)&=\frac{\exp\{\eta(x)\}}{1+\exp\{\eta(x)\}}. \end{aligned} $$

The solution is valid because probabilities in the logistic model satisfy \(0<p(x)<1\), so the log odds are defined, and \(1+\exp\{\eta(x)\}\) is strictly positive. Substituting \(\hat\eta(x)=x^\mathsf{T}\hat\beta\) gives the fitted value. \(\square\)

This transformation has useful checks. Every finite linear predictor produces a probability strictly between zero and one, and a linear predictor of zero produces a fitted probability of one half. A positive predictor gives a probability above one half; a negative predictor gives one below one half. These checks can reveal sign or arithmetic errors before a prediction is reported.

Result: The inverse-logit function \(g(\eta)=\exp(\eta)/\{1+\exp(\eta)\}\) is strictly increasing, takes values strictly between zero and one for finite \(\eta\), and satisfies \(g(0)=1/2\).

For completeness, the range follows because \(\exp(\eta)>0\) and the denominator exceeds the numerator by \(1\), so \(0<g(\eta)<1\). At zero, \(g(0)=1/(1+1)=1/2\). Differentiating gives

$$ g'(\eta)=\frac{\exp(\eta)\{1+\exp(\eta)\}-\exp(\eta)\exp(\eta)} {\{1+\exp(\eta)\}^2} =\frac{\exp(\eta)}{\{1+\exp(\eta)\}^2}>0. $$

Thus \(g\) is strictly increasing. Consequently, comparing two fitted risks from the same fitted model can be checked by first comparing their linear predictors: the larger linear predictor always corresponds to the larger fitted risk. This is a computational property, not a statement about causation. \(\square\)

A Reliable Calculation Sequence

A careful prediction is mostly a matter of constructing the correct row of the model matrix. Before doing arithmetic, identify which values correspond to which coefficients. For a categorical predictor, use its reference-category coding; for a continuous predictor, use the recorded unit or transformation; for an interaction, calculate the product of the relevant profile values. Then sum the coefficient contributions before applying the inverse logit.

1
Write the fitted model.
List the intercept and every main-effect or interaction term that appears in the model.
2
Encode the profile.
Assign each predictor its specified value, respecting reference groups, units, centering, and any transformations.
3
Calculate the linear predictor.
Multiply each design-vector entry by its corresponding estimated coefficient and add all contributions, including the intercept.
4
Transform to a probability.
Compute \(\exp(\hat\eta)/\{1+\exp(\hat\eta)\}\), then report the value with appropriate rounding and context.

Worked Example: A Binary Predictor

Suppose a fitted model for a binary event uses \(A=1\) for treatment and \(A=0\) for control: \(\hat\eta(A)=-1.2+0.7A\). Calculate the fitted risk for a treated profile and a control profile.

Treated profile. Set \(A=1\). The fitted linear predictor is \(\hat\eta(1)=-1.2+0.7(1)=-0.5\). Therefore, \(\hat p(1)=\exp(-0.5)/\{1+\exp(-0.5)\}\). Using \(\exp(-0.5)\approx0.6065\), \(\hat p(1)\approx0.6065/1.6065\approx0.3775\). The fitted event probability is about \(0.378\), or \(37.8\%\).

Control profile. Set \(A=0\). Then \(\hat\eta(0)=-1.2+0.7(0)=-1.2\). Since \(\exp(-1.2)\approx0.3010\), \(\hat p(0)\approx0.3010/1.3010\approx0.2314\). The fitted event probability is about \(23.1\%\).

Both results are between zero and one, and both linear predictors are negative, so both probabilities should be below one half. The calculations meet those checks. The intercept is evaluated at \(A=0\), the model’s control reference profile.

Continuous Predictors and Units

A continuous predictor enters the linear predictor at the profile’s numerical value, not at an informal description such as “older” or “high.” If age is recorded in years, an age of 50 contributes 50 times its coefficient unless the model instead uses a centered or rescaled age variable. Always write down the actual modeled variable before substituting numbers. Centering or rescaling changes the values used in the calculation, even though the procedure is otherwise the same.

Worked Example: A Continuous Predictor and Treatment

Suppose a fitted model is \(\hat\eta(a,A)=-3.0+0.08a+0.5A\), where \(a\) is age in years and \(A=1\) denotes treatment. Find the fitted risk for a 50-year-old treated profile.

Substitute \(a=50\) and \(A=1\): \(\hat\eta(50,1)=-3.0+0.08(50)+0.5(1)\). The age contribution is \(0.08(50)=4.0\), and the treatment contribution is \(0.5\), so \(\hat\eta(50,1)=-3.0+4.0+0.5=1.5\).

Now transform the predictor: \(\hat p(50,1)=\exp(1.5)/\{1+\exp(1.5)\}\). Since \(\exp(1.5)\approx4.4817\), \(\hat p(50,1)\approx4.4817/5.4817\approx0.8176\). The fitted event probability is about \(81.8\%\).

As a unit check, the age term uses 50 years because \(a\) was defined in years. If instead the fitted model had used age in decades, the profile value would be 5 and its coefficient would need to be the coefficient estimated for that decade scale. Substituting 50 into a decade-based model would not represent this profile correctly.

Profiles When the Model Includes an Interaction

An interaction adds a product term to the design vector. Its contribution depends on both profile values, so it must be calculated separately from the corresponding main effects. For a binary treatment \(A\) and a continuous variable \(z\), a model with interaction can be written \(\hat\eta(A,z)=\hat\beta_0+\hat\beta_A A+\hat\beta_z z+\hat\beta_{Az}Az\). At \(A=0\), the product \(Az\) is zero. At \(A=1\), the interaction contribution is \(\hat\beta_{Az}z\). A single coefficient cannot be substituted for the whole profile-specific calculation.

Worked Example: Binary and Continuous Predictors With an Interaction

Consider the fitted model \(\hat\eta(A,z)=-2.0+0.6A+0.4z-0.3Az\), where \(A=1\) denotes treatment, \(A=0\) denotes control, and \(z=(\text{age}-50)/10\). Thus \(z=1\) means age 60 and \(z=-1\) means age 40. Calculate fitted risks for treated and control profiles at both ages.

Age 60, control. Here \(z=1\) and \(A=0\), so \(Az=0\). The predictor is \(\hat\eta(0,1)=-2.0+0.6(0)+0.4(1)-0.3(0)=-1.6\). Then \(\exp(-1.6)\approx0.2019\), giving \(\hat p(0,1)\approx0.2019/1.2019\approx0.1680\).

Age 60, treatment. Here \(z=1\), \(A=1\), and \(Az=1\). Thus \(\hat\eta(1,1)=-2.0+0.6+0.4-0.3=-1.3\). Since \(\exp(-1.3)\approx0.2725\), \(\hat p(1,1)\approx0.2725/1.2725\approx0.2142\).

Age 40, control. Here \(z=-1\), \(A=0\), and \(Az=0\). Therefore \(\hat\eta(0,-1)=-2.0+0.4(-1)=-2.4\). Using \(\exp(-2.4)\approx0.09072\), \(\hat p(0,-1)\approx0.09072/1.09072\approx0.0832\).

Age 40, treatment. Here \(z=-1\), \(A=1\), and \(Az=-1\). The interaction contribution is \((-0.3)(-1)=0.3\), so \(\hat\eta(1,-1)=-2.0+0.6-0.4+0.3=-1.5\). Since \(\exp(-1.5)\approx0.2231\), \(\hat p(1,-1)\approx0.2231/1.2231\approx0.1824\).

This example shows why the interaction term must be evaluated for each profile. The design value \(Az\) changes with both treatment status and age. The calculation itself remains the same: form the complete linear predictor, then apply the inverse logit.

Checks, Interpretation, and a Common Pitfall

A fitted risk is the model’s estimated probability of \(Y=1\) for the specified covariate profile. It is not the observed outcome for a particular person, and it is not automatically a causal probability. Its value depends on the fitted model, the coefficient estimates, the coding, and the profile supplied. When reporting one, name the event and describe the profile so that the number has a clear referent.

Before finalizing a calculation, check that the intercept has been included once; all profile values use the correct coding and units; each interaction product has been computed; and the final result lies between zero and one. Rounding the linear predictor too early can also change the last reported digits, so retain a few digits until the inverse-logit calculation is complete.

  • Common mistake: treating the linear predictor as a risk. If \(\hat\eta=1.5\), reporting a fitted risk of 1.5 is impossible because a probability must lie between zero and one. The correction is to transform it: \(\exp(1.5)/\{1+\exp(1.5)\}\approx0.818\).
  • Common mistake: omitting an interaction contribution. Substituting only the intercept and main effects does not evaluate the stated interaction model. The correction is to calculate every product term at the profile before summing.
  • Common mistake: using the wrong continuous scale. If a model uses centered age in decades, substituting age in years gives the wrong design vector. The correction is to express the profile using the exact variable defined in the fitted model.
Key takeaway: A fitted risk for a specified profile is calculated in two stages: evaluate the entire fitted linear predictor using that profile’s correctly coded design vector, then apply the inverse logit. The profile and the model specification determine every substitution.

Check Your Understanding

Use the fitted coefficients and transformations stated in each question, and show both the linear predictor and inverse-logit step.

  1. For \(\hat\eta=-0.8+0.5A\), where \(A=1\) denotes exposure, calculate the fitted risk for an unexposed profile.
  2. A fitted model is \(\hat\eta=-2+0.03a\), with age \(a\) measured in years. What value of \(a\) belongs in the calculation for a 60-year-old profile?
  3. For \(\hat\eta=-1+0.4A+0.2z-0.1Az\), calculate the linear predictor for \(A=1,z=2\). Which part of the calculation is the interaction contribution?
  4. What probability should a profile receive when its fitted linear predictor is zero, and why?
  5. A calculation gives \(\hat\eta=0.7\) and a reported fitted risk of \(0.7\). Identify the error and state the correct transformation.
Clinical Biostats