[R] Setting up 3D tensor product interactions in mgcv

Gavin Simpson ucfagls at gmail.com
Tue Sep 3 21:21:11 CEST 2013


>From a reading of `?ti`

     It is sometimes useful to investigate smooth models with a
     main-effects + interactions structure, for example

                         f_1(x)  + f_2(z) + f_3(x,z)

     This functional ANOVA decomposition is supported by ‘ti’ terms,
     which produce tensor product interactions from which the main
     effects have been excluded, under the assumption that they will be
     included separately. For example the ‘~ ti(x) + ti(z) + ti(x,z)’
     would produce the above main effects + interaction structure. This
     is much better than attempting the same thing with ‘s’or ‘te’
     terms representing the interactions (although mgcv does not forbid
     it).

I think the following will do what you want:

mdl <- gam(PA ~ ti(x) + ti(y) + ti(z) + ti(x,y) + ti(x,z) + ti(y,z) +
ti(x,y,z), ....)

HTH

G

On 23 August 2013 02:05, Mark Payne <markpayneatwork at gmail.com> wrote:
> Hi,
>
> I am trying to fit a smoothing model where there are three dimensions
> over which I can smooth (x,y,z). I expect interactions between some,
> or all, of these terms, and so I have set up my model as
>
> mdl <- gam(PA ~ s(x) + s(y) + s(z) + te(x,y) + te(x,z) + te(y,z) +
> te(x,y,z),...)
>
> I have recently read about the ti(), "tensor product interaction
> smoother", which takes care of these interaction terms elegantly and
> does the nesting properly. The help file says "This is much better
> than attempting the same thing with ‘s’or ‘te’ terms representing the
> interactions (although mgcv does not forbid it)." There is a 2D
> example there also. But I don't understand how I should set this up
> for my 3D example. Do I simply replace the te's above with ti? Or is
> there more to it than that?
>
> Does anyone have experience with this, and can explain how I should do
> it properly?
>
> Mark
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gavin Simpson, PhD



More information about the R-help mailing list