Gamma family puts plot_nonlinear upside down

Both conditional smooth plots are showing what you’re asking for, so there’s nothing you need to correct. You’re right that the “flipped” direction of the conditional smooth function is because of the differences in the link functions used in your two models.

Your first model uses Gamma(link = "inverse") (the default). Remember that the inverse link is a decreasing function of the (smooth) predictor—bigger values on the link scale imply smaller values on the natural scale of the response. In contrast, the identity link in your second model (i.e., gaussian(link = "identity")) is an increasing function of the predictor. The same increasing property would hold if you had used, for example, Gamma(link = "log").

Like your last question, I definitely recommend incorporating posterior expectation/prediction plots into your post-fitting routine. Dissecting out individual terms is an important part of model interrogation, but their net impact on the natural response scale gets very difficult to infer in isolation from a complex model (smooths, non-identity link functions, etc.).

Close, but not quite. Drop the square on the expected value in the denominator. 1/E[Y]=X\beta in typical regression notation.

1 Like