How to fit a smooth curve to my data in R?

I like loess() a lot for smoothing:

x <- 1:10
y <- c(2,4,6,8,7,12,14,16,18,20)
lo <- loess(y~x)
plot(x,y)
lines(predict(lo), col="red", lwd=2)

Venables and Ripley’s MASS book has an entire section on smoothing that also covers splines and polynomials — but loess() is just about everybody’s favourite.

Leave a Comment