On 04/02/2012 01:26 PM, Mabille, Geraldine wrote:> Hi list,
> I'm working with gamm models of this sort, using Simon Wood's mgcv
library:
> gm<- gamm(Z~te(x,y),data=DATA,random=list(Group=~1))
> gm1<-gamm(Z~te(x,y,by=Factor)+Factor,data=DATA,random=list(Group=~1))
> with a dataset of about 70000 rows and 110 levels for Group
I would be inclined to use something like
gm<-
gam(Z~te(x,y)+s(Group,bs="re"),data=DATA,method="REML")
gm1<-gam(Z~te(x,y,by=Factor)+Factor+s(Group,bs="re"),data=DATA,method="REML")
AIC(gm,gm1)
See ?random.effects in the mgcv help for more details.> in order to test whether tensor product smooths vary across factor levels.
I was wondering if comparing those two models would be enough to conclude? I saw
a preceding post on similar issues
>
http://r.789695.n4.nabble.com/Comparing-and-Interpreting-GAMMs-td2234209.html
> but that example used simple s() smooths instead of tensor product
smooths. In this case, the person was comparing between model A and model A1
like:
>
> A<-gamm4(Z~factor+s(x)+s(x,by=factor) ,data=DATA, random=~(1|Group))
> A1<- gamm4(Z~factor+s(x) ,data=DATA, random=~(1|Group))
>
> I thus also tried to compare my model gm1, with another gm2 model of that
sort:
>
gm2<-gamm(Z~te(x,y)+te(x,y,by=Factor)+Factor,data=DATA,random=list(Group=~1))
> but this type of models never converge and I obtain error messages of that
sort: Error in MEestimate(lmeSt, grps) : Singularity in backsolve at level 0,
block 1
- The problem is that te(x,y) and te(x,y,by=Factor) are confounded. You
can get around this by making `Factor' into an ordered factor. See te
`by' variable section in ?gam.models.> 2 questions from that:
> 1) Keeping in mind that my main question is to check whether tensor
products smooths vary across factor levels, would the comparison of models gm
and gm1 be sufficient for me?
- I'd have thought so.> 2) Otherwise, is there something wrong in my gm2 model that make it
impossible to converge??
>
> Also, side question that I already posted a few days ago but didn't
get an answer for:
> 3)I don't manage to use vis.gam() to print 3 different 2D-contour
plots for the three levels of factors I have in model gm1. It works well with
model gm (when only one plot is generated) but not gm1 (3 plots should be
generated)
> Here is the error message I obtain:
>
vis.gam(gm1$gam,plot.type="contour",n.grid=200,color="heat",zlim=c(0,4))
> Error in predict.gam(x, newdata = newd, se.fit = TRUE, type = type) :
number of items to replace is not a multiple of replacement length
- hmm, possibly a bug. I'll look into it.
best,
Simon> Thanks a lot if someone can help with that,
> Geraldine
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>