[R-sig-ME] Problem fitting multiple smoothers with gamm (William Butler)

Highland Statistics Ltd highstat at highstat.com
Mon Nov 26 19:23:35 CET 2012


On 26/11/2012 12:00, r-sig-mixed-models-request at r-project.org wrote:
> Send R-sig-mixed-models mailing list submissions to
> 	r-sig-mixed-models at r-project.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> or, via email, send a message with subject or body 'help' to
> 	r-sig-mixed-models-request at r-project.org
>
> You can reach the person managing the list at
> 	r-sig-mixed-models-owner at r-project.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of R-sig-mixed-models digest..."
>
>
> Today's Topics:
>
>     1. Problem fitting multiple smoothers with gamm (William Butler)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 26 Nov 2012 00:05:37 +0000
> From: William Butler <willb2306 at hotmail.com>
> To: <r-sig-mixed-models at r-project.org>
> Subject: [R-sig-ME] Problem fitting multiple smoothers with gamm
> Message-ID: <DUB102-W56A7D553DEFD719D4D3D71B45F0 at phx.gbl>
> Content-Type: text/plain
>
>
> Hi all,
>
>
> I'm analyzing egg density data for three species and I'm having some problems fitting multiple smooths with gamm. Here's what I´ve got:
>
>
> Three species (sp1, sp2, sp3)Differing number of females for each species (random effect, nested within species). 14, 9, 10 females for sp1, sp2, sp3 respectively.For each female, multiple measurements (between 20-100) of density on different days post fertilisation (DPF). Note, sp1 only has measurements for 4 females on day 9 as the rest hatched.
>
> Measurements were made on DPF 1,3,6,9 for sp1. DPF 1,3,6,9,12 for sp2. DPF 2,5,7,10,13 for sp3.
>
>
> I want to use GAMs to look at changes in density during the egg phase. I've done some linear mixed effects modeling with lme4, but some of the changes over time aren't linear and I want to try additive mixed effects models to see if it suits the data better.
>
>
> I started with each species separately and it worked fine. Then I tried to add in the species effect as follows:
> mod1 <- gamm(Density~f.species + s(DPF, by=f.species), random=list(female=~1), data=egg.data)
>
>
> The problem is this fits a smooths to day thirteen for all species and as they hatch at different times I want a smooth for each species till the hatch date.
>
>
> So I tried:
> mod2 <- gamm(Density~f.species + s(DPF, by=as.numeric(f.species=="sp1")) +
> s(DPF, by=as.numeric(f.species=="sp2")) +
> s(DPF, by=as.numeric(f.species=="sp3")),
> random=list(female=~1), data=egg.data)
>
>
> And I get the following error:
> Error in MEestimate(lmeSt, grps) : Singularity in backsolve at level 0, block 1
>
>
>
> I'm pretty new to GAMs and really don't understand this error, can anyone help with this?

Will...you need to remove the f.species as a main term. Smoothers with 
obtained with the above construction are not centered around zero.


> And does anyone have suggestions for fitting smooths till the hatch date for each species, all within the same model?

Yeap....fit a smoother as a mixed model...manually using MCMC. That for 
sure will do the trick. Having written these two sentences....that may 
not be the first thing you want to hear. I am not sure whether mgcv can 
use different ranges of the splines. If you go the MCMC route....there 
are lots of clear papers available, with dowloadable R code, that show 
you how to do it. Rupert et al. (2003) is the starting point.


>   Is it possible to have the smooths nested within species?

Not sure I understand this. Neither do I understand why you use 'female' 
as random effect...unless it refers to birds??

There's a book coming out in 2 weeks: A Beginner's Guide to Generalized 
Additive Models. Zuur AF. (2012). It answers some of your questions.

Alain
>   I've looked around the web but couldn't find much info (and didn't understand what I did!).
>
>
> Any help is appreciated.
>
>
> Kind regards
>
>
> Will
>
>
>
>
>   		 	   		
> 	[[alternative HTML version deleted]]
>
>
>
> ------------------------------
>
> _______________________________________________
> R-sig-mixed-models mailing list
> R-sig-mixed-models at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
>
> End of R-sig-mixed-models Digest, Vol 71, Issue 36
> **************************************************
>


-- 

Dr. Alain F. Zuur
First author of:

1. Analysing Ecological Data (2007).
Zuur, AF, Ieno, EN and Smith, GM. Springer. 680 p.
URL: www.springer.com/0-387-45967-7


2. Mixed effects models and extensions in ecology with R. (2009).
Zuur, AF, Ieno, EN, Walker, N, Saveliev, AA, and Smith, GM. Springer.
http://www.springer.com/life+sci/ecology/book/978-0-387-87457-9


3. A Beginner's Guide to R (2009).
Zuur, AF, Ieno, EN, Meesters, EHWG. Springer
http://www.springer.com/statistics/computational/book/978-0-387-93836-3


4. Zero Inflated Models and Generalized Linear Mixed Models with R. (2012) Zuur, Saveliev, Ieno.
http://www.highstat.com/book4.htm

Other books: http://www.highstat.com/books.htm


Statistical consultancy, courses, data analysis and software
Highland Statistics Ltd.
6 Laverock road
UK - AB41 6FN Newburgh
Tel: 0044 1358 788177
Email: highstat at highstat.com
URL: www.highstat.com
URL: www.brodgar.com



More information about the R-sig-mixed-models mailing list