[R] Interactions in GAMMs

David Winsemius dwinsemius at comcast.net
Wed Jul 21 17:50:43 CEST 2010


On Jul 21, 2010, at 11:17 AM, Karen Moore wrote:

> Hi,
>
> I've an issue adding an interaction to a GAMM:
>
> My model was of form:

# Package? Probably:
require(mgcv)

>
> gamm1 <- gamm(TOTSR ~ fROT + s(PH) + s(LOI) + s(ASP) + s(SQRT_ELEV)  
> + CANCOV
> + s(SQRT_TOTCWD) + s(WELLF) + s(WELLN) + s(OLDWDLD) + s(DISTWOOD) +
> s(Annprec) + s(OLDWDLD:DISTWOOD) + (1|fSITE),  family = poisson,  
> data =
> BIOFOR2)
>
> with interaction of s(OLDWDLD:DISTWOOD).
>
> However I got this error message below but don't know what it means?

The documentation for s() says the unnamed arguments must be a list of  
covariates and I do not think OLDWDLD:DISTWOOD constitutes a list. (On  
the other hand it appears that the term "list" is being used a bit  
loosely here, since the examples do not explicitly enclose the  
covariates in the list() function and when I did so with the example  
on the te help page I get an error.)

> (my
> data is composed of info for 150 plots)
>
> #I Warning messages:
> #2: In OLDWDLD:DISTWOOD :
> # numerical expression has 150 elements: only the first used
> #3: In OLDWDLD:DISTWOOD :
> #  numerical expression has 150 elements: only the first used
>
> Can anyone offer advice on how to include this interaction in GAMM  
> model?

Do you have Wood's book? Ch/sect 6.7 has worked examples using the  
te() function which I believe is the GAM(M) counterpart to linear  
interactions. He also makes the point that random arguments to gamm()  
need to be in the list form. (The documentation suggests this has not  
changes since the book was published.)

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list