[R] Use generalised additive model to plot curve
Bill.Venables at csiro.au
Bill.Venables at csiro.au
Tue Dec 14 23:48:14 CET 2010
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.
More information about the R-help
mailing list