2

Below is an example using mtcars.

par(mfrow=c(1,2))
plot(mtcars$disp,mtcars$mpg)
plot(mtcars$hp,mtcars$mpg)

library(mgcv)
gam1 <- gam(mtcars$mpg ~ s(mtcars$disp) + s(mtcars$hp), family = Gamma)
plot(gam1, page = 1)

The strange thing is that if I draw the relationship between disp & mpg, or hp & mpg, they are negatively related (Fig1). But after using GAM, their relation became positive (Fig2). How can they contradict?Fig1 Fig2

T X
  • 1,027

1 Answers1

3

From ?gam.plot:

gam.plot() takes a fitted gam object produced by gam() and plots the component smooth functions that make it up, on the scale of the linear predictor.

Since, canonical link for Gamma distribution is inverse (and you didn't provide your own link), linear predictor is on a scale of $1/\text{mpg}$, and so it was plotted.

Glen_b
  • 282,281
Łukasz Deryło
  • 4,051
  • 1
  • 14
  • 29