[R] Splines

Wayne.W.Jones at shell.com Wayne.W.Jones at shell.com
Fri Oct 5 16:50:23 CEST 2007


smooth.spline is a handy function and does what you need: 
Careful to not over fit though. Use different values of spar and df.


y<-c(467, 468, 460 ,460 ,450, 432, 419, 420, 423, 423)
x<-1:10
plot(x,y)
predict(smooth.spline(x,y,df=4),x=3.5)
lines(predict(smooth.spline(x,y,df=4),x=seq(1,10,length=100)),col="red",lwd=2)
lines(predict(smooth.spline(x,y,df=8),x=seq(1,10,length=100)),col="red",lwd=2)






-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org]On Behalf Of stat stat
Sent: 05 October 2007 09:31
To: r-help at stat.math.ethz.ch
Subject: [R] Splines


I want to fit a cubic spline of x on y. where :
   
  x
 [1] 467 468 460 460 450 432 419 420 423 423
y
 [1]  1  2  3  4  5  6  7  8  9 10
   
  using the syntax
   
  spline(y, x)
   
  I got following output :
   
  $x
 [1]  1.000000  1.310345  1.620690  1.931034  2.241379  2.551724  2.862069
 [8]  3.172414  3.482759  3.793103  4.103448  4.413793  4.724138  5.034483
[15]  5.344828  5.655172  5.965517  6.275862  6.586207  6.896552  7.206897
[22]  7.517241  7.827586  8.137931  8.448276  8.758621  9.068966  9.379310
[29]  9.689655 10.000000
  $y
 [1] 467.0000 469.5381 469.8643 468.4865 465.9444 463.0284 460.6479 459.6560
 [9] 459.8737 460.2296 459.6313 457.4921 454.0094 449.4482 444.1040 438.3613
[17] 432.6204 427.2892 422.8183 419.6733 418.2646 418.3633 419.3283 420.5202
[25] 421.5768 422.4555 423.1312 423.5419 423.5480 423.0000

  Now I want to get what is the value of y at x = 5.25. Can anyone tell me how to find that?
   


thanks in advance
       
---------------------------------
 Meet people who discuss and share your passions.  Join them now.
	[[alternative HTML version deleted]]

______________________________________________
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