Search code examples
rnon-linear-regressiongam

How can I apply interaction between two variable for multiple non-linear regression with GAM?


I have a data with Y and X1, X2 which has different dimension, like X1 = xxxx Volt, X2 = xx hour.

To make regression model with this data, I used code below.

MODEL <- gam(Y ~ s(X1) + s(X2), data = DATA, method = "REML")

It seems to work well, but I want apply a interaction between X1 and X2 to my code.

Could I do the multiple non-linear regression with using a code like :

MODEL <- gam(Y ~ s(X1) + s(X2) + ti(X1, X2), data = DATA, method = "REML")

or should I use different equation to do this work?


Solution

  • The preferred way would be:

    MODEL <- gam(Y ~ te(X1, X2), data = DATA, method = "REML")
    

    as that entails selection of fewer smoothness parameters so it is a slightly simpler version of the model you showed.

    However, if you want to see if the interaction is significant or otherwise want to separate out the main effects from the interaction, then yes, the model you showed is the way to go

    MODEL <- gam(Y ~ s(X1) + s(X2) + ti(X1, X2), data = DATA, method = "REML")