[R] GAM

Patrick Breheny patrick.breheny at uky.edu
Wed Nov 9 14:41:34 CET 2011


On 11/08/2011 11:57 AM, Gyanendra Pokharel wrote:
> Hi R community!
> I am analyzing the data set "motorins" in the package "faraway" by using
> the generalized additive model. it shows the following error. Can some one
> suggest me the right way?
>
> library(faraway)
> data(motorins)
> motori<- motorins[motorins$Zone==1,]
> library(mgcv)
> amgam<- gam(log(Payment) ~ offset(log(Insured))+
> s(as.numeric(Kilometres)) + s(Bonus) + Make + s(Claims),family = gaussian,
> data = motori)
> 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 to provide further information,

 > table(motori$Kilometres)

  1  2  3  4  5
61 63 60 57 54

Kilometres only has 5 unique values; this complicates the issue of 
estimating a curve, as you only have 5 points to work with.  Likewise, 
Bonus only has 7 unique values.  Claims does not pose any problem, as it 
has 98 unique values.  As Jean suggested, you can get around this issue 
with:

amgam<- gam(log(Payment) ~ offset(log(Insured)) + 
s(as.numeric(Kilometres),k=5) + s(Bonus,k=7) + Make + s(Claims),family = 
gaussian, data = motori)

-- 
Patrick Breheny
Assistant Professor
Department of Biostatistics
Department of Statistics
University of Kentucky



More information about the R-help mailing list