[R] smoothing line and a pair of confidence intervals

Simon Wood snw at mcs.st-and.ac.uk
Tue Dec 18 10:04:49 CET 2001


> Suppose I have a data set of y versus x, how can I generate a smoothing line
> of y versus x (for example, using loess)
> and at the same time, generate a pair of confidence intervals for the
> smoothing or mean plus/minus standard deviation?

- You could use library mgcv:

library(mgcv)
g.m<-gam(y~s(x))
plot(g.m) # plot of centred smooth
# or alternatively.....
p.d<-data.frame(x=seq(min(x),max(x),length=100))
b<-predict.gam(g.m,p.d,se=TRUE)
range<-c(min(b$fit-2*b$se.fit),max(b$fit+2*b$se.fit))
plot(p.d$x,b$fit,ylim=range,xlab="x",ylab="y",type="l")
lines(p.d$x,b$fit+b$se.fit*2,col=2)
lines(p.d$x,b$fit-b$se.fit*2,col=2)

cheers,
Simon

  ______________________________________________________________________
> Simon Wood  snw at st-and.ac.uk  http://www.ruwpa.st-and.ac.uk/simon.html
> The Mathematical Institute, North Haugh, St. Andrews, Fife KY16 9SS UK
> Direct telephone: (0)1334 463799          Indirect fax: (0)1334 463748 


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list