Readers, I have been reading 'the r book' by Crawley and think that the generalised additive model is appropriate for this problem. The package 'gam' was installed using the command (as root) install.package("gam") ... library(gam)> library(gam)Loading required package: splines Loading required package: akima> library(mgcv)This is mgcv 1.3-25 Attaching package: 'mgcv' The following object(s) are masked from package:gam : gam, gam.control, gam.fit, plot.gam, predict.gam, s, summary.gam> x<-c(30,50,80,90,100) > y<-c(160,180,250,450,300) > model<-gam(y~s(x))Error in smooth.construct.tp.smooth.spec(object, data, knots) : A term has fewer unique covariate combinations than specified maximum degrees of freedom The objective is to plot y against x, finally to produce a graph with a smooth curve (and then remove the data points). What is my mistake please? yours, r251 gnu/linux mandriva2008
Bill.Venables at csiro.au
2010-Dec-14 22:48 UTC
[R] Use generalised additive model to plot curve
Dear Lurker, If all you art trying to do is to plot something, isn't all you need something like the following? x <- c( 30, 50, 80, 90, 100) y <- c(160, 180, 250, 450, 300) sp <- spline(x, y, n = 500) plot(sp, type = "l", xlab = "x", ylab = "y", las = 1, main = "A Spline Interpolation") points(x, y, pch = 3, col = "red", lwd = 2) Bill Venables. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of e-letter Sent: Wednesday, 15 December 2010 8:37 AM To: r-help at r-project.org Subject: [R] Use generalised additive model to plot curve Readers, I have been reading 'the r book' by Crawley and think that the generalised additive model is appropriate for this problem. The package 'gam' was installed using the command (as root) install.package("gam") ... library(gam)> library(gam)Loading required package: splines Loading required package: akima> library(mgcv)This is mgcv 1.3-25 Attaching package: 'mgcv' The following object(s) are masked from package:gam : gam, gam.control, gam.fit, plot.gam, predict.gam, s, summary.gam> x<-c(30,50,80,90,100) > y<-c(160,180,250,450,300) > model<-gam(y~s(x))Error in smooth.construct.tp.smooth.spec(object, data, knots) : A term has fewer unique covariate combinations than specified maximum degrees of freedom The objective is to plot y against x, finally to produce a graph with a smooth curve (and then remove the data points). What is my mistake please? yours, r251 gnu/linux mandriva2008 ______________________________________________ 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.
On Tue, 2010-12-14 at 22:36 +0000, e-letter wrote:> Readers, > > I have been reading 'the r book' by Crawley and think that the > generalised additive model is appropriate for this problem. The > package 'gam' was installed using the command (as root) > > install.package("gam") > ... > library(gam) > > > library(gam) > Loading required package: splines > Loading required package: akima > > library(mgcv) > This is mgcv 1.3-25Why do you want to use both gam:::gam and mgcv:::gam at the same time? Use one or the other package; not both.> Attaching package: 'mgcv' > > > The following object(s) are masked from package:gam : > > gam, > gam.control, > gam.fit, > plot.gam, > predict.gam, > s, > summary.gamThese warnings/messages are because you loaded two packages that both provide a gam() and other similarly named functions.> > x<-c(30,50,80,90,100) > > y<-c(160,180,250,450,300) > > model<-gam(y~s(x)) > Error in smooth.construct.tp.smooth.spec(object, data, knots) : > A term has fewer unique covariate combinations than specified > maximum degrees of freedomYou are trying to fit a thin-plate spline that is of greater complexity than the available data. You need to reduce the complexity of the fitted spline whilst fitting the model. For these data the maximum complexity is 5:> mod <- gam(y ~ s(x, k = 5))HTH G> The objective is to plot y against x, finally to produce a graph with > a smooth curve (and then remove the data points). What is my mistake > please? > > yours, > > r251 > gnu/linux mandriva2008 > > ______________________________________________ > 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.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% 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 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%