[R-sig-eco] Error message in GAM

Gavin Simpson gavin.simpson at ucl.ac.uk
Thu May 19 08:35:39 CEST 2011


On Wed, 2011-05-18 at 17:16 -0500, ARISTIDES LOPEZ wrote:
> Dear Dr. Gavin,
> 
> Thank you very much for your help. All my data are unique (because I have 56
> different stations). As you suggest I restrict the
> complexity of the individual smooths:
> 
> response ~ s(Lat, k = 9) + s(Long, k = 9) + s(deep, k = 9)
> 
> Problem solved.
> 
> Now I try to make other model:
> 
>  modelo2<-gam(Density~s(year, k=6)+s(Month, k=6)+s(rainfall, k=6),
> family=Gamma, data=at)
> 
> The "new" problem is that R give me the next error  *"Error en
> smooth.construct.tp.smooth.spec(object, dk$data, dk$knots) :
>   A term has fewer unique covariate combinations than specified maximum
> degrees of freedom"*.

It means exactly what it says. One of the terms in the model:

      * s(year, k = 6)
      * s(Month, k = 6)
      * s(rainfall, k = 6)

has *fewer* then 6 unique values. Look at the outputs from

with(at, table(year))
with(at, table(Month))
with(at, table(rainfall))

to see which it(they) is(are).

G

> Anybody knows what mean this?
> 
> Regards.
> 
> 2011/5/18 Gavin Simpson <gavin.simpson at ucl.ac.uk>
> 
> > On Wed, 2011-05-18 at 10:53 -0500, ARISTIDES LOPEZ wrote:
> > > Dear members list,
> > >
> > > I'm trying to make a model for descrive the distribution of demersal
> > fishes
> > > in the Colombian Caribbean Sea. I have a data set of n= 56, the model is
> > > like this: Density (ind/km2) ~ s(Lat) + s(Long) + s(deep). The problem is
> > > that R give me the error message *"Model has more coefficients than
> > data"*.
> > >
> > > Anybody knows how can avoid this?
> > >
> > > Faithfully.
> >
> > Each of your smooths will be using k = 10 degrees of freedom so that is
> > 30 degrees of freedom already, which is a lot for a data set of 56
> > observations.
> >
> > Are all the data unique? i.e. you have 56 unique density values, 56
> > unique lats, 56 unique lons etc. If not, it might be the the unique
> > information in the data is not sufficient to support the complexity of
> > the smooths.
> >
> > My money would be on that you did something you haven't actually told
> > us, and have more smooths in the model than you say and they are using
> > more degrees of freedom than it appears to us.
> >
> > The easy way to try to solve the problem, will be to restrict the
> > complexity of the individual smooths:
> >
> > response ~ s(Lat, k = 6) + s(Long, k = 6) + s(deep, k = 6)
> >
> > for example.
> >
> > You could probably model these data as a Possion with an offset term for
> > the km2 covered by each sample, rather than treating these as a density.
> >
> > HTH,
> >
> > G
> >
> > --
> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> >  Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
> >  ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
> >  Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
> >  Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
> >  UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> >
> >
> 
> 

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-sig-ecology mailing list