gavinsimpson / gratia

ggplot-based graphics and useful functions for GAMs fitted using the mgcv package
https://gavinsimpson.github.io/gratia/
Other
206 stars 28 forks source link

How to remove tensor interaction in gam function? #197

Closed Nataliannash closed 2 years ago

Nataliannash commented 2 years ago

Dear Gavin,

I have a question about removing the tensor interaction in gam function, and I would appreciate it if you could help me. In example: fit <- gam(Y ~ s(X1) + s(X2) + s(X3) +s(X4) + ti(X1,X2,X3) , data=data), I used ti() function because there is interaction between the three variables (X1,X2,X3).

How should I change the gam function if I want that gam just consider the pure effects of these three variables without their interaction?

Some references said that if there is interaction between variables, removing ti() may cause repeating same covariates multiple times.

I tried fit <- gam(Y ~ s(X1) + s(X2) + s(X3) +s(X4) + ti(X1,X2,X3 , np=FALSE) , data=data), and compared it by "np=TRUE" but nothing changed in results.

Kind regards, Nat