
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? And does anyone have suggestions for fitting smooths till the hatch date for each species, all within the same model? Is it possible to have the smooths nested within species? 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]]

