# GAM interaction- how to interpret

I am working with a GAM model (based on a negative binomial distribution): model_n = gam(y ~ x1 +x2+ x3+x4 + s(x5)+x6+s(acc, by=ses)+x7+x8+ x9+x10, data=totalfinals, family=negbin(3))

I am interested in the interaction between s(acc) and the parametric continuous variable ses. I obtained this graph but I am not sure how to interpret the relation.

I guess I am not sure how to interpret the effect of the interaction between s(acc) and ses on the DV - I am confused by the centering based on zero so I am not sure what it means when the values along the y axis get higher or lower than 0, especially in the context of a negative binomial model.

Also, could anyone recommend some books so I can learn about interactions with splines in GAM models?

• When in doubt what some blackbox model is doing, devise some data to feed into its predict method. – Andrew M Oct 5 '18 at 5:36
• Thanks, Andrew- that is definitely useful. I think my main problem is that i am not familiar with spline interactions, I would really like to learn more about that. Best regards! – mikip Oct 5 '18 at 5:39

## 1 Answer

In a linear model, say

$$\hat{y}_i = \beta_0 + \beta_1 x_{1i}$$

the effect of $$\mathbf{x}_1$$ on the response is constant. If we add $$\mathbf{x}_2$$ to the model and an interaction between both covariates

$$\hat{y}_i = \beta_0 + \beta_1 x_{1i} + \beta_2 x_{2i} + \beta_3 (x_{1i}\times x_{2i})$$

the magnitude of the linear effect of $$\mathbf{x}_1$$ depends linearly on the effect of $$\mathbf{x}_2$$.

The same intuition guides the interpretation of a varying coefficient model such as the one you fitted. The key difference is that now we are thinking about how the magnitude of linear effect of $$\mathbf{x}_1$$ depends smoothly on $$\mathbf{x}_2$$.

The way to read the plot you show is to think in terms of $$\hat{\beta} \times \text{ses}$$, and the value of $$\hat{\beta}$$ for any value of $$\text{acc}$$ is indicated by the smooth line. The effect of $$\text{ses}$$ on the response is estimated to be positive, but only for values of $$\text{acc}$$ between ~6 and ~11, with the strongest effect of $$\text{ses}$$ on the response found at $$\text{acc} \approx$$ 8.

As this is a Negative Binomial model, all of the above effects are on the log scale. You would need to exponentiate the values on the y-axis to see the (now multiplicative) effect of $$\text{ses}$$ on the response. To guide this however, $$\exp(0) = 1$$, so the zero line in the plot indicates no effect or change in response on the log scale and on the response scale it also means no effect because the interpretation there is that we multiply values by $$\exp(0) = 1$$.

If you want to really dig into this visually, do as @AndrewM suggests, and create a new data frame with all the covariates except acc held at their mean or median values and vary acc over it's range. If you predict from the model passing this new data set as newdata you can explore the predicted values on the response scale (using type = "response") as you vary acc. I would do this for a few values of sec so you can see how the two variables interact.

• Hi Gavin, thank you so much for your thorough response! I will try and do that and I will report back, hopefully I manage to figure this out. Best regards! – mikip Oct 5 '18 at 15:43