When working with Generalized Additive Models (GAMs) fitted with non-gaussian families—such as logistic regression using a logit link—visualizing partial effects on the link scale (log-odds) is often less intuitive than looking at the response scale (probabilities). While gratia::draw() makes transforming smooth plots easy with arguments like fun = inv_link(), customizing these plots using ggplot2 requires a clear understanding of how partial effects and confidence intervals are transformed.

Understanding Link vs. Response Scales in GAMs

By default, functions like gratia::smooth_estimates() return predictions on the link scale (e.g., log-odds for a logit model). On this scale, partial smooth effects are centered around zero and do not include the model intercept (constant).

To convert partial smooth effects to the response scale (probabilities between 0 and 1), you cannot simply apply the inverse link function plogis() directly to the smooth estimate alone. Doing so ignores the model Intercept, leading to distorted shapes and incorrect values. To get the correct probability scale, you must:

  1. Add the overall model intercept (constant) to the estimated smooth effect and its confidence bounds on the link scale.
  2. Apply the inverse link function to those summed values.

Method 1: Manually Transforming smooth_estimates() Output

If you want to maintain full control over individual smooths using smooth_estimates(), you can extract the model intercept using gratia::model_constant() and apply the inverse link function extracted via gratia::inv_link().

Step-by-Step Code Example