[R] Help with using unpenalised te smooth in negative binomial mgcv gam

Simon Wood s.wood at bath.ac.uk
Wed Jul 24 10:47:21 CEST 2013

Hi Alice,

This is a bug in gam.side, which was assuming that any interaction 
smooth that needed identifiability constraints would be penalized. 
thanks for reporting it - fixed for next version.

In the meantime have you considered using `ti' terms instead of `te'? 
These provide a more satisfactory way of building
models with main effects and interactions. A ti smooth is basically 
built as an interaction with the main effects completely removed, and 
therefore does not require the imposition of further side conditions to 
enforce identifiability  (using `ti' would mean including the main 
effect of x3 in your model).


On 23/07/13 16:02, alice.jones wrote:
> Hi,
> I have been trying to fit an un-penalised gam in mgcv (in order to get more
> reliable p-values for hypothesis testing), but I am struggling to get the
> model to fit sucessfully when I add in a te() interaction.  The model I am
> trying to fit is:
>          gam(count~ s(x1, bs = "ts", k = 4, fx = TRUE) +
>          s(x2, bs = "ts", k = 4, fx = TRUE) +
>          te(x2, x3, bs = c("ts", "cc"), fx = TRUE) +
>          log(offset(y)),
>          knots = list(x3=c(0,360)), family = negbin(c(1,10)))
> The error message I get is:
> "Error in sm[[i]]$S[[j]] : attempt to select less than one element"
> I can fit this model sucessfully if I don't specify the 'fx=TRUE' argument
> (i.e. I can sucesfully fit the penalised model).  It also works when I only
> include the two main terms x1 and x2, but do specify fx = TRUE, and it works
> fine when I only specify the main term x1 and the te smooth for x2 and x3
> and specify fx = TRUE (i.e. without a spearate specification of the main
> term, x2, that is also included in the interaction).  But.... when I have
> both main terms x1 and x2, as well as an interaction between x2 and x3,
> without penalisation, I get the error.
> I have played around with other data and with different covariate
> specification, but it seems that any time I specify a main term that is also
> included in the te interaction, within an un-penalised model, I get this
> same error message.
> Any help would be much appreciated, as I am trying to compare nested models
> (i.e. the full model with the interaction term against the model that just
> contains the two main terms).  I understand that the most appropriate way to
> do this is to use an un-penalised model for p-value estimation.
> Thanks,
> Alice
> --
> View this message in context: http://r.789695.n4.nabble.com/Help-with-using-unpenalised-te-smooth-in-negative-binomial-mgcv-gam-tp4672141.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> 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.

More information about the R-help mailing list