order of points in spline
On Fri, 6 Nov 2009, _nico_ wrote:
Hello everyone, I was trying to fit a spline to some points and I was quite surprised to find out that the function spline does not take into account the order of the points themselves, but orders them by x. For instance, I have: x <- c(262, 275, 264, 250, 247, 242, 238, 233) y <- c(422, 389, 359, 308, 269, 229, 191, 176) plot(x, y, xlim=c(0, 500), ylim=c(0,500)) s <- spline(x,y) points(s, type="l", lwd=2) As you can see from the above examplethe spline is fitted not using the points in the order that was passed, but ordering them by x. Is there a way to prevent this?
Huh?
Prevent spline from using (x[n],y[n]) as the coordinates of the n^{th}
data point?
Why on earth would you want to do that?
Do you think that this:
all.equal( spline(x,y) , spline( rev(x) , rev(y)))
[1] TRUE
should have returned FALSE?? Chuck p.s. Hint: Respond by citing a reference in the peer reviewed math/stats literature that describes a function that does what you want and folks may be able to help you.
I also tried loess and other packages that fit curves to points but didn't have any luck either thanks nico -- View this message in context: http://old.nabble.com/order-of-points-in-spline-tp26230875p26230875.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901