gam error

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

gam error

natalieh
Hi all,

I'm trying to use a gam (mgcv package) to analyse some data with a roughly U shaped curve. My model is very simple with just one explanatory variable:

m1<-gam(CoT~s(incline))

However I just keep getting the error message

"Error in smooth.construct.tp.smooth.spec(object, dk$data, dk$knots) :
  A term has fewer unique covariate combinations than specified maximum degrees of freedom"

Just wondering if anyone had come across this before/ could offer any advice on where the problem might lie

Many thanks,

Natalie


Reply | Threaded
Open this post in threaded view
|

Re: gam error

Joris FA Meys
Data?

On Thu, Jun 3, 2010 at 1:24 PM, natalieh <[hidden email]> wrote:

>
> Hi all,
>
> I'm trying to use a gam (mgcv package) to analyse some data with a roughly
> U
> shaped curve. My model is very simple with just one explanatory variable:
>
> m1<-gam(CoT~s(incline))
>
> However I just keep getting the error message
>
> "Error in smooth.construct.tp.smooth.spec(object, dk$data, dk$knots) :
>  A term has fewer unique covariate combinations than specified maximum
> degrees of freedom"
>
> Just wondering if anyone had come across this before/ could offer any
> advice
> on where the problem might lie
>
> Many thanks,
>
> Natalie
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/gam-error-tp2241518p2241518.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>



--
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
[hidden email]
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: gam error

jannis-2
In reply to this post by natalieh
How many datapoints do you have? The spline smoothers assume a default of 10 degrees of freedom (i think), so If you have less datapoints than 10 I would guess that you get this error. Same would be true if you have >10 datapoints but many replicates of CoT~incline combinations.

Either reduce the degrees of freedom of the smoother or gather more data ;-).

I would not be too sure about the sense of fitting univariate gams....There should be not too much of a difference to just plotting CoT~incline and fitting some spline to it ( i might be wrong here!)

HTH
Jannis

--- natalieh <[hidden email]> schrieb am Do, 3.6.2010:

> Von: natalieh <[hidden email]>
> Betreff: [R] gam error
> An: [hidden email]
> Datum: Donnerstag, 3. Juni, 2010 11:24 Uhr
>
> Hi all,
>
> I'm trying to use a gam (mgcv package) to analyse some data
> with a roughly U
> shaped curve. My model is very simple with just one
> explanatory variable:
>
> m1<-gam(CoT~s(incline))
>
> However I just keep getting the error message
>
> "Error in smooth.construct.tp.smooth.spec(object, dk$data,
> dk$knots) :
>   A term has fewer unique covariate combinations than
> specified maximum
> degrees of freedom"
>
> Just wondering if anyone had come across this before/ could
> offer any advice
> on where the problem might lie
>
> Many thanks,
>
> Natalie
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/gam-error-tp2241518p2241518.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email]
> 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.
>



______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: gam error

natalieh
In reply to this post by Joris FA Meys
Data?

The data are measures of energy use (continuous variable) for running on 7 inclines between -90 and +90 degrees (n=7-21).
Reply | Threaded
Open this post in threaded view
|

Re: gam error

Gavin Simpson
In reply to this post by natalieh
On Thu, 2010-06-03 at 04:24 -0700, natalieh wrote:

> Hi all,
>
> I'm trying to use a gam (mgcv package) to analyse some data with a roughly U
> shaped curve. My model is very simple with just one explanatory variable:
>
> m1<-gam(CoT~s(incline))
>
> However I just keep getting the error message
>
> "Error in smooth.construct.tp.smooth.spec(object, dk$data, dk$knots) :
>   A term has fewer unique covariate combinations than specified maximum
> degrees of freedom"

What this means is that you have fewer unique values for 'incline' than
you have knots in the spline. I forget now what the default (k = -1) in
function s() means, but it will be there in the help.

To set an upper limit, you could try:

K <- length(unique(incline)) - 1
m1 <- gam(CoT ~ s(incline, k = K))

Furthermore, you could try:

str(obj)

where 'obj' is/are your R data objects to check that R and you have the
same impression of what your data actually.

HTH

G

> Just wondering if anyone had come across this before/ could offer any advice
> on where the problem might lie
>
> Many thanks,
>
> Natalie
>
>
>

--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: gam error

Joris FA Meys
In reply to this post by natalieh
This doesn't tell us much either. What does the variable "incline"
represent, and what does the variable "ToC" represent?
I could guess your data looks something like :
ToC Incline
x1    -90
x2    -60
x3    -30
x4     0
x5     30
x6     60
x7     90
x8     -90
...      ...

Or incline could be the number of the sample (going from 1 to 7). No way to
know what you did. Please, read the posting guide and take the hints given
there into consideration.

This said, you very likely just have not enough data to use a thin plate
regression spline without limiting k. see ?choose.k and
?null.space.dimension

Cheers
Joris

On Thu, Jun 3, 2010 at 2:49 PM, natalieh <[hidden email]> wrote:

>
> Data?
>
> The data are measures of energy use (continuous variable) for running on 7
> inclines between -90 and +90 degrees (n=7-21).
> --
> View this message in context:
> http://r.789695.n4.nabble.com/gam-error-tp2241518p2241608.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>



--
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
[hidden email]
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.