[R] Error message in GAM
Simon Wood
s.wood at bath.ac.uk
Thu Oct 18 10:21:19 CEST 2007
In mgcv::gam smooths are represented using basis functions. The `k' argument
of `s' specifies the number of basis functions to use. Its default value is
10. If you have fewer than k unique covariate values then the basis can not
be set up. So you need to reduce k to at most the number of unique covariate
values that you have.
Here is an example...
> x <- rep(1:9*10,10)
> unique(x) ## 90 data, but only 9 values
[1] 10 20 30 40 50 60 70 80 90
> y <- runif(90)*100
> gam(asin(sqrt(.01*y))~s(asin(sqrt(.01*x)))) ## fails k=10 is too large
Error in smooth.construct.tp.smooth.spec(object, data, knots) :
A term has fewer unique covariate combinations than specified maximum
degrees of freedom
> gam(asin(sqrt(.01*y))~s(asin(sqrt(.01*x)),k=9)) ## no problem, k=9 is fine
Family: gaussian
Link function: identity
Formula:
asin(sqrt(0.01 * y)) ~ s(asin(sqrt(0.01 * x)), k = 9)
Estimated degrees of freedom:
5.302189 total = 6.302189
GCV score: 0.1204443
On Wednesday 17 October 2007 18:03, Francesc Montané wrote:
> Hello useRs!
>
> I have % cover data for different plant species in 300 plots, and I use
> the ARCSINE transformation (to deal with % cover data).
> When I use a GLM I do not have any problem.
> But when I am trying to use a GAM model using mgcv package, to account for
> non-linearity I get an âerror messageâ.
>
> I use the following model:
>
> sp1.gam<-gam(asin(sqrt(0.01*SP1COVER))~ s(asin(sqrt(0.01*SP2COVER)))+
> s(asin(sqrt(0.01*SP3COVER)))+ s(asin(sqrt(0.01*SP4COVER)))+
> s(asin(sqrt(0.01*SP5COVER))), family=gaussian, data=plantcover,
> na.action=na.pass)
>
> The error message is the following:
>
> "Error in smooth.construct.tp.smooth.spec(object, data, knots) :
> A term has fewer unique covariate combinations than specified maximum
> degrees of freedom"
>
> It seems that some variables in the model give problems,â¦What is the
> reason of this error message?
> What I do is trying to erase randomly some of the variables (those that I
> expect to have more zeros) in the model (for instance run the same model
> without the SP5COVER term) and try if I get the error message again or
> not,⦠but this is time consuming.
> What can I do?
>
> Thanks!
>
> Francesc
>
> ______________________________________________
> 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.
--
> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
> +44 1225 386603 www.maths.bath.ac.uk/~sw283
More information about the R-help
mailing list