The correct use of tensor product in gam (mgcv) function

I want to resurrect a question that I asked two months ago (Comparing gam models using ti( )), but adding more explanations.

• The aim of my analyses was to compare several gam models with different combinations of independent variables.

• My analyses are done in R using the gam function from the mgcv package

• Some of the models include interactions between some of the independent variables and in such a case, I use the following gam structure. gam(Y ~ ti(X1) + ti(X2) + ti(X1,X2), data = dat). The ti() function is a tensor product that is appropriate when interaction terms and main effects occur simultaneously (https://stat.ethz.ch/R-manual/R-devel/library/mgcv/html/te.html).

• Models that do not include interactions can be written as gam(Y ~ ti(X1) + ti(X2), data = dat) or gam(Y ~ s(X1) + s(X2), data = dat) with s() a function providing a smoother of the variable considered (https://stat.ethz.ch/R-manual/R-devel/library/mgcv/html/s.html)

I have two questions concerning this setup:

1. Is it correct using ti() (i.e. tensor product) when there is no interaction in the formula ?

(I am sure I will be blasted for this question, but if I use ti() instead of s() in those models their AIC value is better ... but see my second question)

1. Can I compare directly (e.g. using AIC for example) models fitted with ti() and models fitted with s() ?

Thanks for your help !

Arnaud

• I'm not knowledgable enough to help out here, but just wanted to let you know that simply editing your previous question puts it at the top of the active page, which a lot of users watch. This shouldn't be abused, but it is designed so that you can provide more clarification without being lost in the sea of questions. Apr 14 '15 at 15:57
• @Chris C Thanks! I did not know that ... so sorry for the double posting Apr 14 '15 at 19:05
• No skin off my back, just wanted to let you know for the future so you know the site better :) Apr 14 '15 at 19:54

Before answering both of your questions, it's important to address the purpose of using ti() (and te() for that matter). Both smoothing functions are used when you're including interaction terms with different scales or units in your model.

On that note, whenever you're trying to examine the effects of an explanatory variable (x1) on y across different values of another explanatory variable (x2), you need to make sure that they're on the same scale.

1. Is it correct using ti() (i.e. tensor product) when there is no interaction in the formula?

It's not appropriate to use the ti() function when there is no interaction in the formula. The purpose of ti() is to separate the interactions from individual univariate effects. In order to accomplish this, you use regular smoothing terms (s()) for each variable, and then ti() for each interaction.

It would look something like this: mod_ti <- gam(y ~ s(x1) + s(x2) + ti(x1, x2)) Where the effects of x1 and x2 are separately smoothed, and the interaction between both on different scales is a separate term contained in ti().

1. Can I compare directly (e.g. using AIC for example) models fitted with ti() and models fitted with s()?

Sure you can compare them, but again, if your interaction terms are on different scales, you shouldn't fit the interaction with s(). You should either use te() or ti() (the choice depends on whether or not you're including the separate effects of the interaction terms in your model).